From 1dce9cf4eade59b9602a5f6e12fa5d91500b8e85 Mon Sep 17 00:00:00 2001 From: cha0smaster Date: Sat, 25 Jun 2005 16:37:50 +0000 Subject: [PATCH] NTFSCP: don't use printf inside signal handler. --- ntfsprogs/ntfscp.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/ntfsprogs/ntfscp.c b/ntfsprogs/ntfscp.c index bc37a116..76dd9f6a 100644 --- a/ntfsprogs/ntfscp.c +++ b/ntfsprogs/ntfscp.c @@ -54,7 +54,7 @@ struct options { static const char *EXEC_NAME = "ntfscp"; static struct options opts; -static int caught_terminate = 0; +volatile sig_atomic_t caught_terminate = 0; GEN_PRINTF (Eprintf, stderr, NULL, FALSE) GEN_PRINTF (Vprintf, stderr, &opts.verbose, TRUE) @@ -237,16 +237,9 @@ static int parse_options (int argc, char **argv) /** * signal_handler - Handle SIGINT and SIGTERM: abort write, sync and exit. */ -static void signal_handler(int arg) +static void signal_handler(int arg __attribute__((unused))) { caught_terminate++; - if (caught_terminate > 3) { - Eprintf("SIGTERM or SIGINT received more than 3 times. " - "Exit immediately.\n"); - exit(2); - } else - Eprintf("%s received. Aborting write.\n", - (arg == SIGINT) ? "SIGINT" : "SIGTERM"); } /** @@ -407,7 +400,11 @@ int main (int argc, char *argv[]) Vprintf("Starting write.\n"); offset = 0; - while (!feof(in) && !caught_terminate) { + while (!feof(in)) { + if (caught_terminate) { + printf("SIGTERM or SIGINT received. Aborting write.\n"); + break; + } br = fread(buf, 1, NTFS_BUF_SIZE, in); if (!br) { if (!feof(in)) perror("ERROR: fread failed");