New function make_pidfile_name().
authorBen Pfaff <blp@nicira.com>
Wed, 23 Jul 2008 20:08:31 +0000 (13:08 -0700)
committerBen Pfaff <blp@nicira.com>
Wed, 23 Jul 2008 20:12:23 +0000 (13:12 -0700)
The upcoming ofp-kill utility wants to use this.

include/daemon.h
lib/daemon.c

index 208cee9..d7273e0 100644 (file)
@@ -34,6 +34,7 @@
 #ifndef DAEMON_H
 #define DAEMON_H 1
 
+char *make_pidfile_name(const char *name);
 void set_pidfile(const char *name);
 void set_detach(void);
 void daemonize(void);
index b153dc0..b597717 100644 (file)
@@ -50,6 +50,16 @@ static bool detach;
 /* Name of pidfile (null if none). */
 static char *pidfile;
 
+/* Returns the file name that would be used for a pidfile if 'name' were
+ * provided to set_pidfile().  The caller must free the returned string. */
+char *
+make_pidfile_name(const char *name) 
+{
+    return (!name ? xasprintf("%s/%s.pid", RUNDIR, program_name)
+            : *name == '/' ? xstrdup(name)
+            : xasprintf("%s/%s", RUNDIR, name));
+}
+
 /* 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
@@ -60,9 +70,7 @@ void
 set_pidfile(const char *name)
 {
     free(pidfile);
-    pidfile = (!name ? xasprintf("%s/%s.pid", RUNDIR, program_name)
-               : *name == '/' ? xstrdup(name)
-               : xasprintf("%s/%s", RUNDIR, name));
+    pidfile = make_pidfile_name(name);
 }
 
 /* Sets up a following call to daemonize() to detach from the foreground