]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
Fork earlier (before monitor creation); otherwise, the unprivileged
authorVincent Bernat <bernat@luffy.cx>
Sun, 16 Nov 2008 20:38:30 +0000 (21:38 +0100)
committerVincent Bernat <bernat@luffy.cx>
Sun, 16 Nov 2008 20:38:30 +0000 (21:38 +0100)
process will not be the child of the monitor after forking the monitor.

src/lldpd.c
src/lldpd.h
src/priv.c

index 98ed8d483cbcf5f6bb08ed92ef6c3ace4ea79da1..812e82fb705bf3faa5058f30d9d950313285c887 100644 (file)
@@ -1349,6 +1349,22 @@ main(int argc, char *argv[])
 
        log_init(debug);
 
+       if (!debug) {
+               int pid;
+               char *spid;
+               if (daemon(0, 0) != 0)
+                       fatal("failed to detach daemon");
+               if ((pid = open(LLDPD_PID_FILE,
+                           O_TRUNC | O_CREAT | O_WRONLY)) == -1)
+                       fatal("unable to open pid file " LLDPD_PID_FILE);
+               if (asprintf(&spid, "%d\n", getpid()) == -1)
+                       fatal("unable to create pid file " LLDPD_PID_FILE);
+               if (write(pid, spid, strlen(spid)) == -1)
+                       fatal("unable to write pid file " LLDPD_PID_FILE);
+               free(spid);
+               close(pid);
+       }
+
        priv_init(PRIVSEP_CHROOT);
 
        if (probe == 0) probe = LLDPD_TTL;
@@ -1398,9 +1414,6 @@ main(int argc, char *argv[])
        TAILQ_INIT(&cfg->g_clients);
 
        gcfg = cfg;
-       if (!debug) {
-               priv_fork();
-       }
        if (atexit(lldpd_exit) != 0) {
                close(cfg->g_ctl);
                priv_ctl_cleanup();
index f9ee0a6ec4c73d9194504bf633a025380ac06777..59cfdfe44c2c0e75013821d8ad37a28f6e51874c 100644 (file)
@@ -332,7 +332,6 @@ void         client_handle_shutdown(struct lldpd *, struct hmsg *,
 
 /* priv.c */
 void    priv_init(char*);
-void    priv_fork();
 int     priv_ctl_create();
 void    priv_ctl_cleanup();
 char           *priv_gethostbyname();
index c74ddbe171ac6378ffb75781180de42bf9fcdb34..82444e42255b051369b944b2c1c9e8c1fd9f410c 100644 (file)
@@ -42,7 +42,6 @@
 
 enum {
        PRIV_PING,
-       PRIV_FORK,
        PRIV_CREATE_CTL_SOCKET,
        PRIV_DELETE_CTL_SOCKET,
        PRIV_GET_HOSTNAME,
@@ -77,16 +76,6 @@ priv_ping()
        LLOG_DEBUG("monitor ready");
 }
 
-/* Proxy for fork */
-void
-priv_fork()
-{
-       int cmd, rc;
-       cmd = PRIV_FORK;
-       must_write(remote, &cmd, sizeof(int));
-       must_read(remote, &rc, sizeof(int));
-}
-
 /* Proxy for ctl_create, no argument since this is the monitor that decides the
  * location of the socket */
 int
@@ -207,27 +196,6 @@ asroot_ping()
        must_write(remote, &rc, sizeof(int));
 }
 
-void
-asroot_fork()
-{
-       int pid;
-       char *spid;
-       if (daemon(0, 0) != 0)
-               fatal("[priv]: failed to detach daemon");
-       if ((pid = open(LLDPD_PID_FILE,
-                   O_TRUNC | O_CREAT | O_WRONLY)) == -1)
-               fatal("[priv]: unable to open pid file " LLDPD_PID_FILE);
-       if (asprintf(&spid, "%d\n", getpid()) == -1)
-               fatal("[priv]: unable to create pid file " LLDPD_PID_FILE);
-       if (write(pid, spid, strlen(spid)) == -1)
-               fatal("[priv]: unable to write pid file " LLDPD_PID_FILE);
-       free(spid);
-       close(pid);
-
-       /* Ack */
-       must_write(remote, &pid, sizeof(int));
-}
-
 void
 asroot_ctl_create()
 {
@@ -462,7 +430,6 @@ struct dispatch_actions {
 
 struct dispatch_actions actions[] = {
        {PRIV_PING, asroot_ping},
-       {PRIV_FORK, asroot_fork},
        {PRIV_CREATE_CTL_SOCKET, asroot_ctl_create},
        {PRIV_DELETE_CTL_SOCKET, asroot_ctl_cleanup},
        {PRIV_GET_HOSTNAME, asroot_gethostbyname},