updates.
[silc.git] / apps / silcd / silcd.c
index 82d29d7a44767154f713a9aa028d594e7a2bee91..53b7f81eb12a57efd4bed910f83f5699874dc60f 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()) {
@@ -282,7 +282,7 @@ int main(int argc, char **argv)
 
   /* Parse command line arguments */
   if (argc > 1) {
-    while ((opt = getopt_long(argc, argv, "f:p:d::xhFVC:",
+    while ((opt = getopt_long(argc, argv, "f:p:d:xhFVC:",
                              long_opts, &option_index)) != EOF) {
       switch(opt) {
        case 'h':
@@ -402,10 +402,12 @@ int main(int argc, char **argv)
   silc_schedule_signal_register(silcd->schedule, SIGTERM, stop_server, NULL);
   silc_schedule_signal_register(silcd->schedule, SIGINT, stop_server, NULL);
 
-  if (!foreground) {
-    /* Drop root. */
-    silc_server_drop(silcd);
+  /* 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);
 
+  if (!foreground) {
     /* Before running the server, fork to background. */
     silc_server_daemonise(silcd);
 
@@ -424,8 +426,8 @@ int main(int argc, char **argv)
 
   /* Stop the server and free it. */
   silc_server_stop(silcd);
-  silc_server_free(silcd);
   silc_server_config_destroy(silcd->config);
+  silc_server_free(silcd);
 
   /* Flush the logging system */
   silc_log_flush_all();