]> code.citadel.org Git - citadel.git/blobdiff - citadel/housekeeping.c
* Wrap txn_begin and txn_end in S_DATABASE mutex
[citadel.git] / citadel / housekeeping.c
index 726c928158e213e09ce0dc51c0a02f8033eeb9b6..15f43df16fd8a1efbb3dbb2b394f4cc241151525 100644 (file)
@@ -1,8 +1,9 @@
 /*
+ * $Id$
+ *
  * This file contains housekeeping tasks which periodically
  * need to be executed.  It keeps a nice little queue...
  *
- * $Id$
  */
 
 #include "sysdep.h"
@@ -20,9 +21,6 @@
 #ifdef HAVE_SYS_SELECT_H
 #include <sys/select.h>
 #endif
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #include "tools.h"
 #include "citadel.h"
 #include "server.h"
@@ -31,6 +29,7 @@
 #include "housekeeping.h"
 #include "sysdep_decls.h"
 #include "room_ops.h"
+#include "database.h"
 
 
 int housepipe[2];      /* This is the queue for housekeeping tasks */
@@ -47,25 +46,18 @@ void terminate_idle_sessions(void) {
        time_t now;
        int session_to_kill;
 
-       do {
-               now = time(NULL);
-               session_to_kill = 0;
-               begin_critical_section(S_SESSION_TABLE);
-               for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
-                       if (  (ccptr!=CC)
-                       && (config.c_sleeping > 0)
-                       && (now - (ccptr->lastcmd) > config.c_sleeping) ) {
-                               session_to_kill = ccptr->cs_pid;
-                               }
-                       }
-               end_critical_section(S_SESSION_TABLE);
-               if (session_to_kill > 0) {
-                       lprintf(3, "Session %d timed out.  Terminating it...\n",
-                               session_to_kill);
-                       kill_session(session_to_kill);
-                       }
-               } while(session_to_kill > 0);
+       now = time(NULL);
+       session_to_kill = 0;
+       begin_critical_section(S_SESSION_TABLE);
+       for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
+               if (  (ccptr!=CC)
+               && (config.c_sleeping > 0)
+               && (now - (ccptr->lastcmd) > config.c_sleeping) ) {
+                       ccptr->kill_me = 1;
+               }
        }
+       end_critical_section(S_SESSION_TABLE);
+}
 
 
 
@@ -107,7 +99,7 @@ void housekeeping_loop(void) {
                        tv.tv_usec = 0;
                        FD_ZERO(&readfds);
                        FD_SET(housepipe[0], &readfds);
-                       select(housepipe[0] + 1, &readfds, 0L, 0L, &tv);
+                       select(housepipe[0] + 1, &readfds, NULL, NULL, &tv);
                        if (FD_ISSET(housepipe[0], &readfds)) {
                                did_something = 1;
                        }
@@ -121,6 +113,7 @@ void housekeeping_loop(void) {
                        }
 
                        extract(cmd, house_cmd, 0);
+                       cdb_begin_transaction();
 
                        /* Do whatever this cmd requires */
 
@@ -139,6 +132,8 @@ void housekeeping_loop(void) {
                                lprintf(7, "Unknown housekeeping command\n");
                        }
 
+                       cdb_end_transaction();
+
                } while (did_something);
        }
 }
@@ -167,26 +162,27 @@ void enter_housekeeping_cmd(char *cmd) {
  * NOTE: this function pair should ONLY be called during startup.  It is NOT
  * thread safe.
  */
-void check_ref_counts_backend(struct quickroom *qrbuf) {
+void check_ref_counts_backend(struct quickroom *qrbuf, void *data) {
        struct floor flbuf;
 
        getfloor(&flbuf, qrbuf->QRfloor);
        ++flbuf.f_ref_count;
        flbuf.f_flags = flbuf.f_flags | QR_INUSE;
        putfloor(&flbuf, qrbuf->QRfloor);
-       }
+}
 
 void check_ref_counts(void) {
        struct floor flbuf;
        int a;
 
+       lprintf(7, "Checking floor reference counts\n");
        for (a=0; a<MAXFLOORS; ++a) {
                getfloor(&flbuf, a);
                flbuf.f_ref_count = 0;
                flbuf.f_flags = flbuf.f_flags & ~QR_INUSE;
                putfloor(&flbuf, a);
-               }
+       }
 
-       ForEachRoom(check_ref_counts_backend);
-       }       
+       ForEachRoom(check_ref_counts_backend, NULL);
+}