diff options
author | Simon Rettberg | 2020-07-21 16:44:45 +0200 |
---|---|---|
committer | Simon Rettberg | 2020-07-21 16:44:45 +0200 |
commit | d6cd84358f729fbd01579605e4f325c737728ba1 (patch) | |
tree | f98f7e96952a797bb83942584a3577a7d853073f /src/fuse/main.c | |
parent | [FUSE] Formatting (diff) | |
download | dnbd3-d6cd84358f729fbd01579605e4f325c737728ba1.tar.gz dnbd3-d6cd84358f729fbd01579605e4f325c737728ba1.tar.xz dnbd3-d6cd84358f729fbd01579605e4f325c737728ba1.zip |
[FUSE] Properly signal worker threads to exit on shutdown
Our main signal handler sends SUGHUP to the receiver and background
threads, so if they block in some recv() or poll() they will get EINTR
and can check keepRunning.
Diffstat (limited to 'src/fuse/main.c')
-rw-r--r-- | src/fuse/main.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/fuse/main.c b/src/fuse/main.c index 295c194..3e08203 100644 --- a/src/fuse/main.c +++ b/src/fuse/main.c @@ -244,7 +244,6 @@ static void image_ll_read( fuse_req_t req, fuse_ino_t ino, size_t size, off_t of ++logInfo.blockRequestCount[startBlock]; } } - if ( !keepRunning ) connection_close(); if ( ino == 2 && size != 0 ) // with size == 0 there is nothing to do { dnbd3_async_t *request = malloc( sizeof(dnbd3_async_t) ); @@ -261,10 +260,12 @@ static void image_sigHandler( int signum ) { if ( signum == SIGINT && fuse_sigIntHandler != NULL ) { keepRunning = false; fuse_sigIntHandler( signum ); + connection_signalShutdown(); } if ( signum == SIGTERM && fuse_sigTermHandler != NULL ) { keepRunning = false; fuse_sigTermHandler( signum ); + connection_signalShutdown(); } errno = temp_errno; } @@ -494,8 +495,11 @@ int main( int argc, char *argv[] ) if ( fuse_set_signal_handlers( se ) != -1 ) { fuse_session_add_chan( se, ch ); //fuse_daemonize(foreground); - if ( single_thread ) fuse_err = fuse_session_loop( se ); - else fuse_err = fuse_session_loop_mt( se ); //MT produces errors (race conditions) in libfuse and didnt improve speed at all + if ( single_thread ) { + fuse_err = fuse_session_loop( se ); + } else { + fuse_err = fuse_session_loop_mt( se ); //MT produces errors (race conditions) in libfuse and didnt improve speed at all + } fuse_remove_signal_handlers( se ); fuse_session_remove_chan( ch ); } @@ -506,5 +510,6 @@ int main( int argc, char *argv[] ) fuse_opt_free_args( &args ); free( newArgv ); logadd( LOG_DEBUG1, "Terminating. FUSE REPLIED: %d\n", fuse_err ); + connection_join(); return fuse_err; } |