diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2019-11-03 00:48:40 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2019-11-03 00:48:40 +0000 |
| commit | a326427caf9da174f6dda7664cdf0e7b769b9933 (patch) | |
| tree | a6ae4607e7e4bf1a82028c3e94252044ef2aaf9a /server.c | |
| parent | Merge branch 'async-ptmx' (diff) | |
server: set CLOEXEC | NONBLOCK directly in socket() call
Diffstat (limited to 'server.c')
| -rw-r--r-- | server.c | 19 |
1 files changed, 2 insertions, 17 deletions
@@ -225,22 +225,12 @@ try_connect(const char *sock_path) { enum connect_status ret = CONNECT_ERR; - int fd = socket(AF_UNIX, SOCK_STREAM, 0); + int fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0); if (fd == -1) { LOG_ERRNO("failed to create UNIX socket"); goto err; } - /* Use non-blocking, so that we don't get stuck in connect() - * waiting for a timeout */ - int flags; - if ((flags = fcntl(fd, F_GETFL)) < 0 || - fcntl(fd, F_SETFL, flags | O_NONBLOCK)) - { - LOG_ERRNO("failed to set O_NONBLOCK"); - goto err; - } - struct sockaddr_un addr = {.sun_family = AF_UNIX}; strncpy(addr.sun_path, sock_path, sizeof(addr.sun_path) - 1); @@ -264,7 +254,7 @@ err: struct server * server_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl) { - int fd = socket(AF_UNIX, SOCK_STREAM, 0); + int fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); if (fd == -1) { LOG_ERRNO("failed to create UNIX socket"); return NULL; @@ -290,11 +280,6 @@ server_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl) unlink(sock_path); - if (fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC) < 0) { - LOG_ERRNO("failed to set FD_CLOEXEC on socket"); - goto err; - } - struct sockaddr_un addr = {.sun_family = AF_UNIX}; strncpy(addr.sun_path, sock_path, sizeof(addr.sun_path) - 1); |
