]>
git.saurik.com Git - apple/launchd.git/blob - launchd/testing/missed-EVFILT_WRITE.c
2 * <rdar://problem/4038866> Lots of hangs in GetLaunchDaemonService state
8 #include <sys/socket.h>
16 static void do_parent(int thefd
);
17 static void do_child(int thefd
);
23 if (-1 == socketpair(AF_UNIX
, SOCK_STREAM
, 0, sp
)) {
24 fprintf(stderr
, "socketpair(): %s\n", strerror(errno
));
30 fprintf(stderr
, "fork(): %s\n", strerror(errno
));
45 static void do_child(int thefd
)
51 if (-1 == fcntl(thefd
, F_SETFL
, O_NONBLOCK
)) {
52 fprintf(stderr
, "fcntl(): %s\n", strerror(errno
));
58 if (-1 == write(thefd
, buf
, 1)) {
59 fprintf(stderr
, "%d: write(): %s\n", __LINE__
, strerror(errno
));
64 r
= read(thefd
, buf
, sizeof(buf
));
66 if (-1 == r
&& errno
!= EAGAIN
) {
67 fprintf(stderr
, "%d: read(): %s\n", __LINE__
, strerror(errno
));
80 select(thefd
+ 1, &rfds
, NULL
, NULL
, NULL
);
84 static void do_parent(int thefd
)
86 struct timespec timeout
= { 1, 0 };
89 int iter
= 0, kq
= kqueue();
91 if (-1 == (kq
= kqueue())) {
92 fprintf(stderr
, "kqueue(): %s\n", strerror(errno
));
96 if (-1 == fcntl(thefd
, F_SETFL
, O_NONBLOCK
)) {
97 fprintf(stderr
, "fcntl(): %s\n", strerror(errno
));
101 EV_SET(&kev
, thefd
, EVFILT_READ
, EV_ADD
, 0, 0, NULL
);
103 if (-1 == kevent(kq
, &kev
, 1, NULL
, 0, NULL
)) {
104 fprintf(stderr
, "%d: kevent(): %s\n", __LINE__
, strerror(errno
));
109 switch (kevent(kq
, NULL
, 0, &kev
, 1, &timeout
)) {
111 fprintf(stderr
, "%d: kevent(): %s\n", __LINE__
, strerror(errno
));
114 fprintf(stderr
, "After %d iterations, 4038866 still exists!\n", iter
);
119 fprintf(stderr
, "kevent should only return -1, 0 or 1 for this case!\n");
123 switch (kev
.filter
) {
125 if (-1 == read(thefd
, buf
, sizeof(buf
))) {
126 fprintf(stderr
, "read(): %s\n", strerror(errno
));
129 if (-1 == write(thefd
, buf
, sizeof(buf
))) {
130 fprintf(stderr
, "%d: write(): %s\n", __LINE__
, strerror(errno
));
133 EV_SET(&kev
, thefd
, EVFILT_WRITE
, EV_ADD
, 0, 0, NULL
);
134 if (-1 == kevent(kq
, &kev
, 1, NULL
, 0, NULL
)) {
135 fprintf(stderr
, "%d: kevent(): %s\n", __LINE__
, strerror(errno
));
140 if (-1 == write(thefd
, buf
, 1)) {
141 fprintf(stderr
, "%d: write(): %s\n", __LINE__
, strerror(errno
));
144 EV_SET(&kev
, thefd
, EVFILT_WRITE
, EV_DELETE
, 0, 0, NULL
);
145 if (-1 == kevent(kq
, &kev
, 1, NULL
, 0, NULL
)) {
146 fprintf(stderr
, "%d: kevent(): %s\n", __LINE__
, strerror(errno
));
151 fprintf(stderr
, "kevent filter isn't EVFILT_READ or EVFILT_WRITE!\n");