Skip to content

Commit c88d4e2

Browse files
committed
cleanup: don't flush the write buffer from a signal handler
When SIGUSR1 aborts an --inplace/--append transfer, _exit_cleanup() runs inside the handler and flushes the receiver's write buffer. If the handler interrupted flush_write_file() after write() returned but before wf_writeBufCnt was updated, the same bytes are written a second time, and with --append the file keeps a duplicated 256 KiB region. Skip that flush when called from a signal handler. A SIGINT, SIGTERM or SIGHUP that reaches the receiver itself still exits from normal code through got_kill_signal, so its flush is unaffected.
1 parent 7998ccf commit c88d4e2

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎cleanup.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ NORETURN void _exit_cleanup(int code, const char *file, int line)
162162
cleanup_fd_r = -1;
163163
}
164164
if (cleanup_fd_w != -1) {
165-
flush_write_file(cleanup_fd_w);
165+
if (!called_from_signal_handler)
166+
flush_write_file(cleanup_fd_w);
166167
close(cleanup_fd_w);
167168
cleanup_fd_w = -1;
168169
}

0 commit comments

Comments
 (0)