Make all fds close-on-exec

This commit is contained in:
Kristian Høgsberg 2011-04-11 09:24:11 -04:00
parent 8f081748f9
commit 7cfcdc610d
3 changed files with 11 additions and 6 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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;