summaryrefslogtreecommitdiff
path: root/libdaemon
diff options
context:
space:
mode:
authorOndrej Kozina <okozina@redhat.com>2015-01-30 15:15:24 +0100
committerOndrej Kozina <okozina@redhat.com>2015-02-02 10:20:35 +0100
commitf73526f58cd8e86a19b5cd8a26449ef40c9697ef (patch)
treeed282773b33f850600b851e526ced07d5e2c7f22 /libdaemon
parent9dd81df8b25a51c919679b5f1c4e5fea9269972b (diff)
downloadlvm2-f73526f58cd8e86a19b5cd8a26449ef40c9697ef.tar.gz
libdaemon: set CLOEXEC flag on systemd socket
all sockets opened by a daemon or handed over by systemd have to have CLOEXEC flag set. Otherwise we get nasty warnings about leaking descriptors in processes spawned by daemon.
Diffstat (limited to 'libdaemon')
-rw-r--r--libdaemon/server/daemon-server.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/libdaemon/server/daemon-server.c b/libdaemon/server/daemon-server.c
index 3dffdbb0b..5ccf4e98c 100644
--- a/libdaemon/server/daemon-server.c
+++ b/libdaemon/server/daemon-server.c
@@ -221,9 +221,7 @@ static int _open_socket(daemon_state s)
goto error;
}
- /* Set Close-on-exec & non-blocking */
- if (fcntl(fd, F_SETFD, 1))
- fprintf(stderr, "setting CLOEXEC on socket fd %d failed: %s\n", fd, strerror(errno));
+ /* Set non-blocking */
if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK))
fprintf(stderr, "setting O_NONBLOCK on socket fd %d failed: %s\n", fd, strerror(errno));
@@ -572,6 +570,10 @@ void daemon_start(daemon_state s)
failed = 1;
}
+ /* Set Close-on-exec */
+ if (fcntl(s.socket_fd, F_SETFD, 1))
+ fprintf(stderr, "setting CLOEXEC on socket fd %d failed: %s\n", s.socket_fd, strerror(errno));
+
/* Signal parent, letting them know we are ready to go. */
if (!s.foreground)
kill(getppid(), SIGTERM);