]> code.citadel.org Git - citadel.git/blobdiff - citadel/server_main.c
MSGS command can now do full text search on the room
[citadel.git] / citadel / server_main.c
index fdf8e15893fcfaa7f667fd5537cba72dfe701f3f..134e564348432a257d4b90bc0427b5be8aed51e5 100644 (file)
@@ -37,6 +37,7 @@
 #include <errno.h>
 #include <stdarg.h>
 #include <grp.h>
+#include <pwd.h>
 #ifdef HAVE_PTHREAD_H
 #include <pthread.h>
 #endif
@@ -53,6 +54,7 @@
 #include "database.h"
 #include "housekeeping.h"
 #include "tools.h"
+#include "citadel_dirs.c"
 
 #ifdef HAVE_SYS_SELECT_H
 #include <sys/select.h>
@@ -74,18 +76,22 @@ int main(int argc, char **argv)
        struct passwd *pw;
        int drop_root_perms = 1;
        size_t size;
-
+       int relh=0;
+       int home=0;
+       char relhome[PATH_MAX]="";
+       char ctdldir[PATH_MAX]=CTDLDIR;
+#ifdef HAVE_RUN_DIR
+       struct stat filestats;
+#endif
+       
        /* initialize the master context */
        InitializeMasterCC();
 
-       /* set default syslog facility */
-       syslog_facility = LOG_DAEMON;
-
        /* parse command-line arguments */
        for (a=1; a<argc; ++a) {
 
                if (!strncmp(argv[a], "-l", 2)) {
-                       safestrncpy(facility, argv[a], sizeof(facility));
+                       safestrncpy(facility, &argv[a][2], sizeof(facility));
                        syslog_facility = SyslogFacility(facility);
                        enable_syslog = 1;
                }
@@ -101,9 +107,14 @@ int main(int argc, char **argv)
                }
 
                else if (!strncmp(argv[a], "-h", 2)) {
-                       safestrncpy(ctdl_home_directory, &argv[a][2],
-                                   sizeof ctdl_home_directory);
+                       relh=argv[a][2]!='/';
+                       if (!relh) safestrncpy(ctdl_home_directory, &argv[a][2],
+                                                                  sizeof ctdl_home_directory);
+                       else
+                               safestrncpy(relhome, &argv[a][2],
+                                                       sizeof relhome);
                        home_specified = 1;
+                       home=1;
                }
 
                else if (!strncmp(argv[a], "-t", 2)) {
@@ -133,20 +144,25 @@ 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;
        }
 
-       /* initialize the syslog facility */
+       /* 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
+        * facilities when we need to...
+        */
        if (enable_syslog) {
                if (running_as_daemon) {
-                       openlog("citadel", LOG_NDELAY, syslog_facility);
+                       openlog("citadel", LOG_NDELAY, 0);
                }
                else {
-                       openlog("citadel", LOG_PERROR|LOG_NDELAY,
-                               syslog_facility);
+                       openlog("citadel", LOG_PERROR|LOG_NDELAY, 0);
                }
                setlogmask(LOG_UPTO(verbosity));
        }
@@ -171,6 +187,19 @@ int main(int argc, char **argv)
        config.c_ipgm_secret = rand();
        put_config();
 
+#ifdef HAVE_RUN_DIR
+       /* on some dists rundir gets purged on startup. so we need to recreate it. */
+
+       if (stat(ctdl_run_dir, &filestats)==-1){
+               pw=getpwuid(config.c_ctdluid);
+               mkdir(ctdl_run_dir, 0755);
+               chown(ctdl_run_dir, config.c_ctdluid, (pw==NULL)?-1:pw->pw_gid);
+
+       }
+                       
+
+#endif
+
        /* Initialize... */
        init_sysdep();
 
@@ -183,10 +212,10 @@ int main(int argc, char **argv)
         * Bind the server to a Unix-domain socket.
         */
        CtdlRegisterServiceHook(0,
-                               "citadel.socket",
-                               citproto_begin_session,
-                               do_command_loop,
-                               do_async_loop);
+                                                       file_citadel_socket,
+                                                       citproto_begin_session,
+                                                       do_command_loop,
+                                                       do_async_loop);
 
        /*
         * Bind the server to our favorite TCP port (usually 504).
@@ -234,7 +263,8 @@ int main(int argc, char **argv)
        /*
         * Now create a bunch of worker threads.
         */
-       lprintf(CTDL_DEBUG, "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();
@@ -242,13 +272,14 @@ int main(int argc, char **argv)
        end_critical_section(S_WORKER_LIST);
 
        /* Create the indexer thread. */
-       create_indexer_thread();
+       create_maintenance_threads();
 
-       /* Now this thread can become a worker as well. */
-       worker_thread(NULL);
-
-       /* Server is exiting. Wait for workers to shutdown. */
-       lprintf(CTDL_INFO, "Server is shutting down.\n");
+       /* This thread is now useless.  It can't be turned into a worker
+        * thread because its stack is too small, but it can't be killed
+        * either because the whole server process would exit.  So we just
+        * join to the first worker thread and exit when it exits.
+        */
+       pthread_join(worker_list->tid, NULL);
        master_cleanup(0);
        return(0);
 }