From: Vincent Bernat Date: Wed, 18 Mar 2015 14:14:41 +0000 (+0100) Subject: ctl: create control socket with close-on-exec semantic X-Git-Tag: 0.7.14~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9475dd4c835e23e87967d9668d8a004933384e5c;p=thirdparty%2Flldpd.git ctl: create control socket with close-on-exec semantic 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. --- diff --git a/src/ctl.c b/src/ctl.c index fd6d50d5..5799f1d6 100644 --- 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) {