diff options
author | Max Kellermann <max@duempel.org> | 2009-02-15 16:27:09 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-02-15 16:27:09 +0100 |
commit | fd8c63b619552f379353e9d6c430cda1164aafc4 (patch) | |
tree | 144ec770ee21078398f9857c9217b96da53e3d6f | |
parent | fd69782a996b02732d92dc846b6d55cc0ad2c031 (diff) | |
download | mpd-fd8c63b619552f379353e9d6c430cda1164aafc4.tar.gz mpd-fd8c63b619552f379353e9d6c430cda1164aafc4.tar.xz mpd-fd8c63b619552f379353e9d6c430cda1164aafc4.zip |
daemon: moved code to daemonize_detach()
Moved the code which detaches from the parent process/session to a
separate function.
Diffstat (limited to '')
-rw-r--r-- | src/daemon.c | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/src/daemon.c b/src/daemon.c index 02b5a4ba9..bb2b8ded1 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -126,6 +126,27 @@ daemonize_set_user(void) #endif } +static void +daemonize_detach(void) +{ + pid_t pid; + + fflush(NULL); + + pid = fork(); + if (pid > 0) + _exit(EXIT_SUCCESS); + else if (pid < 0) + g_error("problems fork'ing for daemon!"); + + if (chdir("/") < 0) + g_error("problems changing to root directory"); + + setsid(); + + g_debug("daemonized!"); +} + void daemonize(bool detach) { @@ -143,25 +164,8 @@ daemonize(bool detach) } } - if (detach) { - int pid; - - fflush(NULL); - pid = fork(); - if (pid > 0) - _exit(EXIT_SUCCESS); - else if (pid < 0) { - g_error("problems fork'ing for daemon!"); - } - - if (chdir("/") < 0) { - g_error("problems changing to root directory"); - } - - setsid(); - - g_debug("daemonized!"); - } + if (detach) + daemonize_detach(); if (pidfile != NULL) { g_debug("writing pid file"); |