From 59e62d95bd7746cfebb9458ec17d216d9b86633e Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@duempel.org>
Date: Sun, 15 Feb 2009 16:28:39 +0100
Subject: [PATCH] daemon: added comments to daemonize_detach()

---
 src/daemon.c | 9 +++++++++
 1 file changed, 9 insertions(+)

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!");