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 fae9acc0 authored by Rob Swindell's avatar Rob Swindell 💬

Use stdatomic for protected int's on Linux too (not just FreeBSD)

Deal with the resulting warnings (using (void)).
Deal with the incorrect integer to protected_int* assignment in services.c
(just don't support server.clients property reading in service scripts).

Also, the strcpy()->SAFECOPY() change in ftpsrvr.c was wrong, caught
by GCC warning - oops.
parent c26055da
Pipeline #1359 passed with stage
in 10 minutes and 13 seconds
......@@ -1527,7 +1527,7 @@ static void filexfer(union xp_sockaddr* addr, SOCKET ctrl_sock, CRYPT_SESSION ct
xfer->dir=dir;
xfer->desc=desc;
SAFECOPY(xfer->filename,filename);
protected_uint32_adjust(&thread_count,1);
(void)protected_uint32_adjust(&thread_count,1);
if(receiving)
result=_beginthread(receive_thread,0,(void*)xfer);
else
......@@ -1647,7 +1647,7 @@ static BOOL ftpalias(char* fullalias, char* filename, user_t* user, client_t* cl
sprintf(filename,"%s%s",scfg.dir[dir]->path,fname);
}
} else if(filename!=NULL)
SAFECOPY(filename,p);
strcpy(filename,p);
result=TRUE; /* success */
break;
......@@ -2397,7 +2397,7 @@ static void ctrl_thread(void* arg)
return;
}
protected_uint32_adjust(&active_clients, 1);
(void)protected_uint32_adjust(&active_clients, 1);
update_clients();
/* Initialize client display */
......@@ -5043,7 +5043,7 @@ static void cleanup(int code, int line)
if(protected_uint32_value(active_clients))
lprintf(LOG_WARNING,"!!!! Terminating with %d active clients", protected_uint32_value(active_clients));
else
protected_uint32_destroy(active_clients);
(void)protected_uint32_destroy(active_clients);
#ifdef _WINSOCKAPI_
if(WSAInitialized && WSACleanup()!=0)
......@@ -5125,11 +5125,11 @@ void DLLCALL ftp_server(void* arg)
startup->recycle_now=FALSE;
startup->shutdown_now=FALSE;
terminate_server=FALSE;
protected_uint32_init(&thread_count, 0);
(void)protected_uint32_init(&thread_count, 0);
do {
listInit(&current_connections, LINK_LIST_MUTEX);
protected_uint32_init(&active_clients, 0);
(void)protected_uint32_init(&active_clients, 0);
/* Setup intelligent defaults */
if(startup->port==0) startup->port=IPPORT_FTP;
......@@ -5138,7 +5138,7 @@ void DLLCALL ftp_server(void* arg)
if(startup->sem_chk_freq==0) startup->sem_chk_freq=DEFAULT_SEM_CHK_FREQ; /* seconds */
if(startup->index_file_name[0]==0) SAFECOPY(startup->index_file_name,"00index");
protected_uint32_adjust(&thread_count,1);
(void)protected_uint32_adjust(&thread_count,1);
thread_up(FALSE /* setuid */);
status("Initializing");
......@@ -5346,7 +5346,7 @@ void DLLCALL ftp_server(void* arg)
memcpy(&ftp->client_addr, &client_addr, client_addr_len);
ftp->client_addr_len = client_addr_len;
protected_uint32_adjust(&thread_count,1);
(void)protected_uint32_adjust(&thread_count,1);
_beginthread(ctrl_thread, 0, ftp);
served++;
}
......@@ -5380,5 +5380,5 @@ void DLLCALL ftp_server(void* arg)
} while(!terminate_server);
protected_uint32_destroy(thread_count);
(void)protected_uint32_destroy(thread_count);
}
......@@ -1154,7 +1154,7 @@ static void pop3_thread(void* arg)
return;
}
protected_uint32_adjust(&active_clients, 1);
(void)protected_uint32_adjust(&active_clients, 1);
update_clients();
/* Initialize client display */
......@@ -1753,7 +1753,7 @@ static void pop3_thread(void* arg)
smb_close(&smb);
listRemoveTaggedNode(&current_logins, socket, /* free_data */TRUE);
protected_uint32_adjust(&active_clients, -1);
(void)protected_uint32_adjust(&active_clients, -1);
update_clients();
client_off(socket);
......@@ -3045,7 +3045,7 @@ static void smtp_thread(void* arg)
getnameinfo(&smtp.client_addr.addr, smtp.client_addr_len, host_name, sizeof(host_name), NULL, 0, NI_NAMEREQD);
lprintf(LOG_INFO,"%04d %s %s Hostname: %s", socket, client.protocol, client_id, host_name);
}
protected_uint32_adjust(&active_clients, 1);
(void)protected_uint32_adjust(&active_clients, 1);
update_clients();
SAFECOPY(hello_name,host_name);
......@@ -3065,7 +3065,7 @@ static void smtp_thread(void* arg)
,socket, client.protocol, host_ip, attempted.count-attempted.dupes, attempted.user, seconds_to_str(banned, ban_duration));
mail_close_socket(&socket, &session);
thread_down();
protected_uint32_adjust(&active_clients, -1);
(void)protected_uint32_adjust(&active_clients, -1);
update_clients();
free(mailproc_to_match);
return;
......@@ -3079,7 +3079,7 @@ static void smtp_thread(void* arg)
sockprintf(socket,client.protocol,session,"550 CLIENT IP ADDRESS BLOCKED: %s", host_ip);
mail_close_socket(&socket, &session);
thread_down();
protected_uint32_adjust(&active_clients, -1);
(void)protected_uint32_adjust(&active_clients, -1);
update_clients();
free(mailproc_to_match);
return;
......@@ -3091,7 +3091,7 @@ static void smtp_thread(void* arg)
sockprintf(socket,client.protocol,session,"550 CLIENT HOSTNAME BLOCKED: %s", host_name);
mail_close_socket(&socket, &session);
thread_down();
protected_uint32_adjust(&active_clients, -1);
(void)protected_uint32_adjust(&active_clients, -1);
update_clients();
free(mailproc_to_match);
return;
......@@ -3112,7 +3112,7 @@ static void smtp_thread(void* arg)
lprintf(LOG_NOTICE,"%04d %s !REFUSED SESSION from blacklisted server (%lu total)"
,socket, client.protocol, ++stats.sessions_refused);
thread_down();
protected_uint32_adjust(&active_clients, -1);
(void)protected_uint32_adjust(&active_clients, -1);
update_clients();
free(mailproc_to_match);
return;
......@@ -3127,7 +3127,7 @@ static void smtp_thread(void* arg)
sockprintf(socket,client.protocol,session, smtp_error, "mail base locked");
mail_close_socket(&socket, &session);
thread_down();
protected_uint32_adjust(&active_clients, -1);
(void)protected_uint32_adjust(&active_clients, -1);
update_clients();
free(mailproc_to_match);
return;
......@@ -3151,7 +3151,7 @@ static void smtp_thread(void* arg)
sockprintf(socket,client.protocol,session,smtp_error, "fopen error");
mail_close_socket(&socket, &session);
thread_down();
protected_uint32_adjust(&active_clients, -1);
(void)protected_uint32_adjust(&active_clients, -1);
update_clients();
free(mailproc_to_match);
return;
......@@ -5013,7 +5013,7 @@ static void smtp_thread(void* arg)
status(STATUS_WFC);
listRemoveTaggedNode(&current_logins, socket, /* free_data */TRUE);
protected_uint32_adjust(&active_clients, -1);
(void)protected_uint32_adjust(&active_clients, -1);
update_clients();
client_off(socket);
......@@ -5915,7 +5915,7 @@ static void cleanup(int code)
if(protected_uint32_value(active_clients))
lprintf(LOG_WARNING,"!!!! Terminating with %d active clients", protected_uint32_value(active_clients));
else
protected_uint32_destroy(active_clients);
(void)protected_uint32_destroy(active_clients);
#ifdef _WINSOCKAPI_
if(WSAInitialized && WSACleanup()!=0)
......@@ -6032,12 +6032,12 @@ void DLLCALL mail_server(void* arg)
terminate_server=FALSE;
SetThreadName("sbbs/mailServer");
protected_uint32_init(&thread_count, 0);
(void)protected_uint32_init(&thread_count, 0);
do {
listInit(&current_logins, LINK_LIST_MUTEX);
listInit(&current_connections, LINK_LIST_MUTEX);
protected_uint32_init(&active_clients, 0);
(void)protected_uint32_init(&active_clients, 0);
/* Setup intelligent defaults */
if(startup->relay_port==0) startup->relay_port=IPPORT_SMTP;
......@@ -6052,7 +6052,7 @@ void DLLCALL mail_server(void* arg)
if(startup->sem_chk_freq==0) startup->sem_chk_freq=DEFAULT_SEM_CHK_FREQ;
if(startup->js.max_bytes==0) startup->js.max_bytes=JAVASCRIPT_MAX_BYTES;
protected_uint32_adjust(&thread_count,1);
(void)protected_uint32_adjust(&thread_count,1);
thread_up(FALSE /* setuid */);
status("Initializing");
......@@ -6211,7 +6211,7 @@ void DLLCALL mail_server(void* arg)
if(!(startup->options&MAIL_OPT_NO_SENDMAIL)) {
sendmail_running=TRUE;
protected_uint32_adjust(&thread_count,1);
(void)protected_uint32_adjust(&thread_count,1);
_beginthread(sendmail_thread, 0, NULL);
}
......@@ -6328,7 +6328,7 @@ void DLLCALL mail_server(void* arg)
memcpy(&smtp->client_addr, &client_addr, client_addr_len);
smtp->client_addr_len=client_addr_len;
smtp->tls_port = (servprot == servprot_submissions);
protected_uint32_adjust(&thread_count,1);
(void)protected_uint32_adjust(&thread_count,1);
_beginthread(smtp_thread, 0, smtp);
stats.connections_served++;
}
......@@ -6346,7 +6346,7 @@ void DLLCALL mail_server(void* arg)
memcpy(&pop3->client_addr, &client_addr, client_addr_len);
pop3->client_addr_len=client_addr_len;
pop3->tls_port = (servprot == servprot_pop3s);
protected_uint32_adjust(&thread_count,1);
(void)protected_uint32_adjust(&thread_count,1);
_beginthread(pop3_thread, 0, pop3);
stats.connections_served++;
}
......@@ -6403,5 +6403,5 @@ void DLLCALL mail_server(void* arg)
} while(!terminate_server);
protected_uint32_destroy(thread_count);
(void)protected_uint32_destroy(thread_count);
}
......@@ -4992,8 +4992,8 @@ static void cleanup(int code)
listFree(&current_logins);
listFree(&current_connections);
protected_uint32_destroy(node_threads_running);
protected_uint32_destroy(ssh_sessions);
(void)protected_uint32_destroy(node_threads_running);
(void)protected_uint32_destroy(ssh_sessions);
status("Down");
thread_down();
......
......@@ -128,7 +128,7 @@ static void sendsmsg(struct sbbs_status_msg *msg)
sock = node->data;
client_off(*sock);
free(sock);
protected_uint32_adjust(&active_clients, -1);
(void)protected_uint32_adjust(&active_clients, -1);
update_clients();
}
listFree(&off_socks);
......@@ -477,7 +477,7 @@ void status_thread(void *arg)
return;
}
protected_uint32_init(&thread_count, 0);
(void)protected_uint32_init(&thread_count, 0);
pthread_once(&init_once, init_lists);
startup->status(startup->cbdata, "Initializing");
......@@ -505,7 +505,7 @@ void status_thread(void *arg)
if(startup->host_name[0]==0)
SAFECOPY(startup->host_name,scfg.sys_inetaddr);
prep_dir(scfg.ctrl_dir, scfg.temp_dir, sizeof(scfg.temp_dir));
protected_uint32_init(&active_clients, 0);
(void)protected_uint32_init(&active_clients, 0);
update_clients();
startup->thread_up(startup->cbdata, TRUE, TRUE);
......@@ -706,7 +706,7 @@ void status_thread(void *arg)
// Send current status
listUnlock(&status_sock);
client_on(*csock, &client, FALSE);
protected_uint32_adjust(&active_clients, 1);
(void)protected_uint32_adjust(&active_clients, 1);
update_clients();
}
else {
......@@ -737,8 +737,8 @@ void status_thread(void *arg)
listRemoveNode(&status_sock, node, FALSE);
}
listUnlock(&status_sock);
protected_uint32_destroy(thread_count);
protected_uint32_destroy(active_clients);
(void)protected_uint32_destroy(thread_count);
(void)protected_uint32_destroy(active_clients);
startup->thread_up(startup->cbdata, FALSE, FALSE);
startup->terminated(startup->cbdata, rc);
......
......@@ -821,8 +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=
&service_client->service->clients;
service_client->service->js_server_props.clients=0; // TODO: &service_client->service->clients
service_client->service->js_server_props.interfaces=
&service_client->service->interfaces;
service_client->service->js_server_props.options=
......@@ -993,7 +992,7 @@ static void js_service_thread(void* arg)
SetThreadName("sbbs/jsService");
thread_up(TRUE /* setuid */);
sbbs_srand(); /* Seed random number generator */
protected_uint32_adjust(&threads_pending_start, -1);
(void)protected_uint32_adjust(&threads_pending_start, -1);
inet_addrtop(&service_client.addr, client.addr, sizeof(client.addr));
......@@ -1207,7 +1206,7 @@ static void js_static_service_thread(void* arg)
SetThreadName("sbbs/jsStatic");
thread_up(TRUE /* setuid */);
sbbs_srand(); /* Seed random number generator */
protected_uint32_adjust(&threads_pending_start, -1);
(void)protected_uint32_adjust(&threads_pending_start, -1);
memset(&service_client,0,sizeof(service_client));
service_client.set = service->set;
......@@ -1312,7 +1311,7 @@ static void native_static_service_thread(void* arg)
SetThreadName("sbbs/static");
thread_up(TRUE /* setuid */);
protected_uint32_adjust(&threads_pending_start, -1);
(void)protected_uint32_adjust(&threads_pending_start, -1);
#ifdef _WIN32
if(!DuplicateHandle(GetCurrentProcess(),
......@@ -1377,7 +1376,7 @@ static void native_service_thread(void* arg)
SetThreadName("sbbs/native");
thread_up(TRUE /* setuid */);
protected_uint32_adjust(&threads_pending_start, -1);
(void)protected_uint32_adjust(&threads_pending_start, -1);
inet_addrtop(&service_client.addr, client.addr, sizeof(client.addr));
......@@ -1625,7 +1624,7 @@ 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);
}
protected_uint32_destroy(threads_pending_start);
(void)protected_uint32_destroy(threads_pending_start);
FREE_AND_NULL(service);
services=0;
......@@ -1786,7 +1785,7 @@ void DLLCALL services_thread(void* arg)
lprintf(LOG_INFO,"Compiled %s/%s %s %s with %s", git_branch, git_hash, __DATE__, __TIME__, compiler);
protected_uint32_init(&threads_pending_start,0);
(void)protected_uint32_init(&threads_pending_start,0);
if(!winsock_startup()) {
cleanup(1);
......@@ -1893,13 +1892,13 @@ void DLLCALL services_thread(void* arg)
if(inst) {
inst->socket=service[i].set->socks[j].sock;
inst->service=&service[i];
protected_uint32_adjust(&threads_pending_start, 1);
(void)protected_uint32_adjust(&threads_pending_start, 1);
_beginthread(native_static_service_thread, service[i].stack_size, inst);
}
}
}
else { /* JavaScript */
protected_uint32_adjust(&threads_pending_start, 1);
(void)protected_uint32_adjust(&threads_pending_start, 1);
_beginthread(js_static_service_thread, service[i].stack_size, &service[i]);
}
}
......@@ -2171,7 +2170,7 @@ void DLLCALL services_thread(void* arg)
udp_buf = NULL;
protected_uint32_adjust(&threads_pending_start, 1);
(void)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 */
......
......@@ -764,7 +764,7 @@ static void thread_up(BOOL setuid)
static void thread_down(void)
{
protected_uint32_adjust(&thread_count,-1);
(void)protected_uint32_adjust(&thread_count,-1);
if(startup!=NULL && startup->thread_up!=NULL)
startup->thread_up(startup->cbdata,FALSE, FALSE);
}
......@@ -6497,7 +6497,7 @@ void http_session_thread(void* arg)
/* Destroyed in this block (before all returns) */
sem_init(&session.output_thread_terminated,0,0);
protected_uint32_adjust(&thread_count,1);
(void)protected_uint32_adjust(&thread_count,1);
_beginthread(http_output_thread, 0, &session);
sbbs_srand(); /* Seed random number generator */
......@@ -6548,7 +6548,7 @@ void http_session_thread(void* arg)
return;
}
protected_uint32_adjust(&active_clients, 1);
(void)protected_uint32_adjust(&active_clients, 1);
update_clients();
SAFECOPY(session.username,unknown);
......@@ -6742,7 +6742,7 @@ static void cleanup(int code)
if(protected_uint32_value(active_clients))
lprintf(LOG_WARNING,"!!!! Terminating with %u active clients", protected_uint32_value(active_clients));
else
protected_uint32_destroy(active_clients);
(void)protected_uint32_destroy(active_clients);
#ifdef _WINSOCKAPI_
if(WSAInitialized && WSACleanup()!=0)
......@@ -6941,10 +6941,10 @@ void DLLCALL web_server(void* arg)
startup->recycle_now=FALSE;
startup->shutdown_now=FALSE;
terminate_server=FALSE;
protected_uint32_init(&thread_count, 0);
(void)protected_uint32_init(&thread_count, 0);
do {
protected_uint32_init(&active_clients,0);
(void)protected_uint32_init(&active_clients,0);
/* Setup intelligent defaults */
if(startup->port==0) startup->port=IPPORT_HTTP;
......@@ -6959,7 +6959,7 @@ void DLLCALL web_server(void* arg)
if(startup->js.max_bytes==0) startup->js.max_bytes=JAVASCRIPT_MAX_BYTES;
if(startup->ssjs_ext[0]==0) SAFECOPY(startup->ssjs_ext,".ssjs");
protected_uint32_adjust(&thread_count,1);
(void)protected_uint32_adjust(&thread_count,1);
thread_up(FALSE /* setuid */);
status("Initializing");
......@@ -7092,7 +7092,7 @@ void DLLCALL web_server(void* arg)
/* Start log thread */
/********************/
http_logging_thread_running=TRUE;
protected_uint32_adjust(&thread_count,1);
(void)protected_uint32_adjust(&thread_count,1);
_beginthread(http_logging_thread, 0, startup->logfile_base);
}
......@@ -7167,7 +7167,7 @@ void DLLCALL web_server(void* arg)
/* Destroyed in http_session_thread */
pthread_mutex_init(&session->struct_filled,NULL);
pthread_mutex_lock(&session->struct_filled);
protected_uint32_adjust(&thread_count,1);
(void)protected_uint32_adjust(&thread_count,1);
_beginthread(http_session_thread, 0, session);
}
......@@ -7279,5 +7279,5 @@ void DLLCALL web_server(void* arg)
} while(!terminate_server);
protected_uint32_destroy(thread_count);
(void)protected_uint32_destroy(thread_count);
}
......@@ -217,7 +217,7 @@ int DLLCALL pthread_mutex_destroy(pthread_mutex_t* mutex)
/* Protected (thread-safe) Integers (e.g. atomic/interlocked variables) */
/************************************************************************/
#ifndef __FreeBSD__
#ifndef __unix__
int DLLCALL protected_int32_init(protected_int32_t* prot, int32_t value)
{
prot->value = value;
......
......@@ -40,7 +40,7 @@
#include "gen_defs.h" /* HANDLE */
#include "wrapdll.h" /* DLLEXPORT and DLLCALL */
#ifdef __FreeBSD__
#ifdef __unix__
#include <stdbool.h>
#ifdef __cplusplus
#include <atomic>
......@@ -157,7 +157,7 @@ DLLEXPORT int DLLCALL pthread_once(pthread_once_t *oc, void (*init)(void));
/* working and being thread-safe on all platforms that support pthread */
/* mutexes. */
/************************************************************************/
#ifdef __FreeBSD__
#ifdef __unix__
#ifdef __cplusplus
typedef std::atomic<int32_t> protected_int32_t;
typedef std::atomic<uint32_t> protected_uint32_t;
......
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