-extern pthread_key_t MyConKey;
-
-extern int ig_tcp_server(char *ip_addr, int port_number, int queue_len);
-extern int ig_uds_server(char *sockpath, int queue_len);
-
-
-char ctdl_key_dir[PATH_MAX]=SSL_DIR;
-char file_crpt_file_key[PATH_MAX]="";
-char file_crpt_file_csr[PATH_MAX]="";
-char file_crpt_file_cer[PATH_MAX]="";
-
-char socket_dir[PATH_MAX]; /* where to talk to our citadel server */
-const char editor_absolut_dir[PATH_MAX]=EDITORDIR; /* nailed to what configure gives us. */
-char static_dir[PATH_MAX]; /* calculated on startup */
-char static_local_dir[PATH_MAX]; /* calculated on startup */
-char static_icon_dir[PATH_MAX]; /* where should we find our mime icons? */
-char *static_dirs[]={ /* needs same sort order as the web mapping */
- (char*)static_dir, /* our templates on disk */
- (char*)static_local_dir, /* user provided templates disk */
- (char*)editor_absolut_dir, /* the editor on disk */
- (char*)static_icon_dir /* our icons... */
-};
-
-/*
- * Subdirectories from which the client may request static content
- *
- * (If you add more, remember to increment 'ndirs' below)
- */
-char *static_content_dirs[] = {
- "static", /* static templates */
- "static.local", /* site local static templates */
- "tiny_mce" /* rich text editor */
-};
-
-int ndirs=3;
-
-
-char *server_cookie = NULL; /* our Cookie connection to the client */
-int http_port = PORT_NUM; /* Port to listen on */
-char *ctdlhost = DEFAULT_HOST; /* our name */
-char *ctdlport = DEFAULT_PORT; /* our Port */
-int setup_wizard = 0; /* should we run the setup wizard? \todo */
-char wizard_filename[PATH_MAX]; /* where's the setup wizard? */
-int running_as_daemon = 0; /* should we deamonize on startup? */
-
-
-
-/*
- * Shut us down the regular way.
- * signum is the signal we want to forward
- */
-pid_t current_child;
-void graceful_shutdown_watcher(int signum) {
- lprintf (1, "bye; shutting down watcher.");
- kill(current_child, signum);
- if (signum != SIGHUP)
- exit(0);
-}
-
-
-
-
-/*
- * Shut us down the regular way.
- * signum is the signal we want to forward
- */
-pid_t current_child;
-void graceful_shutdown(int signum) {
- char wd[SIZ];
- FILE *FD;
- int fd;
- getcwd(wd, SIZ);
- lprintf (1, "bye going down gracefull.[%d][%s]\n", signum, wd);
- fd = msock;
- msock = -1;
- time_to_die = 1;
- FD=fdopen(fd, "a+");
- fflush (FD);
- fclose (FD);
- close(fd);
-}
-
-
-/*
- * Start running as a daemon.
- */
-void start_daemon(char *pid_file)
-{
- int status = 0;
- pid_t child = 0;
- FILE *fp;
- int do_restart = 0;
-
- current_child = 0;
-
- /* Close stdin/stdout/stderr and replace them with /dev/null.
- * We don't just call close() because we don't want these fd's
- * to be reused for other files.
- */
- chdir("/");
-
- signal(SIGHUP, SIG_IGN);
- signal(SIGINT, SIG_IGN);
- signal(SIGQUIT, SIG_IGN);
-
- child = fork();
- if (child != 0) {
- exit(0);
- }
-
- setsid();
- umask(0);
- freopen("/dev/null", "r", stdin);
- freopen("/dev/null", "w", stdout);
- freopen("/dev/null", "w", stderr);
- signal(SIGTERM, graceful_shutdown_watcher);
- signal(SIGHUP, graceful_shutdown_watcher);
-
- do {
- current_child = fork();
-
-
- if (current_child < 0) {
- perror("fork");
- ShutDownLibCitadel ();
- exit(errno);
- }
-
- else if (current_child == 0) { /* child process */
- signal(SIGHUP, graceful_shutdown);
-
- return; /* continue starting webcit. */
- }
- else { /* watcher process */
- if (pid_file) {
- fp = fopen(pid_file, "w");
- if (fp != NULL) {
- fprintf(fp, "%d\n", getpid());
- fclose(fp);
- }
- }
- waitpid(current_child, &status, 0);
- }
-
- do_restart = 0;
-
- /* Did the main process exit with an actual exit code? */
- if (WIFEXITED(status)) {
-
- /* Exit code 0 means the watcher should exit */
- if (WEXITSTATUS(status) == 0) {
- do_restart = 0;
- }
-
- /* Exit code 101-109 means the watcher should exit */
- else if ( (WEXITSTATUS(status) >= 101) && (WEXITSTATUS(status) <= 109) ) {
- do_restart = 0;
- }
-
- /* Any other exit code means we should restart. */
- else {
- do_restart = 1;
- }
- }
-
- /* Any other type of termination (signals, etc.) should also restart. */
- else {
- do_restart = 1;
- }
-
- } while (do_restart);
-
- if (pid_file) {
- unlink(pid_file);
- }
- ShutDownLibCitadel ();
- exit(WEXITSTATUS(status));
-}
-
-/*
- * Spawn an additional worker thread into the pool.
- */
-void spawn_another_worker_thread()
-{
- pthread_t SessThread; /* Thread descriptor */
- pthread_attr_t attr; /* Thread attributes */
- int ret;
-
- lprintf(3, "Creating a new thread\n");