From c04f887249cd0e693b8262e5cd816978631f8e10 Mon Sep 17 00:00:00 2001 From: Levi Neely <141506390+lneely@users.noreply.github.com> Date: Wed, 26 Feb 2025 20:31:25 +0100 Subject: [PATCH] prevent multiple execution of psync_fs_do_stop, and use atexit in the signal handler (#91) --- pclsync/pfs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pclsync/pfs.c b/pclsync/pfs.c index 4bea57b..812b02b 100644 --- a/pclsync/pfs.c +++ b/pclsync/pfs.c @@ -104,6 +104,7 @@ typedef off_t fuse_off_t; #define PSYNC_FS_ERR_MOVE_ACROSS_CRYPTO EXDEV #endif +static int shutdown_in_progress = 0; static struct fuse_chan *psync_fuse_channel = NULL; static struct fuse *psync_fuse = NULL; static char *psync_current_mountpoint = NULL; @@ -3457,6 +3458,11 @@ static void psync_fs_dump_internals() { #endif static void psync_fs_do_stop(void) { + if (!__sync_bool_compare_and_swap(&shutdown_in_progress, 0, 1)) { + // prevent multiple executions + return; + } + debug(D_NOTICE, "stopping"); pthread_mutex_lock(&start_mutex); if (started == 1) { @@ -3521,8 +3527,7 @@ void psync_fs_stop() { psync_fs_do_stop(); } static void psync_signal_handler(int sig) { debug(D_NOTICE, "got signal %d", sig); - psync_fs_do_stop(); - exit(1); + exit(1); // invoke psync_do_stop via atexit() } #if IS_DEBUG