Fixed a bug in the pid writing function, which couldn't be
[silc.git] / apps / silcd / silcd.c
index 095a5c3f819fc0e749f40995aa0712ed53f0dddd..af9d6172b14144ce8e401f53f8a3743089cebe41 100644 (file)
@@ -131,7 +131,7 @@ static void silc_server_checkpid(SilcServer silcd)
 
 /* Drop root privileges. If some system call fails, die. */
 
-static void silc_server_drop(SilcServer server)
+static void silc_server_drop_privs(SilcServer server)
 {
   /* Are we executing silcd as root or a regular user? */
   if (geteuid()) {
@@ -403,9 +403,6 @@ int main(int argc, char **argv)
   silc_schedule_signal_register(silcd->schedule, SIGINT, stop_server, NULL);
 
   if (!foreground) {
-    /* Drop root. */
-    silc_server_drop(silcd);
-
     /* Before running the server, fork to background. */
     silc_server_daemonise(silcd);
 
@@ -418,6 +415,11 @@ int main(int argc, char **argv)
     }
   }
 
+  /* Drop root if we are not in debug mode, so you don't need to bother about
+     file writing permissions and so on */
+  if (!silc_debug)
+    silc_server_drop_privs(silcd);
+
   /* Run the server. When this returns the server has been stopped
      and we will exit. */
   silc_server_run(silcd);