* modules registering serverports now need to specify a plaintext name.
[citadel.git] / citadel / server_main.c
index f27baeb6073ab28d9f3a5a6d7480cae3695677bf..bd3c0032116a1e9727991b6bb50ab2c630c0727b 100644 (file)
 #include "config.h"
 #include "control.h"
 #include "database.h"
+#include "user_ops.h"
 #include "housekeeping.h"
 #include "tools.h"
 #include "citadel_dirs.c"
 
+#include "modules_init.h"
+#include "ecrash.h"
+
 #ifdef HAVE_SYS_SELECT_H
 #include <sys/select.h>
 #endif
@@ -64,8 +68,8 @@
 #ifndef HAVE_SNPRINTF
 #include "snprintf.h"
 #endif
-
-int running_as_daemon = 0;
+const char *CitadelServiceUDS="citadel-UDS";
+const char *CitadelServiceTCP="citadel-TCP";
 
 /*
  * Here's where it all begins.
@@ -85,6 +89,13 @@ int main(int argc, char **argv)
 #ifdef HAVE_RUN_DIR
        struct stat filestats;
 #endif
+       eCrashParameters params;
+//     eCrashSymbolTable symbol_table;
+
+       /* initialise semaphores here. Patch by Matt and davew
+        * its called here as they are needed by lprintf for thread safety
+        */
+       InitialiseSemaphores();
        
        /* initialize the master context */
        InitializeMasterCC();
@@ -147,13 +158,31 @@ int main(int argc, char **argv)
        }
 
        calc_dirs_n_files(relh, home, relhome, ctdldir);
-
        /* daemonize, if we were asked to */
        if (running_as_daemon) {
                start_daemon(0);
                drop_root_perms = 1;
        }
 
+       bzero(&params, sizeof(params));
+       params.filename = file_pid_paniclog;
+       panic_fd=open(file_pid_paniclog, O_APPEND|O_CREAT|O_DIRECT);
+       params.filep = fopen(file_pid_paniclog, "a+");
+       params.debugLevel = ECRASH_DEBUG_VERBOSE;
+       params.dumpAllThreads = TRUE;
+       params.useBacktraceSymbols = 1;
+///    BuildSymbolTable(&symbol_table);
+//     params.symbolTable = &symbol_table;
+       params.signals[0]=SIGSEGV;
+       params.signals[1]=SIGILL;
+       params.signals[2]=SIGBUS;
+       params.signals[3]=SIGABRT;
+
+       eCrash_Init(&params);
+               
+       eCrash_RegisterThread("MasterThread", 0);
+
+///    signal(SIGSEGV, cit_panic_backtrace);
        /* Initialize the syslogger.  Yes, we are really using 0 as the
         * facility, because we are going to bitwise-OR the facility to
         * the severity of each message, allowing us to write to other
@@ -215,10 +244,11 @@ int main(int argc, char **argv)
         * Bind the server to a Unix-domain socket.
         */
        CtdlRegisterServiceHook(0,
-                                                       file_citadel_socket,
-                                                       citproto_begin_session,
-                                                       do_command_loop,
-                                                       do_async_loop);
+                               file_citadel_socket,
+                               citproto_begin_session,
+                               do_command_loop,
+                               do_async_loop,
+                               CitadelServiceUDS);
 
        /*
         * Bind the server to our favorite TCP port (usually 504).
@@ -227,14 +257,22 @@ int main(int argc, char **argv)
                                NULL,
                                citproto_begin_session,
                                do_command_loop,
-                               do_async_loop);
+                               do_async_loop,
+                               CitadelServiceTCP);
 
        /*
         * Load any server-side extensions available here.
         */
        lprintf(CTDL_INFO, "Initializing server extensions\n");
        size = strlen(ctdl_home_directory) + 9;
+       
+/*
        initialize_server_extensions();
+*/
+       
+       initialise_modules();
+       
+       
 
        /*
         * If we need host auth, start our chkpwd daemon.
@@ -288,7 +326,7 @@ int main(int argc, char **argv)
        }
        end_critical_section(S_WORKER_LIST);
 
-       /* Create the indexer thread. */
+       /* Create the maintenance threads. */
        create_maintenance_threads();
 
        /* This thread is now useless.  It can't be turned into a worker