From 0e05569e308f927cd84882f7463739681bf1a33b Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 29 Mar 2016 03:59:20 -0500 Subject: Fix exit code of things like sed -i that use tempfile_handler(). (The sigatexit() handler list code now calls the handlers on the normal exit path, so _exit(1) from the handler is wrong; exit_signal() modifies toys.exitval if necessary.) --- lib/lib.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/lib.c') diff --git a/lib/lib.c b/lib/lib.c index 200f77d6..3ca7052a 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -618,10 +618,9 @@ int wfchmodat(int fd, char *name, mode_t mode) } static char *tempfile2zap; -static void tempfile_handler(int i) +static void tempfile_handler(void) { if (1 < (long)tempfile2zap) unlink(tempfile2zap); - _exit(1); } // Open a temporary file to copy an existing file into. @@ -759,12 +758,13 @@ void generic_signal(int sig) void exit_signal(int sig) { - toys.exitval = sig|128; + if (sig) toys.exitval = sig|128; xexit(); } // Install the same handler on every signal that defaults to killing the -// process, and +// process, calling the handler on the way out. Calling multiple times +// adds the handlers to a list, to be called in order. void sigatexit(void *handler) { struct arg_list *al = xmalloc(sizeof(struct arg_list)); -- cgit v1.2.3