From 073cdb2175b90f4950fb69a9c5004ad90412d0d0 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 15 Feb 2021 17:13:57 +1100 Subject: [PATCH] Delete broken files if application is interrupted unless the keep-broken option is enabled, and return 1 as exit code on interruption. --- main.c | 13 ++++--------- util.c | 7 +++++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/main.c b/main.c index 4987173..a554a1c 100644 --- a/main.c +++ b/main.c @@ -145,15 +145,10 @@ static void license(void) static void sighandler(int sig __UNUSED__) { - struct termios termios_p; - - /* Make sure we haven't died after disabling stdin echo */ - tcgetattr(fileno(stdin), &termios_p); - termios_p.c_lflag |= ECHO; - tcsetattr(fileno(stdin), 0, &termios_p); - - unlink_files(control); - exit(0); + signal(sig, SIG_IGN); + signal(SIGTERM, SIG_IGN); + print_err("Interrupted\n"); + fatal_exit(&local_control); } static void show_summary(void) diff --git a/util.c b/util.c index 94b5c5d..f6ef89d 100644 --- a/util.c +++ b/util.c @@ -100,6 +100,13 @@ void fatal_exit(rzip_control *control) tcsetattr(fileno(stdin), 0, &termios_p); unlink_files(control); + if (!STDOUT && !TEST_ONLY && control->outfile) { + if (!KEEP_BROKEN) { + print_verbose("Deleting broken file %s\n", control->outfile); + unlink(control->outfile); + } else + print_verbose("Keeping broken file %s as requested\n", control->outfile); + } fprintf(control->outputfile, "Fatal error - exiting\n"); fflush(control->outputfile); exit(1);