]> code.citadel.org Git - citadel.git/blobdiff - citadel/sysdep.c
* The size constant "256" which shows up everywhere as a buffer size has now
[citadel.git] / citadel / sysdep.c
index 8a37d59339bd8021a41526565f5dd7083ecec0f4..a50bb0818fe0f7a9d3a8c561f0439d536aafb425 100644 (file)
@@ -461,7 +461,7 @@ void client_write(char *buf, int nbytes)
  */
 void cprintf(const char *format, ...) {   
         va_list arg_ptr;   
-        char buf[256];   
+        char buf[SIZ];   
    
         va_start(arg_ptr, format);   
         if (vsnprintf(buf, sizeof buf, format, arg_ptr) == -1)
@@ -636,7 +636,7 @@ void cmd_nset(char *cmdbuf)
        FILE *netsetup;
        int ch;
        int a, b;
-       char netsetup_args[3][256];
+       char netsetup_args[3][SIZ];
 
        if (CC->usersupp.axlevel < 6) {
                cprintf("%d Higher access required.\n", 
@@ -848,7 +848,7 @@ void init_master_fdset(void) {
  */
 int main(int argc, char **argv)
 {
-       pthread_t HousekeepingThread;   /* Thread descriptor */
+       pthread_t WorkerThread; /* Thread descriptor */
         pthread_attr_t attr;           /* Thread attributes */
        char tracefile[128];            /* Name of file to log traces to */
        int a, i;                       /* General-purpose variables */
@@ -927,6 +927,7 @@ int main(int argc, char **argv)
        lprintf(7, "Loading citadel.config\n");
        get_config();
 
+
        /*
         * Do non system dependent startup functions.
         */
@@ -992,33 +993,26 @@ int main(int argc, char **argv)
                }
        }
 
-       /*
-        * Create the housekeeper thread
-        */
-       lprintf(7, "Starting housekeeper thread\n");
-       pthread_attr_init(&attr);
-               pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-       if (pthread_create(&HousekeepingThread, &attr,
-          (void* (*)(void*)) housekeeping_loop, NULL) != 0) {
-               lprintf(1, "Can't create housekeeping thead: %s\n",
-                       strerror(errno));
-       }
-
-
+       /* We want to check for idle sessions once per minute */
+       CtdlRegisterSessionHook(terminate_idle_sessions, EVT_TIMER);
+       
        /*
         * Now create a bunch of worker threads.
         */
        for (i=0; i<(config.c_min_workers-1); ++i) {
+               lprintf(9, "Creating worker thread %d\n", i);
                pthread_attr_init(&attr);
                        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-               if (pthread_create(&HousekeepingThread, &attr,
+               if (pthread_create(&WorkerThread, &attr,
                   (void* (*)(void*)) worker_thread, NULL) != 0) {
                        lprintf(1, "Can't create worker thead: %s\n",
                        strerror(errno));
                }
        }
 
+
        /* Now this thread can become a worker as well. */
+       lprintf(9, "Original thread entering worker loop\n");
        worker_thread();
 
        return(0);
@@ -1180,9 +1174,7 @@ SETUP_FD: memcpy(&readfds, &masterfds, sizeof masterfds);
                        /* We're bound to a session, now do *one* command */
                        if (bind_me != NULL) {
                                become_session(bind_me);
-                               cdb_begin_transaction();
                                CC->h_command_function();
-                               cdb_end_transaction();
                                become_session(NULL);
                                bind_me->state = CON_IDLE;
                                if (bind_me->kill_me == 1) {
@@ -1197,6 +1189,8 @@ SETUP_FD: memcpy(&readfds, &masterfds, sizeof masterfds);
                        last_timer = time(NULL);
                        PerformSessionHooks(EVT_TIMER);
                }
+
+               check_sched_shutdown();
        }
 
        /* If control reaches this point, the server is shutting down */