1*49cdfc7eSAndroid Build Coastguard Worker /*
2*49cdfc7eSAndroid Build Coastguard Worker *
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) International Business Machines Corp., 2001
4*49cdfc7eSAndroid Build Coastguard Worker *
5*49cdfc7eSAndroid Build Coastguard Worker * This program is free software; you can redistribute it and/or modify
6*49cdfc7eSAndroid Build Coastguard Worker * it under the terms of the GNU General Public License as published by
7*49cdfc7eSAndroid Build Coastguard Worker * the Free Software Foundation; either version 2 of the License, or
8*49cdfc7eSAndroid Build Coastguard Worker * (at your option) any later version.
9*49cdfc7eSAndroid Build Coastguard Worker *
10*49cdfc7eSAndroid Build Coastguard Worker * This program is distributed in the hope that it will be useful,
11*49cdfc7eSAndroid Build Coastguard Worker * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*49cdfc7eSAndroid Build Coastguard Worker * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13*49cdfc7eSAndroid Build Coastguard Worker * the GNU General Public License for more details.
14*49cdfc7eSAndroid Build Coastguard Worker *
15*49cdfc7eSAndroid Build Coastguard Worker * You should have received a copy of the GNU General Public License
16*49cdfc7eSAndroid Build Coastguard Worker * along with this program; if not, write to the Free Software
17*49cdfc7eSAndroid Build Coastguard Worker * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*49cdfc7eSAndroid Build Coastguard Worker */
19*49cdfc7eSAndroid Build Coastguard Worker
20*49cdfc7eSAndroid Build Coastguard Worker /*
21*49cdfc7eSAndroid Build Coastguard Worker * Test Name: recv01
22*49cdfc7eSAndroid Build Coastguard Worker *
23*49cdfc7eSAndroid Build Coastguard Worker * Test Description:
24*49cdfc7eSAndroid Build Coastguard Worker * Verify that recv() returns the proper errno for various failure cases
25*49cdfc7eSAndroid Build Coastguard Worker *
26*49cdfc7eSAndroid Build Coastguard Worker * Usage: <for command-line>
27*49cdfc7eSAndroid Build Coastguard Worker * recv01 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
28*49cdfc7eSAndroid Build Coastguard Worker * where, -c n : Run n copies concurrently.
29*49cdfc7eSAndroid Build Coastguard Worker * -e : Turn on errno logging.
30*49cdfc7eSAndroid Build Coastguard Worker * -i n : Execute test n times.
31*49cdfc7eSAndroid Build Coastguard Worker * -I x : Execute test for x seconds.
32*49cdfc7eSAndroid Build Coastguard Worker * -P x : Pause for x seconds between iterations.
33*49cdfc7eSAndroid Build Coastguard Worker * -t : Turn on syscall timing.
34*49cdfc7eSAndroid Build Coastguard Worker *
35*49cdfc7eSAndroid Build Coastguard Worker * HISTORY
36*49cdfc7eSAndroid Build Coastguard Worker * 07/2001 Ported by Wayne Boyer
37*49cdfc7eSAndroid Build Coastguard Worker *
38*49cdfc7eSAndroid Build Coastguard Worker * RESTRICTIONS:
39*49cdfc7eSAndroid Build Coastguard Worker * None.
40*49cdfc7eSAndroid Build Coastguard Worker *
41*49cdfc7eSAndroid Build Coastguard Worker */
42*49cdfc7eSAndroid Build Coastguard Worker
43*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
44*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
45*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
46*49cdfc7eSAndroid Build Coastguard Worker #include <fcntl.h>
47*49cdfc7eSAndroid Build Coastguard Worker
48*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
49*49cdfc7eSAndroid Build Coastguard Worker #include <sys/socket.h>
50*49cdfc7eSAndroid Build Coastguard Worker #include <sys/signal.h>
51*49cdfc7eSAndroid Build Coastguard Worker #include <sys/un.h>
52*49cdfc7eSAndroid Build Coastguard Worker
53*49cdfc7eSAndroid Build Coastguard Worker #include <netinet/in.h>
54*49cdfc7eSAndroid Build Coastguard Worker
55*49cdfc7eSAndroid Build Coastguard Worker #include "test.h"
56*49cdfc7eSAndroid Build Coastguard Worker #include "safe_macros.h"
57*49cdfc7eSAndroid Build Coastguard Worker
58*49cdfc7eSAndroid Build Coastguard Worker char *TCID = "recv01";
59*49cdfc7eSAndroid Build Coastguard Worker int testno;
60*49cdfc7eSAndroid Build Coastguard Worker
61*49cdfc7eSAndroid Build Coastguard Worker char buf[1024];
62*49cdfc7eSAndroid Build Coastguard Worker int s; /* socket descriptor */
63*49cdfc7eSAndroid Build Coastguard Worker struct sockaddr_in sin1, sin2, sin3, sin4;
64*49cdfc7eSAndroid Build Coastguard Worker static int sfd; /* shared between do_child and start_server */
65*49cdfc7eSAndroid Build Coastguard Worker
66*49cdfc7eSAndroid Build Coastguard Worker void do_child(void), setup(void), setup0(void), setup1(void),
67*49cdfc7eSAndroid Build Coastguard Worker cleanup(void), cleanup0(void), cleanup1(void);
68*49cdfc7eSAndroid Build Coastguard Worker pid_t start_server(struct sockaddr_in *);
69*49cdfc7eSAndroid Build Coastguard Worker
70*49cdfc7eSAndroid Build Coastguard Worker struct test_case_t { /* test case structure */
71*49cdfc7eSAndroid Build Coastguard Worker int domain; /* PF_INET, PF_UNIX, ... */
72*49cdfc7eSAndroid Build Coastguard Worker int type; /* SOCK_STREAM, SOCK_DGRAM ... */
73*49cdfc7eSAndroid Build Coastguard Worker int proto; /* protocol number (usually 0 = default) */
74*49cdfc7eSAndroid Build Coastguard Worker void *buf; /* recv data buffer */
75*49cdfc7eSAndroid Build Coastguard Worker int buflen; /* recv's 3rd argument */
76*49cdfc7eSAndroid Build Coastguard Worker unsigned flags; /* recv's 4th argument */
77*49cdfc7eSAndroid Build Coastguard Worker int retval; /* syscall return value */
78*49cdfc7eSAndroid Build Coastguard Worker int experrno; /* expected errno */
79*49cdfc7eSAndroid Build Coastguard Worker void (*setup) (void);
80*49cdfc7eSAndroid Build Coastguard Worker void (*cleanup) (void);
81*49cdfc7eSAndroid Build Coastguard Worker char *desc;
82*49cdfc7eSAndroid Build Coastguard Worker } tdat[] = {
83*49cdfc7eSAndroid Build Coastguard Worker {
84*49cdfc7eSAndroid Build Coastguard Worker PF_INET, SOCK_STREAM, 0, buf, sizeof(buf), 0,
85*49cdfc7eSAndroid Build Coastguard Worker -1, EBADF, setup0, cleanup0, "bad file descriptor"}
86*49cdfc7eSAndroid Build Coastguard Worker , {
87*49cdfc7eSAndroid Build Coastguard Worker 0, 0, 0, buf, sizeof(buf), 0,
88*49cdfc7eSAndroid Build Coastguard Worker -1, ENOTSOCK, setup0, cleanup0, "invalid socket"}
89*49cdfc7eSAndroid Build Coastguard Worker ,
90*49cdfc7eSAndroid Build Coastguard Worker {
91*49cdfc7eSAndroid Build Coastguard Worker PF_INET, SOCK_STREAM, 0, (void *)-1, sizeof(buf), 0,
92*49cdfc7eSAndroid Build Coastguard Worker -1, EFAULT, setup1, cleanup1, "invalid recv buffer"}
93*49cdfc7eSAndroid Build Coastguard Worker ,
94*49cdfc7eSAndroid Build Coastguard Worker {
95*49cdfc7eSAndroid Build Coastguard Worker PF_INET, SOCK_STREAM, 0, buf, sizeof(buf), MSG_OOB,
96*49cdfc7eSAndroid Build Coastguard Worker -1, EINVAL, setup1, cleanup1, "invalid MSG_OOB flag set"}
97*49cdfc7eSAndroid Build Coastguard Worker ,
98*49cdfc7eSAndroid Build Coastguard Worker {
99*49cdfc7eSAndroid Build Coastguard Worker PF_INET, SOCK_STREAM, 0, buf, sizeof(buf), MSG_ERRQUEUE,
100*49cdfc7eSAndroid Build Coastguard Worker -1, EAGAIN, setup1, cleanup1, "invalid MSG_ERRQUEUE flag set"}
101*49cdfc7eSAndroid Build Coastguard Worker ,};
102*49cdfc7eSAndroid Build Coastguard Worker
103*49cdfc7eSAndroid Build Coastguard Worker int TST_TOTAL = sizeof(tdat) / sizeof(tdat[0]);
104*49cdfc7eSAndroid Build Coastguard Worker
main(int argc,char * argv[])105*49cdfc7eSAndroid Build Coastguard Worker int main(int argc, char *argv[])
106*49cdfc7eSAndroid Build Coastguard Worker {
107*49cdfc7eSAndroid Build Coastguard Worker int lc;
108*49cdfc7eSAndroid Build Coastguard Worker
109*49cdfc7eSAndroid Build Coastguard Worker tst_parse_opts(argc, argv, NULL, NULL);
110*49cdfc7eSAndroid Build Coastguard Worker
111*49cdfc7eSAndroid Build Coastguard Worker setup();
112*49cdfc7eSAndroid Build Coastguard Worker
113*49cdfc7eSAndroid Build Coastguard Worker for (lc = 0; TEST_LOOPING(lc); ++lc) {
114*49cdfc7eSAndroid Build Coastguard Worker tst_count = 0;
115*49cdfc7eSAndroid Build Coastguard Worker for (testno = 0; testno < TST_TOTAL; ++testno) {
116*49cdfc7eSAndroid Build Coastguard Worker if ((tst_kvercmp(3, 17, 0) < 0)
117*49cdfc7eSAndroid Build Coastguard Worker && (tdat[testno].flags & MSG_ERRQUEUE)
118*49cdfc7eSAndroid Build Coastguard Worker && (tdat[testno].type & SOCK_STREAM)) {
119*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TCONF, "skip MSG_ERRQUEUE test, "
120*49cdfc7eSAndroid Build Coastguard Worker "it's supported from 3.17");
121*49cdfc7eSAndroid Build Coastguard Worker continue;
122*49cdfc7eSAndroid Build Coastguard Worker }
123*49cdfc7eSAndroid Build Coastguard Worker
124*49cdfc7eSAndroid Build Coastguard Worker tdat[testno].setup();
125*49cdfc7eSAndroid Build Coastguard Worker TEST(recv(s, tdat[testno].buf, tdat[testno].buflen,
126*49cdfc7eSAndroid Build Coastguard Worker tdat[testno].flags));
127*49cdfc7eSAndroid Build Coastguard Worker if (TEST_RETURN > 0)
128*49cdfc7eSAndroid Build Coastguard Worker TEST_RETURN = 0; /* all nonzero equal here */
129*49cdfc7eSAndroid Build Coastguard Worker if (TEST_RETURN != tdat[testno].retval ||
130*49cdfc7eSAndroid Build Coastguard Worker (TEST_RETURN < 0 &&
131*49cdfc7eSAndroid Build Coastguard Worker TEST_ERRNO != tdat[testno].experrno)) {
132*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "%s ; returned"
133*49cdfc7eSAndroid Build Coastguard Worker " %ld (expected %d), errno %d (expected"
134*49cdfc7eSAndroid Build Coastguard Worker " %d)", tdat[testno].desc,
135*49cdfc7eSAndroid Build Coastguard Worker TEST_RETURN, tdat[testno].retval,
136*49cdfc7eSAndroid Build Coastguard Worker TEST_ERRNO, tdat[testno].experrno);
137*49cdfc7eSAndroid Build Coastguard Worker } else {
138*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TPASS, "%s successful",
139*49cdfc7eSAndroid Build Coastguard Worker tdat[testno].desc);
140*49cdfc7eSAndroid Build Coastguard Worker }
141*49cdfc7eSAndroid Build Coastguard Worker tdat[testno].cleanup();
142*49cdfc7eSAndroid Build Coastguard Worker }
143*49cdfc7eSAndroid Build Coastguard Worker }
144*49cdfc7eSAndroid Build Coastguard Worker cleanup();
145*49cdfc7eSAndroid Build Coastguard Worker
146*49cdfc7eSAndroid Build Coastguard Worker tst_exit();
147*49cdfc7eSAndroid Build Coastguard Worker }
148*49cdfc7eSAndroid Build Coastguard Worker
149*49cdfc7eSAndroid Build Coastguard Worker pid_t pid;
150*49cdfc7eSAndroid Build Coastguard Worker
setup(void)151*49cdfc7eSAndroid Build Coastguard Worker void setup(void)
152*49cdfc7eSAndroid Build Coastguard Worker {
153*49cdfc7eSAndroid Build Coastguard Worker TEST_PAUSE;
154*49cdfc7eSAndroid Build Coastguard Worker
155*49cdfc7eSAndroid Build Coastguard Worker pid = start_server(&sin1);
156*49cdfc7eSAndroid Build Coastguard Worker
157*49cdfc7eSAndroid Build Coastguard Worker (void)signal(SIGPIPE, SIG_IGN);
158*49cdfc7eSAndroid Build Coastguard Worker }
159*49cdfc7eSAndroid Build Coastguard Worker
cleanup(void)160*49cdfc7eSAndroid Build Coastguard Worker void cleanup(void)
161*49cdfc7eSAndroid Build Coastguard Worker {
162*49cdfc7eSAndroid Build Coastguard Worker (void)kill(pid, SIGKILL);
163*49cdfc7eSAndroid Build Coastguard Worker
164*49cdfc7eSAndroid Build Coastguard Worker }
165*49cdfc7eSAndroid Build Coastguard Worker
setup0(void)166*49cdfc7eSAndroid Build Coastguard Worker void setup0(void)
167*49cdfc7eSAndroid Build Coastguard Worker {
168*49cdfc7eSAndroid Build Coastguard Worker if (tdat[testno].experrno == EBADF)
169*49cdfc7eSAndroid Build Coastguard Worker s = 400; /* anything not an open file */
170*49cdfc7eSAndroid Build Coastguard Worker else if ((s = open("/dev/null", O_WRONLY)) == -1)
171*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TBROK | TERRNO, cleanup, "open(/dev/null)");
172*49cdfc7eSAndroid Build Coastguard Worker }
173*49cdfc7eSAndroid Build Coastguard Worker
cleanup0(void)174*49cdfc7eSAndroid Build Coastguard Worker void cleanup0(void)
175*49cdfc7eSAndroid Build Coastguard Worker {
176*49cdfc7eSAndroid Build Coastguard Worker s = -1;
177*49cdfc7eSAndroid Build Coastguard Worker }
178*49cdfc7eSAndroid Build Coastguard Worker
setup1(void)179*49cdfc7eSAndroid Build Coastguard Worker void setup1(void)
180*49cdfc7eSAndroid Build Coastguard Worker {
181*49cdfc7eSAndroid Build Coastguard Worker fd_set rdfds;
182*49cdfc7eSAndroid Build Coastguard Worker struct timeval timeout;
183*49cdfc7eSAndroid Build Coastguard Worker int n;
184*49cdfc7eSAndroid Build Coastguard Worker
185*49cdfc7eSAndroid Build Coastguard Worker s = SAFE_SOCKET(cleanup, tdat[testno].domain, tdat[testno].type,
186*49cdfc7eSAndroid Build Coastguard Worker tdat[testno].proto);
187*49cdfc7eSAndroid Build Coastguard Worker if (tdat[testno].type == SOCK_STREAM &&
188*49cdfc7eSAndroid Build Coastguard Worker connect(s, (struct sockaddr *)&sin1, sizeof(sin1)) < 0) {
189*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TBROK | TERRNO, cleanup, "connect failed");
190*49cdfc7eSAndroid Build Coastguard Worker }
191*49cdfc7eSAndroid Build Coastguard Worker /* Wait for something to be readable, else we won't detect EFAULT on recv */
192*49cdfc7eSAndroid Build Coastguard Worker FD_ZERO(&rdfds);
193*49cdfc7eSAndroid Build Coastguard Worker FD_SET(s, &rdfds);
194*49cdfc7eSAndroid Build Coastguard Worker timeout.tv_sec = 2;
195*49cdfc7eSAndroid Build Coastguard Worker timeout.tv_usec = 0;
196*49cdfc7eSAndroid Build Coastguard Worker n = select(s + 1, &rdfds, 0, 0, &timeout);
197*49cdfc7eSAndroid Build Coastguard Worker if (n != 1 || !FD_ISSET(s, &rdfds))
198*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TBROK, cleanup,
199*49cdfc7eSAndroid Build Coastguard Worker "client setup1 failed - no message ready in 2 sec");
200*49cdfc7eSAndroid Build Coastguard Worker }
201*49cdfc7eSAndroid Build Coastguard Worker
cleanup1(void)202*49cdfc7eSAndroid Build Coastguard Worker void cleanup1(void)
203*49cdfc7eSAndroid Build Coastguard Worker {
204*49cdfc7eSAndroid Build Coastguard Worker (void)close(s);
205*49cdfc7eSAndroid Build Coastguard Worker s = -1;
206*49cdfc7eSAndroid Build Coastguard Worker }
207*49cdfc7eSAndroid Build Coastguard Worker
start_server(struct sockaddr_in * sin0)208*49cdfc7eSAndroid Build Coastguard Worker pid_t start_server(struct sockaddr_in *sin0)
209*49cdfc7eSAndroid Build Coastguard Worker {
210*49cdfc7eSAndroid Build Coastguard Worker pid_t pid;
211*49cdfc7eSAndroid Build Coastguard Worker socklen_t slen = sizeof(*sin0);
212*49cdfc7eSAndroid Build Coastguard Worker
213*49cdfc7eSAndroid Build Coastguard Worker sin0->sin_family = AF_INET;
214*49cdfc7eSAndroid Build Coastguard Worker sin0->sin_port = 0; /* pick random free port */
215*49cdfc7eSAndroid Build Coastguard Worker sin0->sin_addr.s_addr = INADDR_ANY;
216*49cdfc7eSAndroid Build Coastguard Worker
217*49cdfc7eSAndroid Build Coastguard Worker sfd = socket(PF_INET, SOCK_STREAM, 0);
218*49cdfc7eSAndroid Build Coastguard Worker if (sfd < 0) {
219*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TBROK | TERRNO, cleanup, "server socket failed");
220*49cdfc7eSAndroid Build Coastguard Worker return -1;
221*49cdfc7eSAndroid Build Coastguard Worker }
222*49cdfc7eSAndroid Build Coastguard Worker if (bind(sfd, (struct sockaddr *)sin0, sizeof(*sin0)) < 0) {
223*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TBROK | TERRNO, cleanup, "server bind failed");
224*49cdfc7eSAndroid Build Coastguard Worker return -1;
225*49cdfc7eSAndroid Build Coastguard Worker }
226*49cdfc7eSAndroid Build Coastguard Worker if (listen(sfd, 10) < 0) {
227*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TBROK | TERRNO, cleanup, "server listen failed");
228*49cdfc7eSAndroid Build Coastguard Worker return -1;
229*49cdfc7eSAndroid Build Coastguard Worker }
230*49cdfc7eSAndroid Build Coastguard Worker SAFE_GETSOCKNAME(cleanup, sfd, (struct sockaddr *)sin0, &slen);
231*49cdfc7eSAndroid Build Coastguard Worker
232*49cdfc7eSAndroid Build Coastguard Worker switch ((pid = tst_fork())) {
233*49cdfc7eSAndroid Build Coastguard Worker case 0: /* child */
234*49cdfc7eSAndroid Build Coastguard Worker do_child();
235*49cdfc7eSAndroid Build Coastguard Worker break;
236*49cdfc7eSAndroid Build Coastguard Worker case -1:
237*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TBROK | TERRNO, cleanup, "server fork failed");
238*49cdfc7eSAndroid Build Coastguard Worker /* fall through */
239*49cdfc7eSAndroid Build Coastguard Worker default: /* parent */
240*49cdfc7eSAndroid Build Coastguard Worker (void)close(sfd);
241*49cdfc7eSAndroid Build Coastguard Worker return pid;
242*49cdfc7eSAndroid Build Coastguard Worker }
243*49cdfc7eSAndroid Build Coastguard Worker
244*49cdfc7eSAndroid Build Coastguard Worker exit(1);
245*49cdfc7eSAndroid Build Coastguard Worker }
246*49cdfc7eSAndroid Build Coastguard Worker
do_child(void)247*49cdfc7eSAndroid Build Coastguard Worker void do_child(void)
248*49cdfc7eSAndroid Build Coastguard Worker {
249*49cdfc7eSAndroid Build Coastguard Worker struct sockaddr_in fsin;
250*49cdfc7eSAndroid Build Coastguard Worker fd_set afds, rfds;
251*49cdfc7eSAndroid Build Coastguard Worker int nfds, cc, fd;
252*49cdfc7eSAndroid Build Coastguard Worker
253*49cdfc7eSAndroid Build Coastguard Worker FD_ZERO(&afds);
254*49cdfc7eSAndroid Build Coastguard Worker FD_SET(sfd, &afds);
255*49cdfc7eSAndroid Build Coastguard Worker
256*49cdfc7eSAndroid Build Coastguard Worker nfds = sfd + 1;
257*49cdfc7eSAndroid Build Coastguard Worker
258*49cdfc7eSAndroid Build Coastguard Worker /* accept connections until killed */
259*49cdfc7eSAndroid Build Coastguard Worker while (1) {
260*49cdfc7eSAndroid Build Coastguard Worker socklen_t fromlen;
261*49cdfc7eSAndroid Build Coastguard Worker
262*49cdfc7eSAndroid Build Coastguard Worker memcpy(&rfds, &afds, sizeof(rfds));
263*49cdfc7eSAndroid Build Coastguard Worker
264*49cdfc7eSAndroid Build Coastguard Worker if (select(nfds, &rfds, NULL, NULL,
265*49cdfc7eSAndroid Build Coastguard Worker NULL) < 0)
266*49cdfc7eSAndroid Build Coastguard Worker if (errno != EINTR)
267*49cdfc7eSAndroid Build Coastguard Worker exit(1);
268*49cdfc7eSAndroid Build Coastguard Worker if (FD_ISSET(sfd, &rfds)) {
269*49cdfc7eSAndroid Build Coastguard Worker int newfd;
270*49cdfc7eSAndroid Build Coastguard Worker
271*49cdfc7eSAndroid Build Coastguard Worker fromlen = sizeof(fsin);
272*49cdfc7eSAndroid Build Coastguard Worker newfd = accept(sfd, (struct sockaddr *)&fsin, &fromlen);
273*49cdfc7eSAndroid Build Coastguard Worker if (newfd >= 0) {
274*49cdfc7eSAndroid Build Coastguard Worker FD_SET(newfd, &afds);
275*49cdfc7eSAndroid Build Coastguard Worker nfds = MAX(nfds, newfd + 1);
276*49cdfc7eSAndroid Build Coastguard Worker /* send something back */
277*49cdfc7eSAndroid Build Coastguard Worker (void)write(newfd, "hoser\n", 6);
278*49cdfc7eSAndroid Build Coastguard Worker }
279*49cdfc7eSAndroid Build Coastguard Worker }
280*49cdfc7eSAndroid Build Coastguard Worker for (fd = 0; fd < nfds; ++fd)
281*49cdfc7eSAndroid Build Coastguard Worker if (fd != sfd && FD_ISSET(fd, &rfds)) {
282*49cdfc7eSAndroid Build Coastguard Worker cc = read(fd, buf, sizeof(buf));
283*49cdfc7eSAndroid Build Coastguard Worker if (cc == 0 || (cc < 0 && errno != EINTR)) {
284*49cdfc7eSAndroid Build Coastguard Worker (void)close(fd);
285*49cdfc7eSAndroid Build Coastguard Worker FD_CLR(fd, &afds);
286*49cdfc7eSAndroid Build Coastguard Worker }
287*49cdfc7eSAndroid Build Coastguard Worker }
288*49cdfc7eSAndroid Build Coastguard Worker }
289*49cdfc7eSAndroid Build Coastguard Worker }
290