1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

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.
This commit is contained in:
Ondrej Kozina 2015-01-30 15:15:24 +01:00
parent 9dd81df8b2
commit f73526f58c
2 changed files with 6 additions and 3 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.117 -
====================================
set CLOEXEC flag on file descriptors originating in libdaemon
Version 2.02.116 - 30th January 2015
====================================

View File

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