]> code.citadel.org Git - citadel.git/blobdiff - citadel/sysdep.c
Fixed a bug in the threading code that would prevent new threads starting.
[citadel.git] / citadel / sysdep.c
index 1c681a87049cee1891105f942b12530c1f34eaeb..433f3467b1e8a659d566f168945917bbd174aa60 100644 (file)
@@ -171,18 +171,19 @@ void vCtdlLogPrintf(enum LogLevel loglevel, const char *format, va_list arg_ptr)
                struct timeval tv;
                struct tm tim;
                time_t unixtime;
+               struct CitContext *CCC = CC;
 
                gettimeofday(&tv, NULL);
                /* Promote to time_t; types differ on some OSes (like darwin) */
                unixtime = tv.tv_sec;
                localtime_r(&unixtime, &tim);
-               if (CC->cs_pid != 0) {
+               if ((CCC != NULL) && (CCC->cs_pid != 0)) {
                        sprintf(buf,
                                "%04d/%02d/%02d %2d:%02d:%02d.%06ld [%3d] ",
                                tim.tm_year + 1900, tim.tm_mon + 1,
                                tim.tm_mday, tim.tm_hour, tim.tm_min,
                                tim.tm_sec, (long)tv.tv_usec,
-                               CC->cs_pid);
+                               CCC->cs_pid);
                } else {
                        sprintf(buf,
                                "%04d/%02d/%02d %2d:%02d:%02d.%06ld ",
@@ -375,6 +376,9 @@ int ig_uds_server(char *sockpath, int queue_len, char **errormessage)
        int s;
        int i;
        int actual_queue_len;
+#ifdef HAVE_STRUCT_UCRED
+       int passcred = 1;
+#endif
 
        actual_queue_len = queue_len;
        if (actual_queue_len < 5) actual_queue_len = 5;
@@ -431,6 +435,10 @@ int ig_uds_server(char *sockpath, int queue_len, char **errormessage)
                return(-1);
        }
 
+#ifdef HAVE_STRUCT_UCRED
+       setsockopt(s, SOL_SOCKET, SO_PASSCRED, &passcred, sizeof(passcred));
+#endif
+
        chmod(sockpath, S_ISGID|S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH);
        return(s);
 }
@@ -542,7 +550,7 @@ void CtdlFillSystemContext(struct CitContext *context, char *name)
                context->user.usernum = get_new_user_number();
                CtdlLogPrintf(CTDL_DEBUG, "Upgrading system user \"%s\" from user number 0 to user number %d\n", context->user.fullname, context->user.usernum);
                /* add user to the database */
-               putuser(&(context->user));
+               CtdlPutUser(&(context->user));
                cdb_store(CDB_USERSBYNUMBER, &(context->user.usernum), sizeof(long), context->user.fullname, strlen(context->user.fullname)+1);
        }
 }
@@ -566,17 +574,19 @@ static unsigned on = 1, off = 0;
 
 void buffer_output(void) {
 #ifdef HAVE_TCP_BUFFERING
-       if (!CC->redirect_ssl) {
+#ifdef HAVE_OPENSSL
+       if (!CC->redirect_ssl)
+#endif
                setsockopt(CC->client_socket, IPPROTO_TCP, TCP_CORK, &on, 4);
-       }
 #endif
 }
 
 void unbuffer_output(void) {
 #ifdef HAVE_TCP_BUFFERING
-       if (!CC->redirect_ssl) {
+#ifdef HAVE_OPENSSL
+       if (!CC->redirect_ssl)
+#endif
                setsockopt(CC->client_socket, IPPROTO_TCP, TCP_CORK, &off, 4);
-       }
 #endif
 }
 
@@ -868,7 +878,6 @@ void sysdep_master_cleanup(void) {
        CtdlDestroySessionHooks();
        CtdlDestroyServiceHook();
        CtdlDestroyRoomHooks();
-       CtdlDestroyDirectoryServiceFuncs();
        #ifdef HAVE_BACKTRACE
        eCrash_Uninit();
        #endif
@@ -999,14 +1008,15 @@ void checkcrash(void)
                        " The Citadel server process (citserver) terminated unexpectedly."
                        "\n \n"
                        " This could be the result of a bug in the server program, or some external "
-                       "factor.  You can obtain more information about this by enabling core dumps. "
-                       "For more information, please see: "
-                       "http://citadel.org/doku.php/faq:mastering_your_os:gdb#how.do.i.make.my.system.produce.core-files"
+                       "factor.\n \n"
+                       " You can obtain more information about this by enabling core dumps.\n \n"
+                       " For more information, please see:\n \n"
+                       " http://citadel.org/doku.php/faq:mastering_your_os:gdb#how.do.i.make.my.system.produce.core-files"
                        "\n \n"
                        " If you have already done this, the core dump is likely to be found at %score.%d\n"
                        ,
                        ctdl_run_dir, ForkedPid);
-               aide_message(ChrPtr(CrashMail), "Citadel server process terminated unexpectedly");
+               CtdlAideMessage(ChrPtr(CrashMail), "Citadel server process terminated unexpectedly");
                FreeStrBuf(&CrashMail);
        }
 }
@@ -1113,6 +1123,9 @@ void InitializeMasterCC(void) {
  * Bind a thread to a context.  (It's inline merely to speed things up.)
  */
 INLINE void become_session(struct CitContext *which_con) {
+       if (which_con)
+               ctdl_thread_internal_change_state(CT, CTDL_THREAD_RUNNING);
+
        citthread_setspecific(MyConKey, (void *)which_con );
 }