summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-05-24 18:59:46 +0200
committerLennart Poettering <lennart@poettering.net>2010-05-24 18:59:46 +0200
commit8640e111358257bbdd19582c0cac6166e87bd277 (patch)
tree4bf5686d069193e8033df220b1a30219e9974047
parent8efe3c0114758f229273f17944fd6f2952b10c52 (diff)
sd-daemon: set FD_CLOEXEC by default
-rw-r--r--src/sd-daemon.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/sd-daemon.c b/src/sd-daemon.c
index eec4722709..2e1bf3213c 100644
--- a/src/sd-daemon.c
+++ b/src/sd-daemon.c
@@ -28,6 +28,7 @@
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
+#include <sys/fcntl.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <errno.h>
@@ -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: