]> code.citadel.org Git - citadel.git/blobdiff - citadel/server_main.c
* Replaced all "Citadel/UX" references with "Citadel"
[citadel.git] / citadel / server_main.c
index 4a7206ec2a1a8c7be7dbcce3af86da121d998317..3e51f93eac09b7a24d09d2c6d067e7d7d0616b5c 100644 (file)
@@ -15,6 +15,7 @@
 #include <sys/stat.h>
 #include <sys/wait.h>
 #include <sys/socket.h>
+#include <syslog.h>
 
 #if TIME_WITH_SYS_TIME
 # include <sys/time.h>
 #include <pwd.h>
 #include <errno.h>
 #include <stdarg.h>
-#include <syslog.h>
 #include <grp.h>
 #ifdef HAVE_PTHREAD_H
 #include <pthread.h>
 #endif
+#ifdef HAVE_SYS_PRCTL_H
+#include <sys/prctl.h>
+#endif
 #include "citadel.h"
 #include "server.h"
 #include "serv_extensions.h"
@@ -90,6 +93,15 @@ int main(int argc, char **argv)
                        chmod(tracefile, 0600);
                }
 
+               else if (!strncmp(argv[a], "-l", 2)) {
+                       safestrncpy(tracefile, argv[a], sizeof tracefile);
+                       strcpy(tracefile, &tracefile[2]);
+                       syslog_facility = SyslogFacility(tracefile);
+                       if (syslog_facility >= 0) {
+                               openlog("citadel", LOG_PID, syslog_facility);
+                       }
+               }
+
                /* run in the background if -d was specified */
                else if (!strcmp(argv[a], "-d")) {
                        start_daemon( (strlen(tracefile) > 0) ? 0 : 1 ) ;
@@ -118,8 +130,10 @@ int main(int argc, char **argv)
 
                /* any other parameter makes it crash and burn */
                else {
-                       lprintf(1,      "citserver: usage: "
-                                       "citserver [-tTraceFile] [-d] [-f]"
+                       lprintf(CTDL_EMERG,     "citserver: usage: "
+                                       "citserver [-tTraceFile] "
+                                       "[-lLogFacility] "
+                                       "[-d] [-f]"
                                        " [-xLogLevel] [-hHomeDir]\n");
                        exit(1);
                }
@@ -127,25 +141,27 @@ int main(int argc, char **argv)
        }
 
        /* Tell 'em who's in da house */
-       lprintf(1,
-               "\n*** Citadel/UX messaging server engine v%d.%02d ***\n"
-               "Copyright (C) 1987-2003 by the Citadel/UX development team.\n"
+       lprintf(CTDL_NOTICE, "\n");
+       lprintf(CTDL_NOTICE, "\n");
+       lprintf(CTDL_NOTICE,
+               "*** Citadel server engine v%d.%02d ***\n",
+               (REV_LEVEL/100), (REV_LEVEL%100));
+       lprintf(CTDL_NOTICE,
+               "Copyright (C) 1987-2004 by the Citadel development team.\n");
+       lprintf(CTDL_NOTICE,
                "This program is distributed under the terms of the GNU "
-               "General Public License.\n\n",
-               (REV_LEVEL/100),
-               (REV_LEVEL%100)
-       );
-
-       /* Initialize... */
-       init_sysdep();
-       openlog("citserver", LOG_PID, LOG_USER);
+               "General Public License.\n");
+       lprintf(CTDL_NOTICE, "\n");
 
        /* Load site-specific parameters, and set the ipgm secret */
-       lprintf(7, "Loading citadel.config\n");
+       lprintf(CTDL_INFO, "Loading citadel.config\n");
        get_config();
        config.c_ipgm_secret = rand();
        put_config();
 
+       /* Initialize... */
+       init_sysdep();
+
        /*
         * Do non system dependent startup functions.
         */
@@ -157,7 +173,8 @@ int main(int argc, char **argv)
        CtdlRegisterServiceHook(0,
                                "citadel.socket",
                                citproto_begin_session,
-                               do_command_loop);
+                               do_command_loop,
+                               do_async_loop);
 
        /*
         * Bind the server to our favorite TCP port (usually 504).
@@ -165,47 +182,38 @@ int main(int argc, char **argv)
        CtdlRegisterServiceHook(config.c_port_number,
                                NULL,
                                citproto_begin_session,
-                               do_command_loop);
+                               do_command_loop,
+                               do_async_loop);
 
        /*
         * Load any server-side extensions available here.
         */
