diff options
author | Kristian Høgsberg <krh@bitplanet.net> | 2011-04-11 09:24:11 -0400 |
---|---|---|
committer | Kristian Høgsberg <krh@bitplanet.net> | 2011-04-11 09:24:11 -0400 |
commit | 7cfcdc610db4c5ef57ea282bff8b2a5406ac3662 (patch) | |
tree | 7320369d7e0fbbc8607d67fdddacf6a68cb6c1b1 | |
parent | 8f081748f996b91cd49603f62f23d5617f2baf68 (diff) |
Make all fds close-on-exec
-rw-r--r-- | wayland/event-loop.c | 6 | ||||
-rw-r--r-- | wayland/wayland-client.c | 3 | ||||
-rw-r--r-- | 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 8708571..8166356 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 c7db026..adfaf8f 100644 --- a/wayland/wayland-client.c +++ b/wayland/wayland-client.c @@ -31,6 +31,7 @@ #include <sys/un.h> #include <ctype.h> #include <assert.h> +#include <fcntl.h> #include <sys/poll.h> #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 979b225..222014a 100644 --- a/wayland/wayland-server.c +++ b/wayland/wayland-server.c @@ -20,6 +20,8 @@ * OF THIS SOFTWARE. */ +#define _GNU_SOURCE + #include <stdlib.h> #include <stdint.h> #include <stddef.h> @@ -33,6 +35,7 @@ #include <dlfcn.h> #include <assert.h> #include <sys/time.h> +#include <fcntl.h> #include <ffi.h> #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; |