commit - dc3e25b130aee2682cc370e9505fd7386cbe8b53
commit + 1738062c340fe8420ec57741ef1f53fd7a1a3904
blob - 83dcac522cc6d73a9d38e86f10d5e68f1bfa21a1
blob + 35aea2615072b1e68d1f572b0064c6e0d28f3e5b
--- amused.c
+++ amused.c
amused_main(void)
{
int pipe_main2player[2];
- int control_fd;
+ int control_fd, flags;
log_init(debug, LOG_DAEMON);
log_setverbose(verbose);
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
#include <net/if.h>
#include <errno.h>
+#include <fcntl.h>
#include <limits.h>
#include <poll.h>
#include <stdio.h>
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));