From: Ben Pfaff Date: Wed, 23 Jul 2008 20:08:31 +0000 (-0700) Subject: New function make_pidfile_name(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a412f49bb0f5079db6ce0a46aa6ab5b08b2c4394;p=openvswitch New function make_pidfile_name(). The upcoming ofp-kill utility wants to use this. --- diff --git a/include/daemon.h b/include/daemon.h index 208cee9c..d7273e02 100644 --- a/include/daemon.h +++ b/include/daemon.h @@ -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); diff --git a/lib/daemon.c b/lib/daemon.c index b153dc0c..b5977172 100644 --- a/lib/daemon.c +++ b/lib/daemon.c @@ -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