Make set_pidfile() easier to use.
authorBen Pfaff <blp@nicira.com>
Tue, 22 Jul 2008 20:53:20 +0000 (13:53 -0700)
committerBen Pfaff <blp@nicira.com>
Tue, 22 Jul 2008 20:56:26 +0000 (13:56 -0700)
controller/controller.c
lib/daemon.c
secchan/secchan.c
switch/switch.c

index 8e2c7b5..61a550a 100644 (file)
@@ -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':
index 2a835be..e14b776 100644 (file)
@@ -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
index 5577a27..3c96312 100644 (file)
@@ -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':
index ee61fd6..d745bc8 100644 (file)
@@ -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':