From: Ben Pfaff Date: Tue, 22 Jul 2008 20:53:20 +0000 (-0700) Subject: Make set_pidfile() easier to use. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f1f1132e58f6bde39af343d15dfb8800bb4c8a8;p=openvswitch Make set_pidfile() easier to use. --- diff --git a/controller/controller.c b/controller/controller.c index 8e2c7b5c..61a550a4 100644 --- a/controller/controller.c +++ b/controller/controller.c @@ -253,7 +253,7 @@ parse_options(int argc, char *argv[]) break; case 'P': - set_pidfile(optarg ? optarg : "controller.pid"); + set_pidfile(optarg); break; case 'H': diff --git a/lib/daemon.c b/lib/daemon.c index 2a835be9..e14b776d 100644 --- a/lib/daemon.c +++ b/lib/daemon.c @@ -52,12 +52,16 @@ static char *pidfile; /* Sets up a following call to daemonize() to create a pidfile named 'name'. * If 'name' begins with '/', then it is treated as an absolute path. * Otherwise, it is taken relative to RUNDIR, which is $(prefix)/var/run by - * default. */ + * default. + * + * If 'name' is null, then program_name followed by ".pid" is used. */ void set_pidfile(const char *name) { free(pidfile); - pidfile = *name == '/' ? xstrdup(name) : xasprintf("%s/%s", RUNDIR, name); + pidfile = (!name ? xasprintf("%s/%s.pid", RUNDIR, program_name) + : *name == '/' ? xstrdup(name) + : xasprintf("%s/%s", RUNDIR, name)); } /* Sets up a following call to daemonize() to detach from the foreground diff --git a/secchan/secchan.c b/secchan/secchan.c index 5577a27a..3c96312f 100644 --- a/secchan/secchan.c +++ b/secchan/secchan.c @@ -754,7 +754,7 @@ parse_options(int argc, char *argv[]) break; case 'P': - set_pidfile(optarg ? optarg : "secchan.pid"); + set_pidfile(optarg); break; case 'l': diff --git a/switch/switch.c b/switch/switch.c index ee61fd6d..d745bc83 100644 --- a/switch/switch.c +++ b/switch/switch.c @@ -200,7 +200,7 @@ parse_options(int argc, char *argv[]) break; case 'P': - set_pidfile(optarg ? optarg : "switch.pid"); + set_pidfile(optarg); break; case 'v':