Integrate psignal into main loop and remove conflicting handlers

- Added extern "C" linkage to psignal.h for C++ compatibility
- Integrated psignal_check_pending() into pclsync_lib.cpp main loop
- Integrated psignal_check_pending() into ptimer.c timer loop
- Removed conflicting signal handlers from pfs.c
This commit is contained in:
Levi Neely 2026-03-08 14:11:54 +01:00
parent 8f951a7056
commit 59c779d812
4 changed files with 23 additions and 9 deletions

View File

@ -3616,14 +3616,6 @@ static void psync_set_signal(int sig, void (*handler)(int)) {
}
}
static void psync_setup_signals() {
psync_set_signal(SIGTERM, psync_signal_handler);
psync_set_signal(SIGINT, psync_signal_handler);
psync_set_signal(SIGHUP, psync_signal_handler);
pfs_debug_register_signal_handlers();
psync_set_signal(SIGUSR2, psync_usr2_handler);
}
static void pfs_init_once() {
#if pfs_need_per_folder_refresh_const()
unsigned char rndbuff[16];
@ -3637,7 +3629,8 @@ static void pfs_init_once() {
pfs_task_init();
ppagecache_init();
atexit(pfs_do_stop);
psync_setup_signals();
pfs_debug_register_signal_handlers();
psync_set_signal(SIGUSR2, psync_usr2_handler);
pfs_stat_add_files();
pfs_task_add_banned_folders();
}

View File

@ -3,7 +3,15 @@
#include <signal.h>
#ifdef __cplusplus
extern "C" {
#endif
void psignal_register(int signum);
int psignal_check_pending(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -35,6 +35,7 @@
#include "prun.h"
#include "psys.h"
#include "ptimer.h"
#include "psignal.h"
/* Maximum timeout possible is TIMER_ARRAY_SIZE^TIMER_LEVELS seconds, in the
* worst case TIMER_LEVELS operations will be preformed for each timer to
@ -145,8 +146,15 @@ PSYNC_NOINLINE static void timer_process_timers(psync_list *timers) {
static void timer_thread() {
psync_list timers;
time_t lt;
int sig;
lt = __atomic_load_n(&psync_current_time, __ATOMIC_RELAXED);
while (psync_do_run) {
sig = psignal_check_pending();
if (sig) {
pdbg_logf(D_NOTICE, "received signal %d, shutting down", sig);
psync_do_run = 0;
break;
}
psync_list_init(&timers);
psys_sleep_milliseconds(1000);
__atomic_store_n(&psync_current_time, psys_time_seconds(), __ATOMIC_RELAXED);

View File

@ -50,6 +50,7 @@
#include "pclsync/pdbg.h"
#include "pclsync/psock.h"
#include "pclsync/plibs.h"
#include "pclsync/psignal.h"
#include "pclsync_lib.h"
@ -668,6 +669,10 @@ int clib::pclsync_lib::init() {
was_init_ = true;
psignal_register(SIGINT);
psignal_register(SIGTERM);
psignal_register(SIGHUP);
if (!get_mount().empty()) {
psync_set_string_setting("fsroot", get_mount().c_str());
}