Skip to content

Commit

Permalink
Make daemonization happen later, after setup (bnc#739015)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Spiers committed Mar 7, 2012
1 parent 4c4bb54 commit c93995e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/main.c
Expand Up @@ -977,13 +977,21 @@ static int do_server(int type)
int fd;
int rv = -1;

rv = setup(SITE);
if (rv < 0)
goto out;

if (!debug_level) {
if (daemon(0, 0) < 0) {
perror("daemon error");
exit(EXIT_FAILURE);
}
}

/*
The lock cannot be obtained before the call to daemon(), otherwise
the lockfile would contain the pid of the parent, not the daemon.
*/
fd = lockfile();
if (fd < 0)
return fd;
Expand All @@ -996,10 +1004,9 @@ static int do_server(int type)
set_scheduler();
set_oom_adj(-16);

rv = setup(SITE);
if (rv == 0)
rv = loop();
rv = loop();

out:
unlink_lockfile(fd);

return rv;
Expand Down

0 comments on commit c93995e

Please sign in to comment.