commit 1738062c340fe8420ec57741ef1f53fd7a1a3904 from: Omar Polo date: Sat Oct 07 22:12:05 2023 UTC work around missing SOCK_{CLOEXEC,NONBLOCK} on some dumb OSes commit - dc3e25b130aee2682cc370e9505fd7386cbe8b53 commit + 1738062c340fe8420ec57741ef1f53fd7a1a3904 blob - 83dcac522cc6d73a9d38e86f10d5e68f1bfa21a1 blob + 35aea2615072b1e68d1f572b0064c6e0d28f3e5b --- amused.c +++ amused.c @@ -243,7 +243,7 @@ static __dead void amused_main(void) { int pipe_main2player[2]; - int control_fd; + int control_fd, flags; log_init(debug, LOG_DAEMON); log_setverbose(verbose); @@ -252,10 +252,19 @@ amused_main(void) if (!debug) daemon(1, 0); - if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, - PF_UNSPEC, pipe_main2player) == -1) + if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_main2player) == -1) fatal("socketpair"); + if ((flags = fcntl(pipe_main2player[0], F_GETFL)) == -1 || + fcntl(pipe_main2player[0], F_SETFL, flags | O_NONBLOCK) == -1 || + (flags = fcntl(pipe_main2player[1], F_GETFL)) == -1 || + fcntl(pipe_main2player[1], F_SETFL, flags | O_NONBLOCK) == -1) + fatal("fcntl(O_NONBLOCK)"); + + if (fcntl(pipe_main2player[0], F_SETFD, FD_CLOEXEC) == -1 || + fcntl(pipe_main2player[1], F_SETFD, FD_CLOEXEC) == -1) + fatal("fcntl(CLOEXEC)"); + player_pid = start_child(PROC_PLAYER, pipe_main2player[1]); if (ev_init() == -1) blob - cc3809eca78536d510012609246122cc0f80868e blob + 71b8cc38bc317ae9fe20972282bf0dcc0f84f350 --- control.c +++ control.c @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -64,15 +65,21 @@ int control_init(char *path) { struct sockaddr_un sun; - int fd; + int fd, flags; mode_t old_umask; - if ((fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, - 0)) == -1) { + if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { log_warn("%s: socket", __func__); return (-1); } + if ((flags = fcntl(fd, F_GETFL)) == -1 || + fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) + fatal("fcntl(O_NONBLOCK)"); + + if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) + fatal("fcntl(CLOEXEC)"); + memset(&sun, 0, sizeof(sun)); sun.sun_family = AF_UNIX; strlcpy(sun.sun_path, path, sizeof(sun.sun_path));