Skip to content
Snippets Groups Projects
Commit 9af56407 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

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