Permalink
Browse files

Make daemonization happen later, after setup (bnc#739015)

  • Loading branch information...
aspiers committed Mar 6, 2012
1 parent 4c4bb54 commit c93995ed3e6d8ddf1d11ac7d9f8ed4c1a3f3ad73
Showing with 10 additions and 3 deletions.
  1. +10 −3 src/main.c
View
@@ -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;
@@ -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;

0 comments on commit c93995e

Please sign in to comment.