From: Vincent Bernat Date: Wed, 25 May 2016 15:20:17 +0000 (+0200) Subject: daemon: add a `-p` option to specify PID file X-Git-Tag: 0.9.4~28 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7b6cbfe2605f6f6fffd80ba0ad39fb8b42f16730;p=thirdparty%2Flldpd.git daemon: add a `-p` option to specify PID file Fix #181 --- diff --git a/NEWS b/NEWS index c6f83fae..7b8fd070 100644 --- 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. diff --git a/src/daemon/lldpd.8.in b/src/daemon/lldpd.8.in index 79698571..bba37485 100644 --- a/src/daemon/lldpd.8.in +++ b/src/daemon/lldpd.8.in @@ -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 diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c index ba0b422b..b464c2c0 100644 --- a/src/daemon/lldpd.c +++ b/src/daemon/lldpd.c @@ -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); }