CtdlForEachMessage() don't process message 0
authorArt Cancro <ajc@citadel.org>
Tue, 29 Aug 2023 19:03:34 +0000 (15:03 -0400)
committerArt Cancro <ajc@citadel.org>
Tue, 29 Aug 2023 19:03:34 +0000 (15:03 -0400)
citadel/server/citadel_defs.h
citadel/server/housekeeping.c
citadel/server/modules/fulltext/serv_fulltext.c
citadel/server/modules_init.c
citadel/server/msgbase.c
citadel/server/sysdep.c
citadel/server/threads.c

index 2e306a20e371bedaa9465dedbfb337464411ef70..a879c4631a76d48b40893df1942b17d3a5e445e5 100644 (file)
@@ -27,7 +27,7 @@
 #define LIBCITADEL_MIN 951     // Minimum required version of libcitadel
 #define SERVER_TYPE    0       // zero for stock Citadel; other developers please obtain SERVER_TYPE codes for your implementations
 
-#define TRACE  syslog(LOG_DEBUG, "\033[7m  Checkpoint: %s : %d  \033[0m", __FILE__, __LINE__)
+#define TRACE  syslog(LOG_DEBUG, "\033[7m  Checkpoint: %p : %s : %d  \033[0m", CC, __FILE__, __LINE__)
 
 #ifndef LONG_MAX
 #define LONG_MAX 2147483647L
index 55e7e77d68058f1b9b84fcb4a6d1a97ebbeadbfd..5ce28bf8182fd0f9b985191bba4017ea808f4a95 100644 (file)
@@ -88,7 +88,7 @@ void do_housekeeping(void) {
        int do_perminute_housekeeping_now = 0;
        time_t now;
 
-       if (housekeeping_disabled) {
+       if ( (housekeeping_disabled) || (housekeeping_in_progress) ) {
                return;
        }
 
@@ -113,6 +113,10 @@ void do_housekeeping(void) {
                return;
        }
 
+       if (!do_housekeeping_now) {
+               return;
+       }
+
        // Ok, at this point we've made the decision to run the housekeeping
        // loop.  Everything below this point is real work.
 
index b80ade388ad29a4594298a2ba7d153cc224e0293..4f04baad649f300a9fca3d1b4d5f331b4171f480 100644 (file)
@@ -60,6 +60,7 @@ void ft_flush_cache(void) {
        int i;
        time_t last_update = 0;
 
+       cdb_begin_transaction();
        for (i=0; i<65536; ++i) {
                if ((time(NULL) - last_update) >= 10) {
                        syslog(LOG_INFO, "fulltext: flushing index cache to disk (%d%% complete)", (i * 100 / 65536));
@@ -72,6 +73,7 @@ void ft_flush_cache(void) {
                        ftc_msgs[i] = NULL;
                }
        }
+       cdb_end_transaction();
        syslog(LOG_INFO, "fulltext: flushed index cache to disk (100%% complete)");
 }
 
index b27c2fe1bbff04259283da6640f261685ea15a2f..c6cce4988357fbec8739b864136aa2220ea51337 100644 (file)
@@ -45,7 +45,7 @@ void initialize_modules(int is_threading) {
 
        // FIXME
        // There is something in this module that fux0rs the new backend, causing it to deadlock.
-       // syslog(LOG_DEBUG, "extensions: init %s", ctdl_module_init_fulltext());
+       syslog(LOG_DEBUG, "extensions: init %s", ctdl_module_init_fulltext());
 
        syslog(LOG_DEBUG, "extensions: init %s", ctdl_module_init_image());
        syslog(LOG_DEBUG, "extensions: init %s", ctdl_module_init_imap());
index 1f1671da46fcdbe68e308c20f3cf95bff3892381..27c3e51b0b45f2d362fee1f4f298ffcf58fd58eb 100644 (file)
@@ -653,7 +653,7 @@ int CtdlForEachMessage(int mode, long ref, char *search_string,
        }
 
        // Now begin the traversal.
-       if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) {
+       if (num_msgs > 0) for (a = 0; a < num_msgs; ++a) if (msglist[a] > 0) {
 
                // If the caller is looking for a specific MIME type, filter
                // out all messages which are not of the type requested.
index cbe62879a06dfd278336acacbd60d22f3ce3aa68..772308e448e539df575f73cdff9b1a33814c8707 100644 (file)
@@ -825,8 +825,8 @@ do_select:  force_purge = 0;
                }
                end_critical_section(S_SESSION_TABLE);
 
-               if (bind_me) {
-                       goto SKIP_SELECT;
+               if (bind_me) {                  // don't search for a session to bind to.
+                       goto SKIP_SELECT;       // we already found one.
                }
 
                // If we got this far, it means that there are no sessions
@@ -990,13 +990,7 @@ SKIP_SELECT:
        }
 
        // If control reaches this point, the server is shutting down
-       while(1) {
-               sleep(1);               // wait to die
-       }
-       //pthread_mutex_lock(&ThreadCountMutex);
-       //--num_workers;
-       //pthread_mutex_unlock(&ThreadCountMutex);
-       //return(NULL);
+       return(NULL);
 }
 
 
index 6b782a673d684d5e8fb4c5719dbd7342c4dc1273..7fe9d5f38b9d7e98bbeaa088e9b74be2e27e1373 100644 (file)
@@ -21,7 +21,6 @@ int active_workers = 0;                               // Number of ACTIVE worker threads
 pthread_mutex_t Critters[MAX_SEMAPHORES];      // Things needing locking
 int server_shutting_down = 0;                  // set to nonzero during shutdown
 pthread_mutex_t ThreadCountMutex;
-char locks[MAX_SEMAPHORES+1];
 
 void InitializeSemaphores(void) {
        int i;
@@ -29,9 +28,7 @@ void InitializeSemaphores(void) {
        // Set up a bunch of semaphores to be used for critical sections
        for (i=0; i<MAX_SEMAPHORES; ++i) {
                pthread_mutex_init(&Critters[i], NULL);
-               locks[i] = ' ';
        }
-       locks[MAX_SEMAPHORES] = 0;
 }
 
 
@@ -54,25 +51,16 @@ void begin_critical_section(int which_one) {
        // For all types of critical sections except those listed here,
        // ensure nobody ever tries to do a critical section within a
        // transaction; this could lead to deadlock.
-       if (    (which_one != S_FLOORCACHE)
-               && (which_one != S_NETCONFIGS)
-       ) {
+       if ((which_one != S_FLOORCACHE) && (which_one != S_NETCONFIGS)) {
                cdb_check_handles();
        }
 
-       //syslog(LOG_ERR, "\033[3%dm  lock(%14p, %2d, %s)\033[0m", (which_one%6)+1, pthread_self(), which_one, locks);
        pthread_mutex_lock(&Critters[which_one]);
-       //if (locks[which_one] != 'X') {
-               //syslog(LOG_ERR, "\033[31mThread %p had to wait to get a lock on %d\033[0m", pthread_self(), which_one);
-       //}
-       locks[which_one] = 'X';
 }
 
 
 // Release a semaphore lock to end a critical section.
 void end_critical_section(int which_one) {
-       locks[which_one] = '_';
-       //syslog(LOG_ERR, "\033[3%dmunlock(%14p, %2d, %s)\033[0m", (which_one%6)+1, pthread_self(), which_one, locks);
        pthread_mutex_unlock(&Critters[which_one]);
 }