Lines 1-4
Link Here
|
1 |
#include "loop.h" |
1 |
#include "loop.h" |
|
|
2 |
#include "error.h" |
2 |
#include <poll.h> |
3 |
#include <poll.h> |
3 |
#include <sys/termios.h> |
4 |
#include <sys/termios.h> |
4 |
#include <stdio.h> |
5 |
#include <stdio.h> |
Lines 26-40
Link Here
|
26 |
FD_SET(master_fd, &read_set); |
27 |
FD_SET(master_fd, &read_set); |
27 |
select_result = select(master_fd + 1, &read_set, NULL, NULL, NULL); |
28 |
select_result = select(master_fd + 1, &read_set, NULL, NULL, NULL); |
28 |
|
29 |
|
|
|
30 |
// interrupted select is ignored - see CR 7086177 |
31 |
if (select_result == -1 && errno == EINTR) { |
32 |
continue; |
33 |
} |
34 |
|
29 |
if (select_result == -1) { |
35 |
if (select_result == -1) { |
30 |
printf("ERROR: poll failed\n"); |
36 |
err_sys("poll failed\n"); |
31 |
exit(1); |
|
|
32 |
} |
37 |
} |
33 |
|
38 |
|
34 |
if (FD_ISSET(STDIN_FILENO, &read_set)) { |
39 |
if (FD_ISSET(STDIN_FILENO, &read_set)) { |
35 |
if ((n = read(STDIN_FILENO, buf, BUFSIZ)) == -1) { |
40 |
if ((n = read(STDIN_FILENO, buf, BUFSIZ)) == -1) { |
36 |
printf("ERROR: read from stdin failed\n"); |
41 |
err_sys("read from stdin failed\n"); |
37 |
exit(1); |
|
|
38 |
} |
42 |
} |
39 |
|
43 |
|
40 |
if (n == 0) { |
44 |
if (n == 0) { |
Lines 42-56
Link Here
|
42 |
} |
46 |
} |
43 |
|
47 |
|
44 |
if (write(master_fd, buf, n) == -1) { |
48 |
if (write(master_fd, buf, n) == -1) { |
45 |
printf("ERROR: write to master failed\n"); |
49 |
err_sys("write to master failed\n"); |
46 |
exit(1); |
|
|
47 |
} |
50 |
} |
48 |
} |
51 |
} |
49 |
|
52 |
|
50 |
if (FD_ISSET(master_fd, &read_set)) { |
53 |
if (FD_ISSET(master_fd, &read_set)) { |
51 |
if ((n = read(master_fd, buf, BUFSIZ)) == -1) { |
54 |
if ((n = read(master_fd, buf, BUFSIZ)) == -1) { |
52 |
printf("ERROR: read from master failed\n"); |
55 |
err_sys("read from master failed\n"); |
53 |
exit(1); |
|
|
54 |
} |
56 |
} |
55 |
|
57 |
|
56 |
if (n == 0) { |
58 |
if (n == 0) { |
Lines 58-69
Link Here
|
58 |
} |
60 |
} |
59 |
|
61 |
|
60 |
if (write(STDOUT_FILENO, buf, n) == -1) { |
62 |
if (write(STDOUT_FILENO, buf, n) == -1) { |
61 |
printf("ERROR: write to stdout failed\n"); |
63 |
err_sys("write to stdout failed\n"); |
62 |
exit(1); |
64 |
exit(1); |
63 |
} |
65 |
} |
64 |
} |
66 |
} |
65 |
} |
67 |
} |
66 |
|
68 |
|
67 |
return 0; |
69 |
return 0; |
68 |
} |
70 |
} |
69 |
|
71 |
|
Lines 86-100
Link Here
|
86 |
for (;;) { |
88 |
for (;;) { |
87 |
poll_result = poll((struct pollfd*) & fds, 2, INFTIM); |
89 |
poll_result = poll((struct pollfd*) & fds, 2, INFTIM); |
88 |
|
90 |
|
|
|
91 |
// interrupted poll is ignored - see CR 7086177 |
92 |
if (poll_result == -1 && errno == EINTR) { |
93 |
continue; |
94 |
} |
95 |
|
89 |
if (poll_result == -1) { |
96 |
if (poll_result == -1) { |
90 |
printf("ERROR: poll failed\n"); |
97 |
err_sys("poll() failed in main_loop"); |
91 |
exit(1); |
|
|
92 |
} |
98 |
} |
93 |
|
99 |
|
94 |
if (fds[0].revents & POLLIN) { |
100 |
if (fds[0].revents & POLLIN) { |
95 |
if ((n = read(STDIN_FILENO, buf, BUFSIZ)) == -1) { |
101 |
if ((n = read(STDIN_FILENO, buf, BUFSIZ)) == -1) { |
96 |
printf("ERROR: read from stdin failed\n"); |
102 |
err_sys("read from stdin failed"); |
97 |
exit(1); |
|
|
98 |
} |
103 |
} |
99 |
|
104 |
|
100 |
if (n == 0) { |
105 |
if (n == 0) { |
Lines 109-123
Link Here
|
109 |
} |
114 |
} |
110 |
|
115 |
|
111 |
if (writen(master_fd, buf, n) == -1) { |
116 |
if (writen(master_fd, buf, n) == -1) { |
112 |
printf("ERROR: write to master failed\n"); |
117 |
err_sys("write to master failed\n"); |
113 |
exit(1); |
|
|
114 |
} |
118 |
} |
115 |
} |
119 |
} |
116 |
|
120 |
|
117 |
if (fds[1].revents & POLLIN) { |
121 |
if (fds[1].revents & POLLIN) { |
118 |
if ((n = read(master_fd, buf, BUFSIZ)) == -1) { |
122 |
if ((n = read(master_fd, buf, BUFSIZ)) == -1) { |
119 |
printf("ERROR: read from master failed\n"); |
123 |
err_sys("read from master failed\n"); |
120 |
exit(1); |
|
|
121 |
} |
124 |
} |
122 |
|
125 |
|
123 |
if (n == 0) { |
126 |
if (n == 0) { |
Lines 125-132
Link Here
|
125 |
} |
128 |
} |
126 |
|
129 |
|
127 |
if (writen(STDOUT_FILENO, buf, n) == -1) { |
130 |
if (writen(STDOUT_FILENO, buf, n) == -1) { |
128 |
printf("ERROR: write to stdout failed\n"); |
131 |
err_sys("write to stdout failed\n"); |
129 |
exit(1); |
|
|
130 |
} |
132 |
} |
131 |
} |
133 |
} |
132 |
|
134 |
|
Lines 145-151
Link Here
|
145 |
return 1; |
147 |
return 1; |
146 |
} |
148 |
} |
147 |
} |
149 |
} |
148 |
|
150 |
|
149 |
return 0; |
151 |
return 0; |
150 |
} |
152 |
} |
151 |
#endif |
153 |
#endif |
Lines 154-160
Link Here
|
154 |
const char *pos = ptr; |
156 |
const char *pos = ptr; |
155 |
size_t nleft = n; |
157 |
size_t nleft = n; |
156 |
ssize_t nwritten; |
158 |
ssize_t nwritten; |
157 |
|
159 |
|
158 |
while (nleft > 0) { |
160 |
while (nleft > 0) { |
159 |
if ((nwritten = write(fd, pos, nleft)) < 0) { |
161 |
if ((nwritten = write(fd, pos, nleft)) < 0) { |
160 |
if (nleft == n) |
162 |
if (nleft == n) |