daemon: added comments to daemonize_detach()
This commit is contained in:
parent
42415592b4
commit
59e62d95bd
@ -131,18 +131,27 @@ daemonize_detach(void)
|
|||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
|
/* flush all file handles before duplicating the buffers */
|
||||||
|
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
|
|
||||||
|
/* detach from parent process */
|
||||||
|
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid < 0)
|
if (pid < 0)
|
||||||
g_error("fork() failed: %s", g_strerror(errno));
|
g_error("fork() failed: %s", g_strerror(errno));
|
||||||
|
|
||||||
if (pid > 0)
|
if (pid > 0)
|
||||||
|
/* exit the parent process */
|
||||||
_exit(EXIT_SUCCESS);
|
_exit(EXIT_SUCCESS);
|
||||||
|
|
||||||
|
/* release the current working directory */
|
||||||
|
|
||||||
if (chdir("/") < 0)
|
if (chdir("/") < 0)
|
||||||
g_error("problems changing to root directory");
|
g_error("problems changing to root directory");
|
||||||
|
|
||||||
|
/* detach from the current session */
|
||||||
|
|
||||||
setsid();
|
setsid();
|
||||||
|
|
||||||
g_debug("daemonized!");
|
g_debug("daemonized!");
|
||||||
|
Loading…
Reference in New Issue
Block a user