-       lprintf(7, "Initializing server extensions\n");
+       lprintf(CTDL_INFO, "Initializing server extensions\n");
        size = strlen(bbs_home_directory) + 9;
        initialize_server_extensions();
 
-       /*
-        * The rescan pipe exists so that worker threads can be woken up and
-        * told to re-scan the context list for fd's to listen on.  This is
-        * necessary, for example, when a context is about to go idle and needs
-        * to get back on that list.
-        */
-       if (pipe(rescan)) {
-               lprintf(1, "Can't create rescan pipe!\n");
-               exit(errno);
-       }
-
-       init_master_fdset();
-
        /*
         * Now that we've bound the sockets, change to the BBS user id and its
         * corresponding group ids
         */
        if (drop_root_perms) {
                if ((pw = getpwuid(BBSUID)) == NULL)
-                       lprintf(1, "WARNING: getpwuid(%ld): %s\n"
+                       lprintf(CTDL_CRIT, "WARNING: getpwuid(%ld): %s\n"
                                   "Group IDs will be incorrect.\n", (long)BBSUID,
                                strerror(errno));
                else {
                        initgroups(pw->pw_name, pw->pw_gid);
                        if (setgid(pw->pw_gid))
-                               lprintf(3, "setgid(%ld): %s\n", (long)pw->pw_gid,
+                               lprintf(CTDL_CRIT, "setgid(%ld): %s\n", (long)pw->pw_gid,
                                        strerror(errno));
                }
-               lprintf(7, "Changing uid to %ld\n", (long)BBSUID);
+               lprintf(CTDL_INFO, "Changing uid to %ld\n", (long)BBSUID);
                if (setuid(BBSUID) != 0) {
-                       lprintf(3, "setuid() failed: %s\n", strerror(errno));
+                       lprintf(CTDL_CRIT, "setuid() failed: %s\n", strerror(errno));
                }
+#if defined (HAVE_SYS_PRCTL_H) && defined (PR_SET_DUMPABLE)
+               prctl(PR_SET_DUMPABLE, 1);
+#endif
        }
 
        /* We want to check for idle sessions once per minute */
@@ -214,7 +222,7 @@ int main(int argc, char **argv)
        /*
         * Now create a bunch of worker threads.
         */
-       lprintf(9, "Starting %d worker threads\n", config.c_min_workers-1);
+       lprintf(CTDL_DEBUG, "Starting %d worker threads\n", config.c_min_workers-1);
        begin_critical_section(S_WORKER_LIST);
        for (i=0; i<(config.c_min_workers-1); ++i) {
                create_worker();
@@ -226,7 +234,7 @@ int main(int argc, char **argv)
        worker_thread(NULL);
 
        /* Server is exiting. Wait for workers to shutdown. */
-       lprintf(7, "Waiting for worker threads to shut down\n");
+       lprintf(CTDL_INFO, "Waiting for worker threads to shut down\n");
 
        begin_critical_section(S_WORKER_LIST);
        while (worker_list != NULL) {
@@ -236,13 +244,12 @@ int main(int argc, char **argv)
                /* avoid deadlock with an exiting thread */
                end_critical_section(S_WORKER_LIST);
                if ((i = pthread_join(wnp->tid, NULL)))
-                       lprintf(1, "pthread_join: %s\n", strerror(i));
-               phree(wnp);
+                       lprintf(CTDL_CRIT, "pthread_join: %s\n", strerror(i));
+               free(wnp);
                begin_critical_section(S_WORKER_LIST);
        }
        end_critical_section(S_WORKER_LIST);
 
        master_cleanup();
-
        return(0);
 }