4 #include <sys/socket.h>
13 const struct sigevent *sev;
16 static void *start(void *p)
18 struct args *args = p;
22 void (*func)(union sigval) = args->sev->sigev_notify_function;
23 union sigval val = args->sev->sigev_value;
26 n = recv(s, buf, sizeof(buf), MSG_NOSIGNAL|MSG_WAITALL);
28 if (n==sizeof buf && buf[sizeof buf - 1] == 1)
33 int mq_notify(mqd_t mqd, const struct sigevent *sev)
35 struct args args = { .sev = sev };
40 static const char zeros[32];
43 if (!sev || sev->sigev_notify != SIGEV_THREAD)
44 return syscall(SYS_mq_notify, mqd, sev);
46 s = socket(AF_NETLINK, SOCK_RAW|SOCK_CLOEXEC, 0);
50 if (sev->sigev_notify_attributes) attr = *sev->sigev_notify_attributes;
51 else pthread_attr_init(&attr);
52 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
53 sem_init(&args.sem, 0, 0);
55 if (pthread_create(&td, &attr, start, &args)) {
56 __syscall(SYS_close, s);
61 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
63 pthread_setcancelstate(cs, 0);
64 sem_destroy(&args.sem);
66 sev2.sigev_notify = SIGEV_THREAD;
68 sev2.sigev_value.sival_ptr = (void *)&zeros;
70 if (syscall(SYS_mq_notify, mqd, &sev2) < 0) {
72 __syscall(SYS_close, s);