From d4070db6312c4b38980ad165732d6beaaa0c06b3 Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Sun, 26 May 2013 14:52:50 -0700 Subject: Avoid I/O via signal-handler thread. The cleanup code will try to flush the output buffer in some circumstances, which is not valid if we're handling an async signal (since it might have interrupted some partial I/O in the main thread). These signals now set a flag and try to let the main I/O handler take care of the exit strategy. Fixes a protocol error that could happen when trying to exit after a kill signal. --- cleanup.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'cleanup.c') diff --git a/cleanup.c b/cleanup.c index 9de6eab8..971154ce 100644 --- a/cleanup.c +++ b/cleanup.c @@ -34,6 +34,7 @@ extern char *partial_dir; extern char *logfile_name; BOOL shutting_down = False; +BOOL flush_ok_after_signal = False; #ifdef HAVE_SIGACTION static struct sigaction sigact; @@ -182,7 +183,12 @@ NORETURN void _exit_cleanup(int code, const char *file, int line) #include "case_N.h" switch_step++; - if (!code || am_server || am_receiver) + if (flush_ok_after_signal) { + flush_ok_after_signal = False; + if (code == RERR_SIGNAL) + io_flush(FULL_FLUSH); + } + if (!code) io_flush(FULL_FLUSH); /* FALLTHROUGH */ -- cgit v1.2.3