4 #include <sys/socket.h>
15 const struct sigevent *sev;
18 static void *start(void *p)
20 struct args *args = p;
24 void (*func)(union sigval) = args->sev->sigev_notify_function;
25 union sigval val = args->sev->sigev_value;
27 static const char zeros[32];
30 sev2.sigev_notify = SIGEV_THREAD;
32 sev2.sigev_value.sival_ptr = (void *)&zeros;
34 args->err = err = -__syscall(SYS_mq_notify, args->mqd, &sev2);
38 pthread_detach(pthread_self());
39 n = recv(s, buf, sizeof(buf), MSG_NOSIGNAL|MSG_WAITALL);
41 if (n==sizeof buf && buf[sizeof buf - 1] == 1)
46 int mq_notify(mqd_t mqd, const struct sigevent *sev)
48 struct args args = { .sev = sev };
54 if (!sev || sev->sigev_notify != SIGEV_THREAD)
55 return syscall(SYS_mq_notify, mqd, sev);
57 s = socket(AF_NETLINK, SOCK_RAW|SOCK_CLOEXEC, 0);
62 if (sev->sigev_notify_attributes) attr = *sev->sigev_notify_attributes;
63 else pthread_attr_init(&attr);
64 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
65 sem_init(&args.sem, 0, 0);
67 if (pthread_create(&td, &attr, start, &args)) {
68 __syscall(SYS_close, s);
73 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
75 sem_destroy(&args.sem);
78 __syscall(SYS_close, s);
80 pthread_setcancelstate(cs, 0);
85 pthread_setcancelstate(cs, 0);