updates.
[silc.git] / apps / silcd / silcd.c
index 2c8914cd609eaf521f78eb5b138619a416db6e34..bfb50ca7082e2ee95e5fda05e75fee920a528be5 100644 (file)
@@ -2,7 +2,7 @@
 
   silcd.c
   
-  Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+  Author: Pekka Riikonen <priikone@silcnet.org>
 
   Copyright (C) 1997 - 2001 Pekka Riikonen
 
@@ -37,13 +37,11 @@ silc_server_create_key_pair(char *pkcs_name, int bits, char *path,
                            SilcPublicKey *ret_pub_key,
                            SilcPrivateKey *ret_prv_key);
 
-SILC_MUTEX_DEFINE(testi);
-
 /* Long command line options */
 static struct option long_opts[] = 
 {
   { "config-file", 1, NULL, 'f' },
-  { "debug", 0, NULL, 'd' },
+  { "debug", 1, NULL, 'd' },
   { "help", 0, NULL, 'h' },
   { "version", 0, NULL,'V' },
 
@@ -72,7 +70,7 @@ Usage: silcd [options]\n\
 \n\
   Generic Options:\n\
   -f  --config-file=FILE        Alternate configuration file\n\
-  -d  --debug                   Enable debugging (no daemon)\n\
+  -d  --debug=string            Enable debugging (no daemon)\n\
   -h  --help                    Display this message\n\
   -V  --version                 Display version\n\
 \n\
@@ -104,12 +102,13 @@ int main(int argc, char **argv)
   char *config_file = NULL;
   SilcServer silcd;
   struct sigaction sa;
+  char pid[10];
 
   silc_debug = FALSE;
 
   /* Parse command line arguments */
   if (argc > 1) {
-    while ((opt = getopt_long(argc, argv, "cf:dhVC:",
+    while ((opt = getopt_long(argc, argv, "cf:d:hVC:",
                              long_opts, &option_index)) != EOF) {
       switch(opt) 
        {
@@ -121,11 +120,18 @@ int main(int argc, char **argv)
                 "version %s (base: SILC Toolkit %s)\n",
                  silc_dist_version, silc_version);
          printf("(c) 1997 - 2001 Pekka Riikonen "
-                "<priikone@poseidon.pspt.fi>\n");
+                "<priikone@silcnet.org>\n");
          exit(0);
          break;
        case 'd':
          silc_debug = TRUE;
+         silc_debug_hexdump = TRUE;
+         silc_log_set_debug_string(optarg);
+#ifndef SILC_DEBUG
+         fprintf(stdout, 
+                 "Run-time debugging is not enabled. To enable it recompile\n"
+                 "the server with --enable-debug configuration option.\n");
+#endif
          break;
        case 'f':
          config_file = strdup(optarg);
@@ -199,6 +205,12 @@ int main(int argc, char **argv)
     /* Before running the server, fork to background and set
        both user and group no non-root */    
     silc_server_daemonise(silcd);
+
+  /* Set /var/run/silcd.pid */
+  unlink(SILC_SERVER_PID_FILE);
+  memset(pid, 0, sizeof(pid));
+  snprintf(pid, sizeof(pid) - 1, "%d\n", getpid());
+  silc_file_writefile(SILC_SERVER_PID_FILE, pid, strlen(pid));
   
   /* Run the server. When this returns the server has been stopped
      and we will exit. */