X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fserver_main.c;h=9bd9be89e8ebfd21468f6bc1a95b2ad5f6a61604;hb=HEAD;hp=3715bb356fba85b797906885d5c864317f92bb60;hpb=b26b9a4af7901e3a80354248c92baafb8a994c18;p=citadel.git diff --git a/citadel/server_main.c b/citadel/server_main.c deleted file mode 100644 index 3715bb356..000000000 --- a/citadel/server_main.c +++ /dev/null @@ -1,460 +0,0 @@ -/* - * citserver's main() function lives here. - * - * $Id$ - */ - -#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 -#include -#ifdef HAVE_PTHREAD_H -#include -#endif -#ifdef HAVE_SYS_PRCTL_H -#include -#endif -#include -#include "citadel.h" -#include "server.h" -#include "serv_extensions.h" -#include "sysdep_decls.h" -#include "citserver.h" -#include "support.h" -#include "config.h" -#include "control.h" -#include "database.h" -#include "user_ops.h" -#include "housekeeping.h" -#include "citadel_dirs.c" - -#include "modules_init.h" -#include "ecrash.h" - -#ifdef HAVE_SYS_SELECT_H -#include -#endif - -#ifndef HAVE_SNPRINTF -#include "snprintf.h" -#endif -const char *CitadelServiceUDS="citadel-UDS"; -const char *CitadelServiceTCP="citadel-TCP"; - - -void go_threading(void); - - -/* - * Here's where it all begins. - */ -int main(int argc, char **argv) -{ - char facility[32]; - 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; -#ifdef HAVE_RUN_DIR - struct stat filestats; -#endif -#ifdef HAVE_BACKTRACE - eCrashParameters params; -// eCrashSymbolTable symbol_table; -#endif - /* initialise semaphores here. Patch by Matt and davew - * its called here as they are needed by lprintf for thread safety - */ - CtdlInitBase64Table(); - InitialiseSemaphores(); - - /* initialize the master context */ - InitializeMasterCC(); - - /* parse command-line arguments */ - for (a=1; a config.c_min_workers) && (CtdlThreadWorkerAvg < 20)) - { - /* Ask a worker thread to stop as we no longer need it */ - begin_critical_section(S_THREAD_LIST); - last_worker = CtdlThreadList; - while (last_worker) - { - if (last_worker->flags & CTDLTHREAD_WORKER && last_worker->state > CTDL_THREAD_STOPPING) - break; - else - last_worker = last_worker->next; - } - end_critical_section(S_THREAD_LIST); - if (last_worker) - { -#ifdef WITH_THREADLOG - CtdlLogPrintf(CTDL_DEBUG, "Thread system, stopping excess worker thread \"%s\" (%ld).\n", - last_worker->name, - last_worker->tid - ); -#endif - CtdlThreadStop(last_worker); - } - } - - /* - * If all our workers are working hard, start some more to help out - * with things - */ - begin_critical_section(S_THREAD_LIST); - /* FIXME: come up with a better way to dynamically alter the number of threads - * based on the system load - */ -// if ((CtdlThreadGetWorkers() < config.c_max_workers) && (CtdlThreadGetWorkers() < num_sessions)) - // && (CtdlThreadLoadAvg < 90) ) - if ((CtdlThreadGetWorkers() < config.c_max_workers) && (CtdlThreadWorkerAvg > 60) && (CtdlThreadLoadAvg < 90) ) - { - end_critical_section(S_THREAD_LIST); - for (i=0; i<5 ; i++) -// for (i=0; i< (num_sessions - CtdlThreadGetWorkers()) ; i++) -// for (i=0; i< (10 - (55 - CtdlThreadWorkerAvg) / CtdlThreadWorkerAvg / CtdlThreadGetWorkers()) ; i++) - { - begin_critical_section(S_THREAD_LIST); - ctdl_internal_create_thread("Worker Thread", - CTDLTHREAD_BIGSTACK + CTDLTHREAD_WORKER, - worker_thread, - NULL - ); - end_critical_section(S_THREAD_LIST); - } - } - else - end_critical_section(S_THREAD_LIST); - - begin_critical_section(S_THREAD_LIST); - ctdl_internal_thread_gc(); - end_critical_section(S_THREAD_LIST); - - if (CtdlThreadGetCount() <= 1) // Shutting down clean up the garbage collector - { - begin_critical_section(S_THREAD_LIST); - ctdl_internal_thread_gc(); - end_critical_section(S_THREAD_LIST); - } - - if (CtdlThreadGetCount()) - CtdlThreadSleep(1); - } - /* - * If the above loop exits we must be shutting down since we obviously have no threads - */ - ctdl_thread_internal_cleanup(); -}