aboutsummaryrefslogtreecommitdiffstats
path: root/src/daemon.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-02-15 16:28:39 +0100
committerMax Kellermann <max@duempel.org>2009-02-15 16:28:39 +0100
commit59e62d95bd7746cfebb9458ec17d216d9b86633e (patch)
treef47a04e2dcf680ea5a3b65cbdcd3799cdf503649 /src/daemon.c
parent42415592b4368d1dc6fb2c8446da32318fd06d44 (diff)
downloadmpd-59e62d95bd7746cfebb9458ec17d216d9b86633e.tar.gz
mpd-59e62d95bd7746cfebb9458ec17d216d9b86633e.tar.xz
mpd-59e62d95bd7746cfebb9458ec17d216d9b86633e.zip
daemon: added comments to daemonize_detach()
Diffstat (limited to '')
-rw-r--r--src/daemon.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/daemon.c b/src/daemon.c
index 3cf81911e..51503bc7a 100644
--- a/src/daemon.c
+++ b/src/daemon.c
@@ -131,18 +131,27 @@ daemonize_detach(void)
{
pid_t pid;
+ /* flush all file handles before duplicating the buffers */
+
fflush(NULL);
+ /* detach from parent process */
+
pid = fork();
if (pid < 0)
g_error("fork() failed: %s", g_strerror(errno));
if (pid > 0)
+ /* exit the parent process */
_exit(EXIT_SUCCESS);
+ /* release the current working directory */
+
if (chdir("/") < 0)
g_error("problems changing to root directory");
+ /* detach from the current session */
+
setsid();
g_debug("daemonized!");