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 fd;
int rv = -1; int rv = -1;


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

if (!debug_level) { if (!debug_level) {
if (daemon(0, 0) < 0) { if (daemon(0, 0) < 0) {
perror("daemon error"); perror("daemon error");
exit(EXIT_FAILURE); 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(); fd = lockfile();
if (fd < 0) if (fd < 0)
return fd; return fd;
Expand All @@ -996,10 +1004,9 @@ static int do_server(int type)
set_scheduler(); set_scheduler();
set_oom_adj(-16); set_oom_adj(-16);


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


out:
unlink_lockfile(fd); unlink_lockfile(fd);


return rv; return rv;
Expand Down

0 comments on commit c93995e

Please sign in to comment.