commit 23a9967121cd2e7ead33dc7ccdeac7d8be2855c8 from: Omar Polo date: Sun Oct 08 19:11:45 2023 UTC (cont) work around lack of SOCK_{CLOEXEC,NONBLOCK} funny how they're trying to deprecate daemon() in favour of the mess of posix_spawn and still don't provide genuinely useful stuff like SOCK_CLOEXEC, NONBLOCK and pipe2(2). commit - 1738062c340fe8420ec57741ef1f53fd7a1a3904 commit + 23a9967121cd2e7ead33dc7ccdeac7d8be2855c8 blob - 71b8cc38bc317ae9fe20972282bf0dcc0f84f350 blob + dfecb8c2146a1d26235b34e947cac4aadec6e160 --- control.c +++ control.c @@ -135,14 +135,13 @@ control_listen(int fd) void control_accept(int listenfd, int event, void *bula) { - int connfd; + int connfd, flags; socklen_t len; struct sockaddr_un sun; struct ctl_conn *c; len = sizeof(sun); - if ((connfd = accept4(listenfd, (struct sockaddr *)&sun, &len, - SOCK_CLOEXEC | SOCK_NONBLOCK)) == -1) { + if ((connfd = accept(listenfd, (struct sockaddr *)&sun, &len)) == -1) { /* * Pause accept if we are out of file descriptors, or * libevent will haunt us here too. @@ -158,6 +157,12 @@ control_accept(int listenfd, int event, void *bula) return; } + if ((flags = fcntl(connfd, F_GETFL)) == -1 || + fcntl(connfd, F_SETFL, flags | O_NONBLOCK) == -1) + fatal("fcntl(O_NONBLOCK)"); + if (fcntl(connfd, F_SETFD, FD_CLOEXEC) == -1) + fatal("fcntl(CLOEXEC)"); + if ((c = calloc(1, sizeof(struct ctl_conn))) == NULL) { log_warn("%s: calloc", __func__); close(connfd);