]> 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 9d06152f5baf091a707cff4dfdd610c42da0f4b7..3e51f93eac09b7a24d09d2c6d067e7d7d0616b5c 100644 (file)
@@ -40,6 +40,9 @@
 #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"
@@ -127,7 +130,7 @@ int main(int argc, char **argv)
 
                /* any other parameter makes it crash and burn */
                else {
-                       lprintf(1,      "citserver: usage: "
+                       lprintf(CTDL_EMERG,     "citserver: usage: "
                                        "citserver [-tTraceFile] "
                                        "[-lLogFacility] "
                                        "[-d] [-f]"
@@ -138,18 +141,20 @@ int main(int argc, char **argv)
        }
 
        /* Tell 'em who's in da house */
-       lprintf(1, "\n");
-       lprintf(1, "\n");
-       lprintf(1,"*** Citadel/UX messaging server engine v%d.%02d ***\n",
-               (REV_LEVEL/100),
-               (REV_LEVEL%100) );
-       lprintf(1,"Copyright (C) 1987-2003 by the Citadel/UX development team.\n");
-       lprintf(1,"This program is distributed under the terms of the GNU ");
-       lprintf(1,"General Public License.\n");
-       lprintf(1, "\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");
+       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();
@@ -168,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).
@@ -176,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 */
@@ -225,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();
@@ -237,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) {
@@ -247,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);
 }