From 9475dd4c835e23e87967d9668d8a004933384e5c Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Wed, 18 Mar 2015 15:14:41 +0100 Subject: [PATCH] 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. --- src/ctl.c | 4 ++++ 1 file changed, 4 insertions(+) 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) { -- 2.47.2