Migrate psync_set_signal to psignal module
- Added psignal_set_custom_handler() to psignal.h and psignal.c - Replaced psync_set_signal() calls in pfs.c with psignal_set_custom_handler() - Centralizes all signal handling in psignal module
This commit is contained in:
parent
59c779d812
commit
c6826235bf
|
|
@ -3601,20 +3601,7 @@ static void psync_usr2_handler(int sig) {
|
|||
pdbg_reopen_log();
|
||||
}
|
||||
|
||||
static void psync_set_signal(int sig, void (*handler)(int)) {
|
||||
struct sigaction sa;
|
||||
|
||||
if (pdbg_unlikely(sigaction(sig, NULL, &sa)))
|
||||
return;
|
||||
|
||||
if (sa.sa_handler == SIG_DFL) {
|
||||
memset(&sa, 0, sizeof(struct sigaction));
|
||||
sigemptyset(&(sa.sa_mask));
|
||||
sa.sa_handler = handler;
|
||||
sa.sa_flags = 0;
|
||||
sigaction(sig, &sa, NULL);
|
||||
}
|
||||
}
|
||||
#include "psignal.h"
|
||||
|
||||
static void pfs_init_once() {
|
||||
#if pfs_need_per_folder_refresh_const()
|
||||
|
|
@ -3630,7 +3617,7 @@ static void pfs_init_once() {
|
|||
ppagecache_init();
|
||||
atexit(pfs_do_stop);
|
||||
pfs_debug_register_signal_handlers();
|
||||
psync_set_signal(SIGUSR2, psync_usr2_handler);
|
||||
psignal_set_custom_handler(SIGUSR2, psync_usr2_handler);
|
||||
pfs_stat_add_files();
|
||||
pfs_task_add_banned_folders();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,23 @@ static void sighup_handler(int sig) {
|
|||
sighup_flag = 1;
|
||||
}
|
||||
|
||||
void psignal_register(int signum) {
|
||||
void psignal_set_custom_handler(int sig, void (*handler)(int)) {
|
||||
struct sigaction sa;
|
||||
|
||||
if (sigaction(sig, NULL, &sa) != 0)
|
||||
return;
|
||||
|
||||
if (sa.sa_handler == SIG_DFL) {
|
||||
sa.sa_handler = handler;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = 0;
|
||||
if (sigaction(sig, &sa, NULL) != 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void psignal_register(int signum) {
|
||||
void (*handler)(int) = NULL;
|
||||
|
||||
if (signum == SIGINT) {
|
||||
|
|
@ -32,12 +47,7 @@ void psignal_register(int signum) {
|
|||
return;
|
||||
}
|
||||
|
||||
sa.sa_handler = handler;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = 0;
|
||||
if (sigaction(signum, &sa, NULL) != 0) {
|
||||
return;
|
||||
}
|
||||
psignal_set_custom_handler(signum, handler);
|
||||
}
|
||||
|
||||
int psignal_check_pending(void) {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ extern "C" {
|
|||
|
||||
void psignal_register(int signum);
|
||||
int psignal_check_pending(void);
|
||||
void psignal_set_custom_handler(int sig, void (*handler)(int));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue