X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fdaemon.c;h=50cc3352142755887baf5bfadc450303e4b4fc46;hb=8419883d698965962e37b024cfb7f2f0ccba376f;hp=a35c6393452887514f3180792d00f01553d7a8ba;hpb=3f355f47f8e7343e909ccfa854454d667baf3c38;p=openvswitch diff --git a/lib/daemon.c b/lib/daemon.c index a35c6393..50cc3352 100644 --- a/lib/daemon.c +++ b/lib/daemon.c @@ -23,6 +23,7 @@ #include #include "fatal-signal.h" #include "dirs.h" +#include "lockfile.h" #include "timeval.h" #include "util.h" @@ -80,6 +81,13 @@ set_no_chdir(void) chdir_ = false; } +/* Will we chdir to "/" as part of daemonizing? */ +bool +is_chdir_enabled(void) +{ + return chdir_; +} + /* Normally, die_if_already_running() will terminate the program with a message * if a locked pidfile already exists. If this function is called, * die_if_already_running() will merely log a warning. */ @@ -97,6 +105,13 @@ set_detach(void) detach = true; } +/* Will daemonize() really detach? */ +bool +get_detach(void) +{ + return detach; +} + /* If a pidfile has been configured and that pidfile already exists and is * locked by a running process, returns the pid of the running process. * Otherwise, returns 0. */ @@ -217,13 +232,14 @@ daemonize(void) /* Child process. */ close(fds[0]); make_pidfile(); - write(fds[1], &c, 1); + ignore(write(fds[1], &c, 1)); close(fds[1]); setsid(); if (chdir_) { - chdir("/"); + ignore(chdir("/")); } time_postfork(); + lockfile_postfork(); break; case -1: