X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fsysdep.c;h=01e7e831d49ddcd5de11b260bac2e02e29c60acd;hb=3367e0fa984b3e5f61b2f75f07fc4e11f824bb73;hp=b59445a850996413b669ab93574c6b6990df29a0;hpb=aa7365c86de8e26e796d3aa3fd605c85d8c26220;p=citadel.git diff --git a/citadel/sysdep.c b/citadel/sysdep.c index b59445a85..01e7e831d 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -73,10 +73,6 @@ #include #endif -#ifndef HAVE_SNPRINTF -#include "snprintf.h" -#endif - #include "ctdl_module.h" #include "threads.h" #include "user_ops.h" @@ -912,7 +908,8 @@ int client_getln(char *buf, int bufsize) void close_masters (void) { struct ServiceFunctionHook *serviceptr; - + const char *Text; + /* * close all protocol master sockets */ @@ -921,18 +918,37 @@ void close_masters (void) if (serviceptr->tcp_port > 0) { - syslog(LOG_INFO, "Closing %d listener on port %d\n", + if (serviceptr->msock == -1) + Text = "not closing again"; + else + Text = "Closing"; + + syslog(LOG_INFO, "%s %d listener on port %d\n", + Text, serviceptr->msock, serviceptr->tcp_port); serviceptr->tcp_port = 0; } if (serviceptr->sockpath != NULL) - syslog(LOG_INFO, "Closing %d listener on '%s'\n", + { + if (serviceptr->msock == -1) + Text = "not closing again"; + else + Text = "Closing"; + + syslog(LOG_INFO, "%s %d listener on '%s'\n", + Text, serviceptr->msock, serviceptr->sockpath); + } + if (serviceptr->msock != -1) + { close(serviceptr->msock); + serviceptr->msock = -1; + } + /* If it's a Unix domain socket, remove the file. */ if (serviceptr->sockpath != NULL) { unlink(serviceptr->sockpath); @@ -1141,7 +1157,9 @@ void *worker_thread(void *blah) { CitContext *con = NULL; /* Temporary context pointer */ int i; + pthread_mutex_lock(&ThreadCountMutex); ++num_workers; + pthread_mutex_unlock(&ThreadCountMutex); while (!server_shutting_down) { @@ -1323,7 +1341,10 @@ do_select: force_purge = 0; SKIP_SELECT: /* We're bound to a session */ + pthread_mutex_lock(&ThreadCountMutex); ++active_workers; + pthread_mutex_unlock(&ThreadCountMutex); + if (bind_me != NULL) { become_session(bind_me); @@ -1357,11 +1378,23 @@ SKIP_SELECT: dead_session_purge(force_purge); do_housekeeping(); + + pthread_mutex_lock(&ThreadCountMutex); --active_workers; + if ((active_workers + config.c_min_workers < num_workers) && + (num_workers > config.c_min_workers)) + { + num_workers--; + pthread_mutex_unlock(&ThreadCountMutex); + return (NULL); + } + pthread_mutex_unlock(&ThreadCountMutex); } /* If control reaches this point, the server is shutting down */ + pthread_mutex_lock(&ThreadCountMutex); --num_workers; + pthread_mutex_unlock(&ThreadCountMutex); return(NULL); }