From 7cfcdc610db4c5ef57ea282bff8b2a5406ac3662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Mon, 11 Apr 2011 09:24:11 -0400 Subject: [PATCH] Make all fds close-on-exec --- wayland/event-loop.c | 6 +++--- wayland/wayland-client.c | 3 ++- wayland/wayland-server.c | 8 ++++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/wayland/event-loop.c b/wayland/event-loop.c index 8708571d..8166356f 100644 --- a/wayland/event-loop.c +++ b/wayland/event-loop.c @@ -197,7 +197,7 @@ wl_event_loop_add_timer(struct wl_event_loop *loop, source->base.interface = &timer_source_interface; source->base.loop = loop; - source->fd = timerfd_create(CLOCK_MONOTONIC, 0); + source->fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC); if (source->fd < 0) { fprintf(stderr, "could not create timerfd\n: %m"); free(source); @@ -296,7 +296,7 @@ wl_event_loop_add_signal(struct wl_event_loop *loop, sigemptyset(&mask); sigaddset(&mask, signal_number); - source->fd = signalfd(-1, &mask, 0); + source->fd = signalfd(-1, &mask, SFD_CLOEXEC); if (source->fd < 0) { fprintf(stderr, "could not create fd to watch signal\n: %m"); free(source); @@ -389,7 +389,7 @@ wl_event_loop_create(void) if (loop == NULL) return NULL; - loop->epoll_fd = epoll_create(16); + loop->epoll_fd = epoll_create1(EPOLL_CLOEXEC); if (loop->epoll_fd < 0) { free(loop); return NULL; diff --git a/wayland/wayland-client.c b/wayland/wayland-client.c index c7db0266..adfaf8fd 100644 --- a/wayland/wayland-client.c +++ b/wayland/wayland-client.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include "wayland-client-protocol.h" @@ -328,7 +329,7 @@ connect_to_socket(struct wl_display *display, const char *name) const char *runtime_dir; size_t name_size; - display->fd = socket(PF_LOCAL, SOCK_STREAM, 0); + display->fd = socket(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0); if (display->fd < 0) return -1; diff --git a/wayland/wayland-server.c b/wayland/wayland-server.c index 979b2255..222014a8 100644 --- a/wayland/wayland-server.c +++ b/wayland/wayland-server.c @@ -20,6 +20,8 @@ * OF THIS SOFTWARE. */ +#define _GNU_SOURCE + #include #include #include @@ -33,6 +35,7 @@ #include #include #include +#include #include #include "wayland-server.h" @@ -642,7 +645,8 @@ socket_data(int fd, uint32_t mask, void *data) int client_fd; length = sizeof name; - client_fd = accept (fd, (struct sockaddr *) &name, &length); + client_fd = + accept4(fd, (struct sockaddr *) &name, &length, SOCK_CLOEXEC); if (client_fd < 0) fprintf(stderr, "failed to accept\n"); @@ -660,7 +664,7 @@ wl_display_add_socket(struct wl_display *display, const char *name) if (s == NULL) return -1; - s->fd = socket(PF_LOCAL, SOCK_STREAM, 0); + s->fd = socket(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0); if (s->fd < 0) { free(s); return -1;