]> code.citadel.org Git - citadel.git/blobdiff - citadel/server_main.c
calculate the directories in a central manner.
[citadel.git] / citadel / server_main.c
index fdf8e15893fcfaa7f667fd5537cba72dfe701f3f..34f49d022b2c047241b1cf1a1905406182edb36b 100644 (file)
@@ -74,18 +74,21 @@ int main(int argc, char **argv)
        struct passwd *pw;
        int drop_root_perms = 1;
        size_t size;
-
+       int relh=0;
+       int home=0;
+       const char* basedir;
+       char dirbuffer[PATH_MAX]="";
+       char relhome[PATH_MAX]="";
+       char ctdldir[PATH_MAX]=CTDLDIR;
+       
        /* 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 +104,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 +141,74 @@ int main(int argc, char **argv)
 
        }
 
+       /* calculate all our path on a central place */
+    /* where to keep our config */
+       
+#define COMPUTE_DIRECTORY(SUBDIR) memcpy(dirbuffer,SUBDIR, sizeof dirbuffer);\
+       snprintf(SUBDIR,sizeof SUBDIR,  "%s%s%s%s%s%s%s", \
+                        (home&!relh)?ctdl_home_directory:basedir, \
+             ((basedir!=ctdldir)&(home&!relh))?basedir:"/", \
+             ((basedir!=ctdldir)&(home&!relh))?"/":"", \
+                        relhome, \
+             (relhome[0]!='\0')?"/":"",\
+                        dirbuffer,\
+                        (dirbuffer[0]!='\0')?"/":"");
+
+#ifndef HAVE_ETC_DIR
+       basedir=ctdldir;
+#else
+       basedir=ETC_DIR;
+#endif
+       COMPUTE_DIRECTORY(ctdl_etc_dir);
+
+#ifndef HAVE_RUN_DIR
+       basedir=ctdldir;
+#else
+       basedir=RUN_DIR;
+#endif
+       COMPUTE_DIRECTORY(ctdl_run_dir);
+
+#ifndef HAVE_DATA_DIR
+       basedir=ctdldir;
+#else
+       basedir=DATA_DIR;
+#endif
+       COMPUTE_DIRECTORY(ctdl_bio_dir);
+       COMPUTE_DIRECTORY(ctdl_bb_dir);
+       COMPUTE_DIRECTORY(ctdl_data_dir);
+       COMPUTE_DIRECTORY(ctdl_file_dir);
+       COMPUTE_DIRECTORY(ctdl_hlp_dir);
+       COMPUTE_DIRECTORY(ctdl_image_dir);
+       COMPUTE_DIRECTORY(ctdl_info_dir);
+       COMPUTE_DIRECTORY(ctdl_message_dir);
+       COMPUTE_DIRECTORY(ctdl_usrpic_dir);
+#ifndef HAVE_SPOOL_DIR
+       basedir=ctdldir;
+#else
+       basedir=SPOOL_DIR;
+#endif
+       COMPUTE_DIRECTORY(ctdl_spool_dir);
+       COMPUTE_DIRECTORY(ctdl_netout_dir);
+       COMPUTE_DIRECTORY(ctdl_netin_dir);
+
+
        /* 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));
        }
@@ -183,7 +245,12 @@ int main(int argc, char **argv)
         * Bind the server to a Unix-domain socket.
         */
        CtdlRegisterServiceHook(0,
-                               "citadel.socket",
+#ifndef HAVE_RUN_DIR
+                                        "."
+#else
+                                        RUN_DIR
+#endif
+                               "/citadel.socket",
                                citproto_begin_session,
                                do_command_loop,
                                do_async_loop);
@@ -234,7 +301,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 +310,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);
 }