]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
ctl: create control socket with close-on-exec semantic
authorVincent Bernat <vincent@bernat.im>
Wed, 18 Mar 2015 14:14:41 +0000 (15:14 +0100)
committerVincent Bernat <vincent@bernat.im>
Wed, 18 Mar 2015 14:14:41 +0000 (15:14 +0100)
Otherwise, when we spawn lldpcli, it inherits the file descriptor and
doesn't detect if the daemon dies just after because it is listening
itself to the Unix socket.

src/ctl.c

index fd6d50d5772c3275ede081c0f2321cf6e3da2006..5799f1d6325d62fedb0a5066fb859f7a6b441025 100644 (file)
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -46,6 +46,10 @@ ctl_create(const char *name)
 
        if ((s = socket(PF_UNIX, SOCK_STREAM, 0)) == -1)
                return -1;
+       if (fcntl(s, F_SETFD, FD_CLOEXEC) == -1) {
+               close(s);
+               return -1;
+       }
        su.sun_family = AF_UNIX;
        strlcpy(su.sun_path, name, sizeof(su.sun_path));
        if (bind(s, (struct sockaddr *)&su, sizeof(struct sockaddr_un)) == -1) {