]> code.citadel.org Git - citadel.git/blobdiff - citadel/sysdep.c
* lots of warning fixes; builds with -std1 on dec unix
[citadel.git] / citadel / sysdep.c
index 8680e2209592a1cae6b444a1e1e79d330c01893d..93cfa8e2679da4012b2f0b1f0c2c55484d6da369 100644 (file)
@@ -21,6 +21,7 @@
 #include <sys/wait.h>
 #include <sys/socket.h>
 #include <sys/time.h>
+#include <limits.h>
 #include <netinet/in.h>
 #include <netdb.h>
 #include <string.h>
 #include <pthread.h>
 #include "citadel.h"
 #include "server.h"
-#include "proto.h"
-
-#ifdef NEED_SELECT_H
+#include "sysdep_decls.h"
+#include "citserver.h"
+#include "support.h"
+#include "config.h"
+#include "database.h"
+#include "housekeeping.h"
+#include "dynloader.h"
+
+#ifdef HAVE_SYS_SELECT_H
 #include <sys/select.h>
 #endif
 
-extern struct CitContext *ContextList;
-extern struct config config;
-extern char bbs_home_directory[];
-extern int home_specified;
+#ifndef HAVE_SNPRINTF
+#include "snprintf.h"
+#endif
 
 pthread_mutex_t Critters[MAX_SEMAPHORES];      /* Things needing locking */
 pthread_key_t MyConKey;                                /* TSD key for MyContext() */
@@ -48,6 +54,8 @@ pthread_key_t MyConKey;                               /* TSD key for MyContext() */
 int msock;                                     /* master listening socket */
 int verbosity = 3;                             /* Logging level */
 
+struct CitContext masterCC;
+
 
 /*
  * lprintf()  ...   Write logging information
@@ -81,7 +89,7 @@ void init_sysdep(void) {
                }
 
        /*
-        * Set up a place to put thread-specific data.
+        * Set up a place to put thred-specific data.
         * We only need a single pointer per thread - it points to the
         * thread's CitContext structure in the ContextList linked list.
         */
@@ -93,10 +101,10 @@ void init_sysdep(void) {
         * The action for unexpected signals and exceptions should be to
         * call master_cleanup() to gracefully shut down the server.
         */
-       signal(SIGINT, master_cleanup);
-       signal(SIGQUIT, master_cleanup);
-       signal(SIGHUP, master_cleanup);
-       signal(SIGTERM, master_cleanup);
+       signal(SIGINT, (void(*)(int))master_cleanup);
+       signal(SIGQUIT, (void(*)(int))master_cleanup);
+       signal(SIGHUP, (void(*)(int))master_cleanup);
+       signal(SIGTERM, (void(*)(int))master_cleanup);
        }
 
 
@@ -108,7 +116,6 @@ void begin_critical_section(int which_one)
        int oldval;
 
        lprintf(8, "begin_critical_section(%d)\n", which_one);
-       if (CC != NULL) hook_crit_get(CC->cs_pid, which_one);
 
        /* Don't get interrupted during the critical section */
        pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldval);
@@ -116,7 +123,6 @@ void begin_critical_section(int which_one)
        /* Obtain a semaphore */
        pthread_mutex_lock(&Critters[which_one]);
 
-       if (CC != NULL) hook_crit_got(CC->cs_pid, which_one);
        }
 
 /*
@@ -127,7 +133,6 @@ void end_critical_section(int which_one)
        int oldval;
 
        lprintf(8, "  end_critical_section(%d)\n", which_one);
-       if (CC != NULL) hook_crit_end(CC->cs_pid, which_one);
 
        /* Let go of the semaphore */
        pthread_mutex_unlock(&Critters[which_one]);
@@ -152,7 +157,7 @@ int ig_tcp_server(int port_number, int queue_len)
        struct sockaddr_in sin;
        int s, i;
 
-       bzero((char *)&sin, sizeof(sin));
+       memset(&sin, 0, sizeof(sin));
        sin.sin_family = AF_INET;
        sin.sin_addr.s_addr = INADDR_ANY;
 
@@ -213,7 +218,10 @@ int ig_tcp_server(int port_number, int queue_len)
  * Return a pointer to a thread's own CitContext structure (new)
  */
 struct CitContext *MyContext(void) {
-       return (struct CitContext *) pthread_getspecific(MyConKey);
+       struct CitContext *retCC;
+       retCC = (struct CitContext *) pthread_getspecific(MyConKey);
+       if (retCC == NULL) retCC = &masterCC;
+       return(retCC);
        }
 
 
@@ -229,6 +237,7 @@ struct CitContext *CreateNewContext(void) {
                lprintf(1, "citserver: can't allocate memory!!\n");
                pthread_exit(NULL);
                }
+       memset(me, 0, sizeof(struct CitContext));
 
        begin_critical_section(S_SESSION_TABLE);
        me->next = ContextList;
@@ -428,10 +437,8 @@ int client_gets(char *buf)
  * The system-dependent part of master_cleanup() - close the master socket.
  */
 void sysdep_master_cleanup(void) {
-       lprintf(3, "Closing master socket %d\n", msock);
+       lprintf(7, "Closing master socket %d\n", msock);
        close(msock);
-       lprintf(7, "Closing databases\n");
-       close_databases();
        }
 
 /*
@@ -463,10 +470,11 @@ void kill_session(int session_to_kill) {
 /*
  * The system-dependent wrapper around the main context loop.
  */
-void sd_context_loop(struct CitContext *con) {
+void *sd_context_loop(struct CitContext *con) {
        pthread_cleanup_push(*cleanup_stuff, NULL);
        context_loop(con);
        pthread_cleanup_pop(0);
+       return NULL;
        }
 
 
@@ -594,7 +602,8 @@ int main(int argc, char **argv)
        char tracefile[128];            /* Name of file to log traces to */
        int a, i;                       /* General-purpose variables */
        char convbuf[128];
-
+       char modpath[128];
+        
        /* specify default port name and trace file */
        strcpy(tracefile, "");
 
@@ -645,17 +654,21 @@ int main(int argc, char **argv)
        /* Initialize... */
        init_sysdep();
        openlog("citserver",LOG_PID,LOG_USER);
-
+        lprintf(1, "Initting modules...\n");
+        snprintf(modpath, 128, "%s/modules", BBSDIR);
+        DLoader_Init(modpath);
+        lprintf(1, "Modules done initializing...\n");
+/*
+        lprintf(1, "First symtab item:");
+        lprintf(1, my_symtab->fcn_name);
+        lprintf(1, "\n");
+*/                                                 
        /* Load site-specific parameters */
        lprintf(7, "Loading citadel.config\n");
        get_config();
-       hook_init();
 
-       /* Databases must be opened *after* config is loaded, otherwise we might
-        * end up working in the wrong directory.
-        */
-       lprintf(7, "Opening databases\n");
-       open_databases();
+       /* Do non system dependent startup functions */
+       master_startup();
 
        /*
         * Bind the server to our favourite port.
@@ -704,8 +717,10 @@ int main(int argc, char **argv)
 
                        /* now create the thread */
                        lprintf(9, "creating thread\n");
-                       if (pthread_create(&SessThread, &attr, (void *)sd_context_loop,
-                          con) != 0) {
+                       if (pthread_create(&SessThread, &attr,
+                                          (void* (*)(void*)) sd_context_loop,
+                                          con)
+                           != 0) {
                                lprintf(1,
                                        "citserver: can't create thread: %s\n",
                                        strerror(errno));