X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fdaemon.c;h=4c7c8e16ae3f2f9b6760185e86dfa00258c5be56;hb=1335a8d578b03e;hp=546612c6eb032f6fac3158abb4c990f00d49bbe6;hpb=d6bc33f37a218832456fed11fa1796e6b7e93102;p=sliver-openvswitch.git diff --git a/lib/daemon.c b/lib/daemon.c index 546612c6e..4c7c8e16a 100644 --- a/lib/daemon.c +++ b/lib/daemon.c @@ -15,6 +15,7 @@ */ #include #include "daemon.h" +#include "daemon-private.h" #include #include #include @@ -26,6 +27,36 @@ VLOG_DEFINE_THIS_MODULE(daemon); * /dev/null (if false) or keep it for the daemon to use (if true). */ static bool save_fds[3]; +/* Will daemonize() really detach? */ +bool +get_detach(void) +{ + return detach; +} + +/* If configured with set_pidfile() or set_detach(), creates the pid file and + * detaches from the foreground session. */ +void +daemonize(void) +{ + daemonize_start(); + daemonize_complete(); +} + +/* Sets up a following call to daemonize() to create a pidfile named 'name'. + * If 'name' begins with '/' (or contains ':' in windows), then it is treated + * as an absolute path. Otherwise, it is taken relative to RUNDIR, + * which is $(prefix)/var/run by default. + * + * If 'name' is null, then program_name followed by ".pid" is used. */ +void +set_pidfile(const char *name) +{ + assert_single_threaded(); + free(pidfile); + pidfile = make_pidfile_name(name); +} + /* A daemon doesn't normally have any use for the file descriptors for stdin, * stdout, and stderr after it detaches. To keep these file descriptors from * e.g. holding an SSH session open, by default detaching replaces each of