X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fserver_main.c;h=054c8054752fbf116894e44fa2936f9f2cdcde53;hb=8904d5e7123ba2f4588f48deed392b1a2d9faa39;hp=e04fd6286acb1f54ffbbf7e317e80a7e76a3f779;hpb=1248e88ae490d17b4896ada5a74a0a9ea23b365c;p=citadel.git diff --git a/citadel/server_main.c b/citadel/server_main.c index e04fd6286..054c80547 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -1,188 +1,203 @@ /* * citserver's main() function lives here. + * + * Copyright (c) 1987-2013 by the citadel.org team * - * $Id$ + * This program is open source software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. */ - -#include "sysdep.h" -#include -#include #include -#include -#include -#include #include -#include -#include -#include -#include - -#if TIME_WITH_SYS_TIME -# include -# include -#else -# if HAVE_SYS_TIME_H -# include -# else -# include -# endif -#endif - -#include -#include -#include -#include -#include -#include -#include -#include #include -#ifdef HAVE_PTHREAD_H -#include -#endif -#ifdef HAVE_SYS_PRCTL_H -#include -#endif -#include "citadel.h" -#include "server.h" -#include "serv_extensions.h" -#include "sysdep_decls.h" +#include + #include "citserver.h" -#include "support.h" +#include "svn_revision.h" +#include "modules_init.h" #include "config.h" -#include "database.h" -#include "housekeeping.h" -#include "tools.h" -#include "citadel_dirs.c" +#include "control.h" +#include "serv_extensions.h" +#include "citadel_dirs.h" +#include "user_ops.h" +#include "ecrash.h" -#ifdef HAVE_SYS_SELECT_H -#include -#endif +const char *CitadelServiceUDS="citadel-UDS"; +const char *CitadelServiceTCP="citadel-TCP"; -#ifndef HAVE_SNPRINTF -#include "snprintf.h" -#endif -int running_as_daemon = 0; + +void go_threading(void); /* * Here's where it all begins. */ int main(int argc, char **argv) { + size_t basesize = 64; char facility[32]; - int a, i; /* General-purpose variables */ - struct passwd *pw; + int a; /* General-purpose variables */ + struct passwd pw, *pwp = NULL; + char pwbuf[SIZ]; int drop_root_perms = 1; - size_t size; int relh=0; int home=0; + int dbg=0; char relhome[PATH_MAX]=""; char ctdldir[PATH_MAX]=CTDLDIR; - + int syslog_facility = LOG_DAEMON; + const char *eDebuglist[] = {NULL, NULL}; +#ifdef HAVE_RUN_DIR + struct stat filestats; +#endif +#ifdef HAVE_BACKTRACE + eCrashParameters params; +// eCrashSymbolTable symbol_table; +#endif + /* initialize the master context */ InitializeMasterCC(); + InitializeMasterTSD(); /* parse command-line arguments */ - for (a=1; apw_name, pw->pw_gid); - if (setgid(pw->pw_gid)) - lprintf(CTDL_CRIT, "setgid(%ld): %s\n", (long)pw->pw_gid, + initgroups(pw.pw_name, pw.pw_gid); + if (setgid(pw.pw_gid)) + syslog(LOG_CRIT, "setgid(%ld): %s", (long)pw.pw_gid, strerror(errno)); } - lprintf(CTDL_INFO, "Changing uid to %ld\n", (long)CTDLUID); + syslog(LOG_INFO, "Changing uid to %ld", (long)CTDLUID); if (setuid(CTDLUID) != 0) { - lprintf(CTDL_CRIT, "setuid() failed: %s\n", strerror(errno)); + syslog(LOG_CRIT, "setuid() failed: %s", strerror(errno)); } #if defined (HAVE_SYS_PRCTL_H) && defined (PR_SET_DUMPABLE) prctl(PR_SET_DUMPABLE, 1); @@ -246,28 +324,10 @@ int main(int argc, char **argv) } /* We want to check for idle sessions once per minute */ - CtdlRegisterSessionHook(terminate_idle_sessions, EVT_TIMER); - - /* - * Now create a bunch of worker threads. - */ - 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(); - } - end_critical_section(S_WORKER_LIST); - - /* Create the indexer thread. */ - create_maintenance_threads(); + CtdlRegisterSessionHook(terminate_idle_sessions, EVT_TIMER, PRIO_CLEANUP + 1); - /* 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); + go_threading(); + + master_cleanup(exit_signal); return(0); }