]> 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 6ee7f9b806efdff4b7be05cd102d5a0258096247..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,7 +76,14 @@ 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();
 
@@ -98,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)) {
@@ -130,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));
        }
@@ -168,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();
 
@@ -180,15 +212,10 @@ int main(int argc, char **argv)
         * Bind the server to a Unix-domain socket.
         */
        CtdlRegisterServiceHook(0,
-#ifndef HAVE_RUN_DIR
-                                        "."
-#else
-                                        RUN_DIR
-#endif
-                               "/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).