summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/sys/daemon.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/common/sys/daemon.c b/common/sys/daemon.c
index 4d925c1c..4d490cb4 100644
--- a/common/sys/daemon.c
+++ b/common/sys/daemon.c
@@ -41,11 +41,6 @@ daemonize(const char * pidfile, const char * logfile)
if (pid > 0)
exit(0);
- if (chdir("/") < 0) {
- perror("Can't chdir to root");
- exit(-1);
- }
-
if (pidfile) {
if ((fd = creat(pidfile, 0644)) >= 0) {
snprintf(buf, sizeof(buf), "%d", (int)getpid());
@@ -66,6 +61,11 @@ daemonize(const char * pidfile, const char * logfile)
}
}
+ if (chdir("/") < 0) {
+ perror("Can't chdir to root");
+ exit(-1);
+ }
+
#if 0
fd = getdtablesize();
while (fd > 2)