11 /* select_bug forks child processes that perform select()
12 /* on a shared socket, and sees if a wakeup affects other
13 /* processes selecting on a different socket or stdin.
15 /* Problems are reported to the standard error stream.
19 /* The Secure Mailer license must be distributed with this software.
22 /* IBM T.J. Watson Research
24 /* Yorktown Heights, NY 10598, USA
31 #include <sys/socket.h>
35 #include <string.h> /* bzero() prototype for 44BSD */
37 /* Utility library. */
41 #include <msg_vstream.h>
43 static pid_t
fork_and_read_select(const char *what
, int delay
, int fd
)
49 switch (pid
= fork()) {
51 msg_fatal("fork: %m");
57 switch (select(fd
+ 1, &readfds
, (fd_set
*) 0, &readfds
, &tv
)) {
59 msg_fatal("select: %m");
61 msg_info("%s select timed out", what
);
64 msg_info("%s select wakeup", what
);
72 int main(int argc
, char **argv
)
77 msg_vstream_init(argv
[0], VSTREAM_ERR
);
81 if (socketpair(AF_UNIX
, SOCK_STREAM
, 0, pair1
) < 0)
82 msg_fatal("socketpair: %m");
83 if (socketpair(AF_UNIX
, SOCK_STREAM
, 0, pair2
) < 0)
84 msg_fatal("socketpair: %m");
86 vstream_printf("Doing multiple select on socket1, then write to it...\n");
87 vstream_fflush(VSTREAM_OUT
);
88 fork_and_read_select("socket1", DELAY
, pair1
[0]); /* one */
89 fork_and_read_select("socket1", DELAY
, pair1
[0]); /* two */
90 fork_and_read_select("socket2", DELAY
, pair2
[0]);
91 fork_and_read_select("stdin", DELAY
, 0);
92 if (write(pair1
[1], "", 1) != 1)
93 msg_fatal("write: %m");
94 while (wait((int *) 0) >= 0)