]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
priv: on Linux, when monitor dies, kill child
authorVincent Bernat <vincent@bernat.im>
Wed, 18 Mar 2015 09:00:44 +0000 (10:00 +0100)
committerVincent Bernat <vincent@bernat.im>
Wed, 18 Mar 2015 09:00:44 +0000 (10:00 +0100)
When the monitor dies, it sends its child a TERM signal but if it
segfaults or is killed with an uncatchable signal, the child will
continue to run "unharmed". On Linux, it is possible to send a signal to
the child in this case, with `prctl()`. Do that.

src/daemon/lldpd.h
src/daemon/priv-bsd.c
src/daemon/priv-linux.c
src/daemon/priv.c

index 72d523172440a0df163542bb149cd7783ed656ab..aea2b716f5d1abef203f9dd542daf3775a727323 100644 (file)
@@ -221,6 +221,7 @@ client_handle_client(struct lldpd *cfg,
 
 /* priv.c */
 void    priv_init(const char*, int, uid_t, gid_t);
+void    priv_init_os(void);
 void    priv_wait(void);
 void    priv_ctl_cleanup(const char *ctlname);
 char           *priv_gethostname(void);
index f32f990cb15269d1da5b776a86971512691725d3..3b13b757e203c3573c7ca0b46d0c773535cf97e3 100644 (file)
 #include <errno.h>
 #include <string.h>
 
+void
+priv_init_os()
+{
+}
+
 int
 asroot_iface_init_os(int ifindex, char *name, int *fd)
 {
index c5736155c607ec722e164170ce222a9b5c9d099c..69054cd7c72338a516d82cccd174332fff7d5642 100644 (file)
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <signal.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <regex.h>
 #include <sys/ioctl.h>
+#include <sys/prctl.h>
 #include <netpacket/packet.h> /* For sockaddr_ll */
 #include <linux/filter.h>     /* For BPF filtering */
 #include <linux/ethtool.h>
 #include <linux/sockios.h>
 
+void
+priv_init_os()
+{
+       if (prctl(PR_SET_PDEATHSIG, SIGTERM) == -1)
+               log_warn("privsep", "unable to setup parent death signal");
+}
+
 /* Proxy for open */
 int
 priv_open(char *file)
index 0d9ea4a2ec62737286b1410d8939f78f5386c2f0..92d7824c596d15525dae446cd5bbdcd2160fb12b 100644 (file)
@@ -633,6 +633,7 @@ priv_init(const char *chrootdir, int ctl, uid_t uid, gid_t gid)
 #endif
                }
                close(pair[1]);
+               priv_init_os();
                priv_ping();
                break;
        default: