#include <sys/select.h>
#endif
-#ifndef HAVE_SNPRINTF
-#include "snprintf.h"
-#endif
-
#include "ctdl_module.h"
#include "threads.h"
#include "user_ops.h"
void close_masters (void)
{
struct ServiceFunctionHook *serviceptr;
-
+ const char *Text;
+
/*
* close all protocol master sockets
*/
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);
CtdlDestroyCleanupHooks();
CtdlDestroyFixedOutputHooks();
CtdlDestroySessionHooks();
+ CtdlDestroyTDAPVetoHooks();
CtdlDestroyServiceHook();
CtdlDestroyRoomHooks();
CtdlDestroySearchHooks();
CitContext *con = NULL; /* Temporary context pointer */
int i;
+ pthread_mutex_lock(&ThreadCountMutex);
++num_workers;
+ pthread_mutex_unlock(&ThreadCountMutex);
while (!server_shutting_down) {
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);
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);
}