]> jfr.im git - irc/evilnet/x3.git/blobdiff - src/main.c
Minor typo in previous commit where returning 0 when it should have been 1 from opser...
[irc/evilnet/x3.git] / src / main.c
index 9894ed27a66a5d56d1597a977e623c13e36a3ecd..e411bc6ade96f5171ba7c6794b7a18ba99c7557b 100644 (file)
@@ -1,9 +1,9 @@
 /* main.c - X3
- * Copyright 2000-2004 srvx Development Team
+ * Copyright 2000-2006 srvx Development Team
  *
- * This file is part of x3.
+ * This file is part of X3.
  *
- * x3 is free software; you can redistribute it and/or modify
+ * srvx is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
 #include "modcmd.h"
 #include "saxdb.h"
 #include "mail.h"
-#include "spamserv.h"
-#include "shun.h"
 #include "timeq.h"
 #include "sar.h"
+#include "shun.h"
 
 #include "chanserv.h"
 #include "global.h"
 #include "modules.h"
 #include "opserv.h"
+#include "spamserv.h"
 
 #ifdef HAVE_GETOPT_H
 #include <getopt.h>
 #include <sys/wait.h>
 #endif
 
-#ifndef SIGCHLD
-#define SIGCHLD SIGCLD
-#endif
-
 #include "main-common.c"
 
 void sigaction_writedb(int x)
@@ -107,7 +103,8 @@ gc_warn_proc(char *msg, GC_word arg)
 
 int main(int argc, char *argv[])
 {
-    int daemon, debug;
+    int run_as_daemon;
+    int debug;
     pid_t pid = 0;
     FILE *file_out;
     struct sigaction sv;
@@ -118,7 +115,7 @@ int main(int argc, char *argv[])
     GC_enable_incremental();
 #endif
 
-    daemon = 1;
+    run_as_daemon = 1;
     debug = 0;
     tools_init();
 
@@ -137,31 +134,31 @@ int main(int argc, char *argv[])
     sigaction(SIGCHLD, &sv, NULL);
 
     if (argc > 1) { /* parse command line, if any */
-       int c;
-       struct option options[] =
-       {
-           {"config", 1, 0, 'c'},
+        int c;
+        struct option options[] =
+        {
+            {"config", 1, 0, 'c'},
             {"debug", 0, 0, 'd'},
-           {"foreground", 0, 0, 'f'},
-           {"help", 0, 0, 'h'},
-           {"check", 0, 0, 'k'},
+            {"foreground", 0, 0, 'f'},
+            {"help", 0, 0, 'h'},
+            {"check", 0, 0, 'k'},
             {"replay", 1, 0, 'r'},
-           {"version", 0, 0, 'v'},
-           {0, 0, 0, 0}
-       };
+            {"version", 0, 0, 'v'},
+            {0, 0, 0, 0}
+        };
 
         while ((c = getopt_long(argc, argv, "c:dfhkr:v", options, NULL)) != -1) {
             switch (c) {
-           case 'c':
-               services_config = optarg;
-               break;
-           case 'k':
-               if (conf_read(services_config)) {
-                   printf("%s appears to be a valid configuration file.\n", services_config);
-               } else {
-                   printf("%s is an invalid configuration file.\n", services_config);
-               }
-               exit(0);
+            case 'c':
+                services_config = optarg;
+                break;
+            case 'k':
+                if (conf_read(services_config)) {
+                    printf("%s appears to be a valid configuration file.\n", services_config);
+                } else {
+                    printf("%s is an invalid configuration file.\n", services_config);
+                }
+                exit(0);
             case 'r':
                 replay_file = fopen(optarg, "r");
                 if (!replay_file) {
@@ -173,19 +170,19 @@ int main(int argc, char *argv[])
             case 'd':
                 debug = 1;
                 break;
-           case 'f':
-               daemon = 0;
-               break;
-           case 'v':
-               version();
-               license();
-               exit(0);
-           case 'h':
-           default:
-               usage(argv[0]);
-               exit(0);
-           }
-       }
+            case 'f':
+                run_as_daemon = 0;
+                break;
+            case 'v':
+                version();
+                license();
+                exit(0);
+            case 'h':
+            default:
+                usage(argv[0]);
+                exit(0);
+            }
+        }
     }
 
     version();
@@ -195,10 +192,10 @@ int main(int argc, char *argv[])
          * mostly to get the right value of "now" for when we do the
          * irc_introduce. */
         replay_read_line();
-        boot_time = now;
     } else {
-        boot_time = time(&now);
+        now = time(NULL);
     }
+    boot_time = now;
 
     fprintf(stdout, "Initializing daemon...\n");
     if (!conf_read(services_config)) {
@@ -208,29 +205,28 @@ int main(int argc, char *argv[])
 
     conf_register_reload(uplink_compile);
 
-    if (daemon) {
-       /* Attempt to fork into the background if daemon mode is on. */
-       pid = fork();
-       if (pid < 0) {
+    if (run_as_daemon) {
+        /* Attempt to fork into the background if daemon mode is on. */
+        pid = fork();
+        if (pid < 0) {
             fprintf(stderr, "Unable to fork: %s\n", strerror(errno));
         } else if (pid > 0) {
             fprintf(stdout, "Forking into the background (pid: %d)...\n", pid);
-           exit(0);
-       }
-       setsid();
+            exit(0);
+        }
+        setsid();
     }
 
-
     file_out = fopen(PID_FILE, "w");
     if (file_out == NULL) {
-       /* Create the main process' pid file */
+        /* Create the main process' pid file */
         fprintf(stderr, "Unable to create PID file: %s", strerror(errno));
     } else {
-       fprintf(file_out, "%i\n", (int)getpid());
-       fclose(file_out);
+        fprintf(file_out, "%i\n", (int)getpid());
+        fclose(file_out);
     }
 
-    if (daemon) {
+    if (run_as_daemon) {
         /* Close these since we should not use them from now on. */
         fclose(stdin);
         fclose(stdout);
@@ -241,7 +237,7 @@ int main(int argc, char *argv[])
     services_argv = argv;
 
     atexit(call_exit_funcs);
-    reg_exit_func(main_shutdown);
+    reg_exit_func(main_shutdown, NULL);
 
     log_init();
     MAIN_LOG = log_register_type("x3", "file:main.log");
@@ -267,7 +263,7 @@ int main(int argc, char *argv[])
     modules_finalize();
 
     /* The first exit func to be called *should* be saxdb_write_all(). */
-    reg_exit_func(saxdb_write_all);
+    reg_exit_func(saxdb_write_all, NULL);
     if (replay_file) {
         char *msg;
         log_module(MAIN_LOG, LOG_INFO, "Beginning replay...");
@@ -286,7 +282,8 @@ int main(int argc, char *argv[])
             free(msg);
         }
     } else {
-        srand(time(&now));
+        now = time(NULL);
+        srand(now);
         ioset_run();
     }
     return 0;