Initialize TSD key earlier in the startup process. Newer Linux/Linux distributions...
authorArt Cancro <ajc@citadel.org>
Tue, 13 Aug 2019 18:37:14 +0000 (14:37 -0400)
committerArt Cancro <ajc@citadel.org>
Tue, 13 Aug 2019 18:37:14 +0000 (14:37 -0400)
citadel/citadel.h
citadel/database.c
citadel/debian/changelog
citadel/server_main.c
citadel/sysdep.c
citadel/threads.c
citadel/threads.h
citadel/user_ops.c

index 8f33900899032aacc9b273860a7e177174918705..8f1576218d29dd042b1dfc2657b755f93b4639d0 100644 (file)
@@ -35,7 +35,7 @@ extern "C" {
  */
 #define CITADEL        PACKAGE_STRING
 
-#define REV_LEVEL      925             // This version
+#define REV_LEVEL      927             // This version
 #define REV_MIN                591             // Oldest compatible database
 #define EXPORT_REV_MIN 760             // Oldest compatible export files
 #define LIBCITADEL_MIN 922             // Minimum required version of libcitadel
index 8b5820edb1a5eb9d0e229bf52b33d3f78154fa62..94d283714e126154b500c9c5965463788ffc8bc3 100644 (file)
@@ -76,7 +76,7 @@ void cdb_verbose_err(const DB_ENV * dbenv, const char *errpfx, const char *msg)
 
 
 /* wrapper for txn_abort() that logs/aborts on error */
-static void txabort(DB_TXN * tid)
+static void txabort(DB_TXN *tid)
 {
        int ret;
 
@@ -90,7 +90,7 @@ static void txabort(DB_TXN * tid)
 
 
 /* wrapper for txn_commit() that logs/aborts on error */
-static void txcommit(DB_TXN * tid)
+static void txcommit(DB_TXN *tid)
 {
        int ret;
 
@@ -104,7 +104,7 @@ static void txcommit(DB_TXN * tid)
 
 
 /* wrapper for txn_begin() that logs/aborts on error */
-static void txbegin(DB_TXN ** tid)
+static void txbegin(DB_TXN **tid)
 {
        int ret;
 
@@ -416,9 +416,8 @@ int cdb_store(int cdb, const void *ckey, int ckeylen, void *cdata, int cdatalen)
 {
 
        DBT dkey, ddata;
-       DB_TXN *tid;
+       DB_TXN *tid = NULL;
        int ret = 0;
-
        struct CtdlCompressHeader zheader;
        char *compressed_data = NULL;
        int compressing = 0;
@@ -472,11 +471,11 @@ int cdb_store(int cdb, const void *ckey, int ckeylen, void *cdata, int cdatalen)
              retry:
                txbegin(&tid);
 
-               if ((ret = dbp[cdb]->put(dbp[cdb],      /* db */
-                                        tid,   /* transaction ID */
-                                        &dkey, /* key */
-                                        &ddata,        /* data */
-                                        0))) { /* flags */
+               if ((ret = dbp[cdb]->put(dbp[cdb],      // db
+                                        tid,           // transaction ID
+                                        &dkey,         // key
+                                        &ddata,        // data
+                                        0))) {         // flags
                        if (ret == DB_LOCK_DEADLOCK) {
                                txabort(tid);
                                goto retry;
@@ -772,8 +771,7 @@ void cdb_trunc(int cdb)
                        } else {
                                syslog(LOG_EMERG, "db: cdb_truncate(%d): %s", cdb, db_strerror(ret));
                                if (ret == ENOMEM) {
-                                       syslog(LOG_EMERG,
-                                              "db: You may need to tune your database; please read http://www.citadel.org/doku.php?id=faq:troubleshooting:out_of_lock_entries for more information.");
+                                       syslog(LOG_EMERG, "db: You may need to tune your database; please read http://www.citadel.org/doku.php?id=faq:troubleshooting:out_of_lock_entries for more information.");
                                }
                                exit(CTDLEXIT_DB);
                        }
index 94917604fed1cc7d2050331c758da4f6a732b391..760d93d20c1487d67a874c8159a8be672820451e 100644 (file)
@@ -1,3 +1,9 @@
+citadel (927-1) stable; urgency=low
+
+  * new release
+
+ -- Wilfried Goesgens <w.goesgens@outgesourced.org>  Wed, 19 Dec 2018 16:57:49 -0500
+
 citadel (925-1) stable; urgency=low
 
   * new release
index 10e366051bba31ac3e41c8d39d6f504112378752..8c4f6374184ef380a508810eebe3d4bb934b2704 100644 (file)
@@ -32,7 +32,6 @@
 uid_t ctdluid = 0;
 const char *CitadelServiceUDS="citadel-UDS";
 const char *CitadelServiceTCP="citadel-TCP";
-void go_threading(void);
 int sanity_diag_mode = 0;
 
 
@@ -40,7 +39,7 @@ int sanity_diag_mode = 0;
  * Create or remove a lock file, so we only have one Citadel Server running at a time.
  */
 void ctdl_lockfile(int yo) {
-       static char lockfilename[SIZ];
+       static char lockfilename[PATH_MAX];
        static FILE *fp;
 
        if (yo) {
@@ -251,26 +250,12 @@ int main(int argc, char **argv)
 #endif
 
        ctdl_lockfile(1);
-
-       /* Initialize... */
-       init_sysdep();
-
-       /*
-        * Do non system dependent startup functions.
-        */
-       master_startup();
-
-       /*
-        * Check that the control record is correct and place sensible values if it isn't
-        */
-       check_control();
-       
-       /*
-        * Run any upgrade entry points
-        */
-       syslog(LOG_INFO, "main: upgrading modules");
+       init_sysdep();                                          // Initialize...
+       master_startup();                                       // Do non system dependent startup functions
+       check_control();                                        // Check, sanitize, initialize the control record
+       syslog(LOG_INFO, "main: upgrading modules");            // Run any upgrade entry points
        upgrade_modules();
-       
+
 /*
  * Load the user for the masterCC or create them if they don't exist
  */
@@ -313,9 +298,6 @@ int main(int argc, char **argv)
                                do_async_loop,
                                CitadelServiceTCP);
 
-                               
-       
-       
        /*
         * Load any server-side extensions available here.
         */
index 971d729c4c282de588a791b04dd7de96eddbd679..c547f9772be4cff4c5fee27c84291bfb8d93817a 100644 (file)
@@ -86,14 +86,14 @@ void init_sysdep(void) {
        init_ssl();
 #endif
 
-       /*
-        * Set up a place to put thread-specific data.
-        * We only need a single pointer per thread - it points to the
-        * CitContext structure (in the ContextList linked list) of the
-        * session to which the calling thread is currently bound.
-        */
-       if (pthread_key_create(&MyConKey, NULL) != 0) {
+       if (pthread_key_create(&ThreadKey, NULL) != 0) {                        // TSD for threads
+               syslog(LOG_ERR, "pthread_key_create() : %m");
+               abort();
+       }
+       
+       if (pthread_key_create(&MyConKey, NULL) != 0) {                         // TSD for sessions
                syslog(LOG_CRIT, "sysdep: can't create TSD key: %m");
+               abort();
        }
 
        /*
index 4da15e6fb650a4985fa5b4161df92e17706f535a..b0856bf2277e50afd8d298f0e9fd4a4e19dc0d44 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Thread handling stuff for Citadel server
  *
- * Copyright (c) 1987-2015 by the citadel.org team
+ * Copyright (c) 1987-2019 by the citadel.org team
  *
  * This program is open source software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License, version 3.
 #include "context.h"
 #include "threads.h"
 
-
 int num_workers = 0;                           /* Current number of worker threads */
 int active_workers = 0;                                /* Number of ACTIVE worker threads */
 pthread_key_t ThreadKey;
 pthread_mutex_t Critters[MAX_SEMAPHORES];      /* Things needing locking */
 struct thread_tsd masterTSD;
 int server_shutting_down = 0;                  /* set to nonzero during shutdown */
-
-pthread_mutex_t ThreadCountMutex;;
-
+pthread_mutex_t ThreadCountMutex;
 
 void InitializeSemaphores(void)
 {
@@ -45,8 +42,6 @@ void InitializeSemaphores(void)
 }
 
 
-
-
 /*
  * Obtain a semaphore lock to begin a critical section.
  * but only if no one else has one
@@ -83,6 +78,7 @@ void begin_critical_section(int which_one)
        pthread_mutex_lock(&Critters[which_one]);
 }
 
+
 /*
  * Release a semaphore lock to end a critical section.
  */
@@ -92,18 +88,18 @@ void end_critical_section(int which_one)
 }
 
 
-
-
 /*
  * Return a pointer to our thread-specific (not session-specific) data.
  */ 
 struct thread_tsd *MyThread(void) {
-        register struct thread_tsd *c;
-        return ((c = (struct thread_tsd *) pthread_getspecific(ThreadKey), c == NULL) ? &masterTSD : c);
+        struct thread_tsd *c = (struct thread_tsd *) pthread_getspecific(ThreadKey) ;
+       if (!c) {
+               return &masterTSD;
+       }
+       return c;
 }
 
 
-
 /* 
  * Called by CtdlThreadCreate()
  * We have to pass through here before starting our thread in order to create a set of data
@@ -119,8 +115,7 @@ void *CTC_backend(void *supplied_start_routine)
        pthread_setspecific(ThreadKey, (const void *) mytsd);
 
        start_routine(NULL);
-
-//     free(mytsd);
+       // free(mytsd);
        return(NULL);
 }
 
@@ -134,7 +129,6 @@ void CtdlThreadCreate(void *(*start_routine)(void*))
        pthread_attr_t attr;
        int ret = 0;
 
-
        ret = pthread_attr_init(&attr);
        ret = pthread_attr_setstacksize(&attr, THREADSTACKSIZE);
        ret = pthread_create(&thread, &attr, CTC_backend, (void *)start_routine);
@@ -143,6 +137,7 @@ void CtdlThreadCreate(void *(*start_routine)(void*))
 
 
 void InitializeMasterTSD(void) {
+       TRACE;
        memset(&masterTSD, 0, sizeof(struct thread_tsd));
 }
 
@@ -152,11 +147,6 @@ void InitializeMasterTSD(void) {
  */
 void go_threading(void)
 {
-       if (pthread_key_create(&ThreadKey, NULL) != 0) {
-               syslog(LOG_ERR, "pthread_key_create() : %m");
-               abort();
-       }
-
        pthread_mutex_init(&ThreadCountMutex, NULL);
 
        /* Second call to module init functions now that threading is up */
index 21e790530e90c63d7ed54aa29fc0bfdf3a05c7b4..5540d27a83568efd99076ab21c8cbcc7eaaa46e8 100644 (file)
@@ -24,6 +24,7 @@ struct thread_tsd {
        DBC *cursors[MAXCDB];   /* Cursors, for traversals... */
 };
 
+pthread_key_t ThreadKey;
 extern struct thread_tsd masterTSD;
 #define TSD MyThread()
 
index b9a357db90aa3182a3a6a69dc5adf057e174610a..f8c74445d9a89bd3ed4068042bb511fe6b85fd1c 100644 (file)
@@ -1180,10 +1180,9 @@ void ForEachUser(void (*CallBack) (char *, void *out_data), void *in_data)
 
        // Phase 2 : perform the callback for each username
        for (i=0; i<num_users; ++i) {
-               syslog(LOG_DEBUG, "user_ops: %3d %3d %s", i, usernames[i].version, usernames[i].username);      // FIXME
-               if (usernames[i].version < 927) {
-                       // FIXME we have to reindex this record
-               }
+               //if (usernames[i].version < 927) {
+                       // FIXME This is where we will do the reindexing stuff
+               //}
                (*CallBack) (usernames[i].username, in_data);
        }