From: Lennart Poettering Date: Mon, 24 May 2010 16:59:46 +0000 (+0200) Subject: sd-daemon: set FD_CLOEXEC by default X-Git-Tag: 0.git+20100605+dfd8ee-1~11^2^2~9 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8640e111358257bbdd19582c0cac6166e87bd277;p=systemd sd-daemon: set FD_CLOEXEC by default --- diff --git a/src/sd-daemon.c b/src/sd-daemon.c index eec47227..2e1bf321 100644 --- a/src/sd-daemon.c +++ b/src/sd-daemon.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -41,7 +42,7 @@ int sd_listen_fds(int unset_environment) { #ifdef DISABLE_SYSTEMD return 0; #else - int r; + int r, fd; const char *e; char *p = NULL; unsigned long l; @@ -88,6 +89,24 @@ int sd_listen_fds(int unset_environment) { goto finish; } + + for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + (int) l; fd ++) { + int flags; + + if ((flags = fcntl(fd, F_GETFD)) < 0) { + r = -errno; + goto finish; + } + + if (flags & FD_CLOEXEC) + continue; + + if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) { + r = -errno; + goto finish; + } + } + r = (int) l; finish: