4 #include <sys/socket.h>
10 pthread_barrier_t barrier;
12 const struct sigevent *sev;
15 static void *start(void *p)
17 struct args *args = p;
21 void (*func)(union sigval) = args->sev->sigev_notify_function;
22 union sigval val = args->sev->sigev_value;
24 pthread_barrier_wait(&args->barrier);
25 n = recv(s, buf, sizeof(buf), MSG_NOSIGNAL|MSG_WAITALL);
27 if (n==sizeof buf && buf[sizeof buf - 1] == 1)
32 int mq_notify(mqd_t mqd, const struct sigevent *sev)
34 struct args args = { .sev = sev };
39 static const char zeros[32];
41 if (!sev || sev->sigev_notify != SIGEV_THREAD)
42 return syscall(SYS_mq_notify, mqd, sev);
44 s = socket(AF_NETLINK, SOCK_RAW|SOCK_CLOEXEC, 0);
48 if (sev->sigev_notify_attributes) attr = *sev->sigev_notify_attributes;
49 else pthread_attr_init(&attr);
50 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
51 pthread_barrier_init(&args.barrier, 0, 2);
53 if (pthread_create(&td, &attr, start, &args)) {
54 __syscall(SYS_close, s);
59 pthread_barrier_wait(&args.barrier);
60 pthread_barrier_destroy(&args.barrier);
62 sev2.sigev_notify = SIGEV_THREAD;
64 sev2.sigev_value.sival_ptr = (void *)&zeros;
66 if (syscall(SYS_mq_notify, mqd, &sev2) < 0) {
68 __syscall(SYS_close, s);