Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 9af56407 authored by Rob Swindell's avatar Rob Swindell 💬

Track client counter per service again

Add the "two or three lines" that Deuce said were needed to restore this functionality.

Also got rid of some now unnecessary (void) protected_*int* return value ignoring warning-suppressors.
parent f6b13178
Pipeline #1378 passed with stage
in 10 minutes and 26 seconds
......@@ -81,7 +81,7 @@ typedef struct {
js_startup_t js;
js_server_props_t js_server_props;
/* These are run-time state and stat vars */
uint32_t clients;
protected_uint32_t clients;
ulong served;
struct xpms_set *set;
int running;
......@@ -105,7 +105,7 @@ typedef struct {
} service_client_t;
static service_t *service=NULL;
static uint32_t services=0;
static unsigned int services=0;
#if defined(__GNUC__) // Catch printf-format errors with lprintf
static int lprintf(int level, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
......@@ -177,7 +177,7 @@ static ulong active_clients(void)
ulong total_clients=0;
for(i=0;i<services;i++)
total_clients+=service[i].clients;
total_clients += protected_uint32_value(service[i].clients);
return(total_clients);
}
......@@ -604,7 +604,7 @@ js_client_add(JSContext *cx, uintN argc, jsval *arglist)
if((service_client=(service_client_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
service_client->service->clients++;
protected_uint32_adjust(&service_client->service->clients, 1);
update_clients();
service_client->service->served++;
served++;
......@@ -719,11 +719,11 @@ js_client_remove(JSContext *cx, uintN argc, jsval *arglist)
rc=JS_SUSPENDREQUEST(cx);
client_off(sock);
if(service_client->service->clients==0)
if(protected_uint32_value(service_client->service->clients) == 0)
lprintf(LOG_WARNING,"%s !client_remove() called with 0 service clients"
,service_client->service->protocol);
else {
service_client->service->clients--;
protected_uint32_adjust(&service_client->service->clients, -1);
update_clients();
}
JS_RESUMEREQUEST(cx, rc);
......@@ -821,7 +821,7 @@ js_initcx(JSRuntime* js_runtime, SOCKET sock, service_client_t* service_client,
,"Synchronet Services %s%c", VERSION, REVISION);
service_client->service->js_server_props.version_detail=
services_ver();
service_client->service->js_server_props.clients=0; // TODO: &service_client->service->clients
service_client->service->js_server_props.clients = &service_client->service->clients;
service_client->service->js_server_props.interfaces=
&service_client->service->interfaces;
service_client->service->js_server_props.options=
......@@ -953,8 +953,7 @@ static BOOL handle_crypt_call(int status, service_client_t *service_client, cons
static void js_service_failure_cleanup(service_t *service, SOCKET socket)
{
close_socket(socket);
if(service->clients)
service->clients--;
protected_uint32_adjust(&service->clients, -1);
thread_down();
return;
}
......@@ -992,7 +991,7 @@ static void js_service_thread(void* arg)
SetThreadName("sbbs/jsService");
thread_up(TRUE /* setuid */);
sbbs_srand(); /* Seed random number generator */
(void)protected_uint32_adjust(&threads_pending_start, -1);
protected_uint32_adjust(&threads_pending_start, -1);
inet_addrtop(&service_client.addr, client.addr, sizeof(client.addr));
......@@ -1011,8 +1010,7 @@ static void js_service_thread(void* arg)
lprintf(LOG_NOTICE,"%04d %s !CLIENT BLOCKED in host.can: %s"
,socket, service->protocol, host_name);
close_socket(socket);
if(service->clients)
service->clients--;
protected_uint32_adjust(&service->clients, -1);
thread_down();
return;
}
......@@ -1092,8 +1090,7 @@ static void js_service_thread(void* arg)
cryptDestroySession(service_client.tls_sess);
client_off(socket);
close_socket(socket);
if(service->clients)
service->clients--;
protected_uint32_adjust(&service->clients, -1);
thread_down();
return;
}
......@@ -1162,8 +1159,7 @@ static void js_service_thread(void* arg)
}
FREE_AND_NULL(service_client.subscan);
if(service->clients)
service->clients--;
protected_uint32_adjust(&service->clients, -1);
update_clients();
#ifdef _WIN32
......@@ -1206,7 +1202,7 @@ static void js_static_service_thread(void* arg)
SetThreadName("sbbs/jsStatic");
thread_up(TRUE /* setuid */);
sbbs_srand(); /* Seed random number generator */
(void)protected_uint32_adjust(&threads_pending_start, -1);
protected_uint32_adjust(&threads_pending_start, -1);
memset(&service_client,0,sizeof(service_client));
service_client.set = service->set;
......@@ -1271,11 +1267,10 @@ static void js_static_service_thread(void* arg)
jsrt_Release(js_runtime);
if(service->clients) {
if(protected_uint32_value(service->clients)) {
if(service->log_level >= LOG_WARNING)
lprintf(LOG_WARNING,"%s !service terminating with %u active clients"
, service->protocol, service->clients);
service->clients=0;
, service->protocol, protected_uint32_value(service->clients));
}
thread_down();
......@@ -1311,7 +1306,7 @@ static void native_static_service_thread(void* arg)
SetThreadName("sbbs/static");
thread_up(TRUE /* setuid */);
(void)protected_uint32_adjust(&threads_pending_start, -1);
protected_uint32_adjust(&threads_pending_start, -1);
#ifdef _WIN32
if(!DuplicateHandle(GetCurrentProcess(),
......@@ -1376,7 +1371,7 @@ static void native_service_thread(void* arg)
SetThreadName("sbbs/native");
thread_up(TRUE /* setuid */);
(void)protected_uint32_adjust(&threads_pending_start, -1);
protected_uint32_adjust(&threads_pending_start, -1);
inet_addrtop(&service_client.addr, client.addr, sizeof(client.addr));
......@@ -1400,8 +1395,7 @@ static void native_service_thread(void* arg)
lprintf(LOG_NOTICE,"%04d %s !CLIENT BLOCKED in host.can: %s"
,socket, service->protocol, host_name);
close_socket(socket);
if(service->clients)
service->clients--;
protected_uint32_adjust(&service->clients, -1);
thread_down();
return;
}
......@@ -1469,8 +1463,7 @@ static void native_service_thread(void* arg)
system(fullcmd);
if(service->clients)
service->clients--;
protected_uint32_adjust(&service->clients, -1);
update_clients();
#ifdef _WIN32
......@@ -1624,7 +1617,10 @@ static void cleanup(int code)
lprintf(LOG_NOTICE,"0000 Services cleanup waiting on %d threads pending start",protected_uint32_value(threads_pending_start));
SLEEP(1000);
}
(void)protected_uint32_destroy(threads_pending_start);
protected_uint32_destroy(threads_pending_start);
for(unsigned i = 0; i < services; i++)
protected_uint32_destroy(service[i].clients);
FREE_AND_NULL(service);
services=0;
......@@ -1785,7 +1781,7 @@ void DLLCALL services_thread(void* arg)
lprintf(LOG_INFO,"Compiled %s/%s %s %s with %s", git_branch, git_hash, __DATE__, __TIME__, compiler);
(void)protected_uint32_init(&threads_pending_start,0);
protected_uint32_init(&threads_pending_start,0);
if(!winsock_startup()) {
cleanup(1);
......@@ -1837,6 +1833,9 @@ void DLLCALL services_thread(void* arg)
return;
}
for(i=0; i < (int)services; i++)
protected_uint32_init(&service[i].clients, 0);
update_clients();
/* Open and Bind Listening Sockets */
......@@ -1892,13 +1891,13 @@ void DLLCALL services_thread(void* arg)
if(inst) {
inst->socket=service[i].set->socks[j].sock;
inst->service=&service[i];
(void)protected_uint32_adjust(&threads_pending_start, 1);
protected_uint32_adjust(&threads_pending_start, 1);
_beginthread(native_static_service_thread, service[i].stack_size, inst);
}
}
}
else { /* JavaScript */
(void)protected_uint32_adjust(&threads_pending_start, 1);
protected_uint32_adjust(&threads_pending_start, 1);
_beginthread(js_static_service_thread, service[i].stack_size, &service[i]);
}
}
......@@ -1968,7 +1967,7 @@ void DLLCALL services_thread(void* arg)
if(service[i].set==NULL)
continue;
if(!(service[i].options&SERVICE_OPT_FULL_ACCEPT)
&& service[i].max_clients && service[i].clients >= service[i].max_clients)
&& service[i].max_clients && protected_uint32_value(service[i].clients) >= service[i].max_clients)
continue;
for(j=0; j<service[i].set->sock_count; j++) {
FD_SET(service[i].set->socks[j].sock,&socket_set);
......@@ -2119,7 +2118,7 @@ void DLLCALL services_thread(void* arg)
,client_socket
,service[i].protocol, host_ip, inet_addrport(&client_addr));
if(service[i].max_clients && service[i].clients+1>service[i].max_clients) {
if(service[i].max_clients && protected_uint32_value(service[i].clients) + 1 > service[i].max_clients) {
lprintf(LOG_WARNING,"%04d %s !MAXIMUM CLIENTS (%u) reached, access denied"
,client_socket, service[i].protocol, service[i].max_clients);
close_socket(client_socket);
......@@ -2159,7 +2158,7 @@ void DLLCALL services_thread(void* arg)
client->socket=client_socket;
client->addr=client_addr;
client->service=&service[i];
client->service->clients++; /* this should be mutually exclusive */
protected_uint32_adjust(&client->service->clients, 1);
client->udp_buf=udp_buf;
client->udp_len=udp_len;
client->callback.limit = service[i].js.time_limit;
......@@ -2170,7 +2169,7 @@ void DLLCALL services_thread(void* arg)
udp_buf = NULL;
(void)protected_uint32_adjust(&threads_pending_start, 1);
protected_uint32_adjust(&threads_pending_start, 1);
if(service[i].options&SERVICE_OPT_NATIVE) /* Native */
_beginthread(native_service_thread, service[i].stack_size, client);
else /* JavaScript */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment