From 19982b7b17a603bd4a0b47c724b4e830daaf88d9 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Wed, 16 Oct 2013 14:17:46 +0200 Subject: [PATCH] Kill children on fatal errors. If dss is about to die because it received SIGINT or SIGTERM, we first restart the rsync process by sending SIGCONT, then send SIGTERM to both the rsync and the rm process to get rid of any child processes. This works fine, but there are other fatal errors for which we miss to clean up as thoroughly, most importantly if there is not enough free disk space for a single snapshot. This patch moves the signal-related cleanup part to the new function kill_children(), and changes handle_signal() and com_run() to call this function right before the exit hook is invoked. --- dss.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/dss.c b/dss.c index 237208b..3a2f468 100644 --- a/dss.c +++ b/dss.c @@ -1038,6 +1038,13 @@ static int handle_sighup(void) return change_to_dest_dir(); } +static void kill_children(void) +{ + restart_create_process(); + dss_kill(create_pid, SIGTERM, NULL); + dss_kill(remove_pid, SIGTERM, NULL); +} + static int handle_signal(void) { int sig, ret = next_signal(); @@ -1048,9 +1055,7 @@ static int handle_signal(void) switch (sig) { case SIGINT: case SIGTERM: - restart_create_process(); - dss_kill(create_pid, SIGTERM, NULL); - dss_kill(remove_pid, SIGTERM, NULL); + kill_children(); ret = -E_SIGNAL; break; case SIGHUP: @@ -1319,6 +1324,7 @@ static int com_run(void) ret = select_loop(); if (ret >= 0) /* impossible */ ret = -E_BUG; + kill_children(); exit_hook(ret); return ret; } -- 2.39.2