]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
daemon: add a `-p` option to specify PID file
authorVincent Bernat <vincent@bernat.im>
Wed, 25 May 2016 15:20:17 +0000 (17:20 +0200)
committerVincent Bernat <vincent@bernat.im>
Wed, 25 May 2016 15:20:17 +0000 (17:20 +0200)
Fix #181

NEWS
src/daemon/lldpd.8.in
src/daemon/lldpd.c

diff --git a/NEWS b/NEWS
index c6f83fae94a80f6a1d377a161ae7fc4cc4e593b0..7b8fd070157bd487277e2d54f8264bfe416fba42 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+lldpd (0.9.4)
+  * Change:
+    + Make lldpd accepts a `-p` option to specify the PID file.
+
 lldpd (0.9.3)
   * Change:
     + Do not rely on support of constructors for liblldpctl.
index 7969857148a68c22271a22c6b9709e30e47c8863..bba37485f6f5c25ef2d3c9e2ce243d4b45ddd6c5 100644 (file)
@@ -23,6 +23,7 @@
 .Nm
 .Op Fl dxcseiklrv
 .Op Fl D Ar debug
+.Op Fl p Ar pidfile
 .Op Fl S Ar description
 .Op Fl P Ar platform
 .Op Fl X Ar socket
@@ -120,6 +121,10 @@ Smart filtering of different protocols on the same port.
 .It Sy netlink
 Netlink subsystem.
 .El
+.It Fl p Ar pidfile
+Use the provided PID file to record
+.Nm
+PID instead of @LLDPD_PID_FILE@.
 .It Fl k
 Disable advertising of kernel release, version and machine. Kernel name
 (ie: Linux) will still be shared, and Inventory software version will be set
index ba0b422b92b3338978f9a85ff7993a6145519785..b464c2c01aaded734b2bb7340246e06fc453d3ce 100644 (file)
@@ -1445,7 +1445,7 @@ lldpd_main(int argc, char *argv[], char *envp[])
         * unless there is a very good reason. Most command-line options will
         * get deprecated at some point. */
        char *popt, opts[] =
-               "H:vhkrdD:xX:m:u:4:6:I:C:p:M:P:S:iL:@                    ";
+               "H:vhkrdD:p:xX:m:u:4:6:I:C:p:M:P:S:iL:@                    ";
        int i, found, advertise_version = 1;
 #ifdef ENABLE_LLDPMED
        int lldpmed = 0, noinventory = 0;
@@ -1455,6 +1455,7 @@ lldpd_main(int argc, char *argv[], char *envp[])
        char *platform_override = NULL;
        char *lsb_release = NULL;
        const char *lldpcli = LLDPCLI_PATH;
+       const char *pidfile = LLDPD_PID_FILE;
        int smart = 15;
        int receiveonly = 0, version = 0;
        int ctl;
@@ -1502,6 +1503,9 @@ lldpd_main(int argc, char *argv[], char *envp[])
                case 'D':
                        log_accept(optarg);
                        break;
+               case 'p':
+                       pidfile = optarg;
+                       break;
                case 'r':
                        receiveonly = 1;
                        break;
@@ -1701,13 +1705,16 @@ lldpd_main(int argc, char *argv[], char *envp[])
                log_debug("main", "daemonize");
                if (daemon(0, 0) != 0)
                        fatal("main", "failed to detach daemon");
-               if ((pid = open(LLDPD_PID_FILE,
+               if ((pid = open(pidfile,
                            O_TRUNC | O_CREAT | O_WRONLY, 0666)) == -1)
-                       fatal("main", "unable to open pid file " LLDPD_PID_FILE);
+                       fatal("main", "unable to open pid file " LLDPD_PID_FILE
+                           " (or the specified one)");
                if (asprintf(&spid, "%d\n", getpid()) == -1)
-                       fatal("main", "unable to create pid file " LLDPD_PID_FILE);
+                       fatal("main", "unable to create pid file " LLDPD_PID_FILE
+                           " (or the specified one)");
                if (write(pid, spid, strlen(spid)) == -1)
-                       fatal("main", "unable to write pid file " LLDPD_PID_FILE);
+                       fatal("main", "unable to write pid file " LLDPD_PID_FILE
+                           " (or the specified one)");
                free(spid);
                close(pid);
        }