]> jfr.im git - solanum.git/blobdiff - ircd/ircd.c
whowas.c: store account name in whowas (#323)
[solanum.git] / ircd / ircd.c
index de8e80a4fe95084d441e61008a4ea2f315ba1322..21b7605e255a9c076f997053654bd85a129bf87b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  charybdis: A slightly useful ircd.
+ *  Solanum: a slightly advanced ircd
  *  ircd.c: Starts up and runs the ircd.
  *
  *  Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
@@ -197,7 +197,7 @@ ircd_shutdown(const char *reason)
 static void
 init_sys(void)
 {
-#if !defined(_WIN32) && defined(RLIMIT_NOFILE) && defined(HAVE_SYS_RESOURCE_H)
+#if defined(RLIMIT_NOFILE) && defined(HAVE_SYS_RESOURCE_H)
        struct rlimit limit;
 
        if(!getrlimit(RLIMIT_NOFILE, &limit))
@@ -206,7 +206,7 @@ init_sys(void)
                if(maxconnections <= MAX_BUFFER)
                {
                        fprintf(stderr, "ERROR: Shell FD limits are too low.\n");
-                       fprintf(stderr, "ERROR: charybdis reserves %d FDs, shell limits must be above this\n", MAX_BUFFER);
+                       fprintf(stderr, "ERROR: solanum reserves %d FDs, shell limits must be above this\n", MAX_BUFFER);
                        exit(EXIT_FAILURE);
                }
                return;
@@ -215,7 +215,6 @@ init_sys(void)
        maxconnections = MAXCONNECTIONS;
 }
 
-#ifndef _WIN32
 static int
 make_daemon(void)
 {
@@ -225,6 +224,12 @@ make_daemon(void)
           we need control over the parent after forking to print
           the startup message -- Aaron */
 
+       if((nullfd = open("/dev/null", O_RDWR)) < 0)
+       {
+               perror("open /dev/null");
+               exit(EXIT_FAILURE);
+       }
+
        if((pid = fork()) < 0)
        {
                perror("fork");
@@ -238,12 +243,6 @@ make_daemon(void)
                exit(EXIT_SUCCESS);
        }
 
-       if((nullfd = open("/dev/null", O_RDWR)) < 0)
-       {
-               perror("open /dev/null");
-               exit(EXIT_FAILURE);
-       }
-
        for(fdx = 0; fdx <= 2; fdx++)
                if (fdx != nullfd)
                        (void) dup2(nullfd, fdx);
@@ -255,7 +254,6 @@ make_daemon(void)
 
        return 0;
 }
-#endif
 
 static int printVersion = 0;
 
@@ -296,7 +294,7 @@ check_rehash(void *unused)
 
        if(doremotd)
        {
-               sendto_realops_snomask(SNO_GENERAL, L_ALL,
+               sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
                                     "Got signal SIGUSR1, reloading ircd motd file");
                cache_user_motd();
                doremotd = false;
@@ -353,104 +351,6 @@ initialize_global_set_options(void)
 
 }
 
-/*
- * initialize_server_capabs
- *
- * inputs       - none
- * output       - none
- */
-static void
-initialize_server_capabs(void)
-{
-       default_server_capabs &= ~CAP_ZIP;
-}
-
-#ifdef _WIN32
-/*
- * relocate_paths
- *
- * inputs       - none
- * output       - none
- * side effects - items in ircd_paths[] array are relocated
- */
-static void
-relocate_paths(void)
-{
-       char prefix[PATH_MAX], workbuf[PATH_MAX];
-       char *p;
-
-       rb_strlcpy(prefix, rb_path_to_self(), sizeof prefix);
-
-       ircd_paths[IRCD_PATH_IRCD_EXEC] = rb_strdup(prefix);
-
-       /* if we're running from inside the source tree, we probably do not want to relocate any other paths */
-       if (strstr(prefix, ".libs") != NULL)
-               return;
-
-       /* prefix = /home/kaniini/ircd/bin/ircd */
-       p = strrchr(prefix, RB_PATH_SEPARATOR);
-       if (rb_unlikely(p == NULL))
-               return;
-       *p = 0;
-
-       /* prefix = /home/kaniini/ircd/bin */
-       p = strrchr(prefix, RB_PATH_SEPARATOR);
-       if (rb_unlikely(p == NULL))
-               return;
-       *p = 0;
-
-       /* prefix = /home/kaniini/ircd */
-       ircd_paths[IRCD_PATH_PREFIX] = rb_strdup(prefix);
-
-       /* now that we have our prefix, we can relocate the other paths... */
-       snprintf(workbuf, sizeof workbuf, "%s%cmodules", prefix, RB_PATH_SEPARATOR);
-       ircd_paths[IRCD_PATH_MODULES] = rb_strdup(workbuf);
-
-       snprintf(workbuf, sizeof workbuf, "%s%cmodules%cautoload", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR);
-       ircd_paths[IRCD_PATH_AUTOLOAD_MODULES] = rb_strdup(workbuf);
-
-       snprintf(workbuf, sizeof workbuf, "%s%cetc", prefix, RB_PATH_SEPARATOR);
-       ircd_paths[IRCD_PATH_ETC] = rb_strdup(workbuf);
-
-       snprintf(workbuf, sizeof workbuf, "%s%clog", prefix, RB_PATH_SEPARATOR);
-       ircd_paths[IRCD_PATH_LOG] = rb_strdup(workbuf);
-
-       snprintf(workbuf, sizeof workbuf, "%s%chelp%cusers", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR);
-       ircd_paths[IRCD_PATH_USERHELP] = rb_strdup(workbuf);
-
-       snprintf(workbuf, sizeof workbuf, "%s%chelp%copers", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR);
-       ircd_paths[IRCD_PATH_OPERHELP] = rb_strdup(workbuf);
-
-       snprintf(workbuf, sizeof workbuf, "%s%cetc%circd.conf", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR);
-       ircd_paths[IRCD_PATH_IRCD_CONF] = rb_strdup(workbuf);
-
-       snprintf(workbuf, sizeof workbuf, "%s%cetc%circd.motd", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR);
-       ircd_paths[IRCD_PATH_IRCD_MOTD] = rb_strdup(workbuf);
-
-       snprintf(workbuf, sizeof workbuf, "%s%cetc%copers.motd", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR);
-       ircd_paths[IRCD_PATH_IRCD_OMOTD] = rb_strdup(workbuf);
-
-       snprintf(workbuf, sizeof workbuf, "%s%cetc%cban.db", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR);
-       ircd_paths[IRCD_PATH_BANDB] = rb_strdup(workbuf);
-
-       snprintf(workbuf, sizeof workbuf, "%s%cetc%circd.pid", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR);
-       ircd_paths[IRCD_PATH_IRCD_PID] = rb_strdup(workbuf);
-
-       snprintf(workbuf, sizeof workbuf, "%s%clogs%circd.log", prefix, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR);
-       ircd_paths[IRCD_PATH_IRCD_LOG] = rb_strdup(workbuf);
-
-       snprintf(workbuf, sizeof workbuf, "%s%cbin", prefix, RB_PATH_SEPARATOR);
-       ircd_paths[IRCD_PATH_BIN] = rb_strdup(workbuf);
-       ircd_paths[IRCD_PATH_LIBEXEC] = rb_strdup(workbuf);
-
-       inotice("runtime paths:");
-       for (int i = 0; i < IRCD_PATH_COUNT; i++)
-       {
-               inotice("  %s: %s", ircd_pathnames[i], ircd_paths[i]);
-       }
-}
-#endif
-
 /*
  * write_pidfile
  *
@@ -553,7 +453,7 @@ ircd_restart_cb(const char *str)
 /*
  * Why EXIT_FAILURE here?
  * Because if ircd_die_cb() is called it's because of a fatal
- * error inside libcharybdis, and we don't know how to handle the
+ * error inside libsolanum, and we don't know how to handle the
  * exception, so it is logical to return a FAILURE exit code here.
  *    --nenolod
  */
@@ -627,22 +527,16 @@ seed_random(void *unused)
  * Side Effects - this is where the ircd gets going right now
  */
 int
-charybdis_main(int argc, char * const argv[])
+solanum_main(int argc, char * const argv[])
 {
        int fd;
 
-#ifndef _WIN32
        /* Check to see if the user is running us as root, which is a nono */
        if(geteuid() == 0)
        {
                fprintf(stderr, "Don't run ircd as root!!!\n");
                return -1;
        }
-#endif
-
-#ifdef _WIN32
-       relocate_paths();
-#endif
 
        logFileName = ircd_paths[IRCD_PATH_IRCD_LOG];
        pidFileName = ircd_paths[IRCD_PATH_IRCD_PID];
@@ -679,6 +573,7 @@ charybdis_main(int argc, char * const argv[])
        me.localClient = &meLocalUser;
 
        /* Make sure all lists are zeroed */
+       memset(&global_client_list, 0, sizeof(global_client_list));
        memset(&unknown_list, 0, sizeof(unknown_list));
        memset(&lclient_list, 0, sizeof(lclient_list));
        memset(&serv_list, 0, sizeof(serv_list));
@@ -708,7 +603,6 @@ charybdis_main(int argc, char * const argv[])
        if (testing_conf)
                server_state_foreground = true;
 
-#ifndef _WIN32
        /* Make sure fd 0, 1 and 2 are in use -- jilles */
        do
        {
@@ -718,14 +612,17 @@ charybdis_main(int argc, char * const argv[])
                close(fd);
        else if (fd == -1)
                exit(1);
-#endif
 
        /* Check if there is pidfile and daemon already running */
        if(!testing_conf)
        {
                check_pidfile(pidFileName);
+
                inotice("starting %s ...", ircd_version);
                inotice("%s", rb_lib_version());
+
+               if(!server_state_foreground)
+                       make_daemon();
        }
 
        /* Init the event subsystem */
@@ -779,7 +676,6 @@ charybdis_main(int argc, char * const argv[])
 
        rehash_bans();
 
-       initialize_server_capabs();     /* Set up default_server_capabs */
        initialize_global_set_options();
 
        if(ServerInfo.name == NULL)
@@ -817,13 +713,6 @@ charybdis_main(int argc, char * const argv[])
                        ircd_ssl_ok = true;
        }
 
-       if (testing_conf)
-       {
-               fprintf(stderr, "\nConfig testing complete.\n");
-               fflush(stderr);
-               return 0;       /* Why? We want the launcher to exit out. */
-       }
-
        me.from = &me;
        me.servptr = &me;
        SetMe(&me);
@@ -837,7 +726,15 @@ charybdis_main(int argc, char * const argv[])
 
        construct_umodebuf();
 
+       if (testing_conf)
+       {
+               fprintf(stderr, "\nConfig testing complete.\n");
+               fflush(stderr);
+               return 0;       /* Why? We want the launcher to exit out. */
+       }
+
        check_class();
+       write_pidfile(pidFileName);
        load_help();
        open_logfiles();
 
@@ -861,12 +758,6 @@ charybdis_main(int argc, char * const argv[])
        if(server_state_foreground)
                inotice("now running in foreground mode from %s as pid %d ...",
                        ConfigFileEntry.dpath, getpid());
-#ifndef _WIN32
-       else
-               make_daemon();
-#endif
-
-       write_pidfile(pidFileName);
 
        rb_lib_loop(0);