aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-03-29 03:59:20 -0500
committerRob Landley <rob@landley.net>2016-03-29 03:59:20 -0500
commit0e05569e308f927cd84882f7463739681bf1a33b (patch)
tree306bb0f70500028948256fe92d0e1db5f0968f36 /lib
parente223cca4f66bf2e201b21869304dc63befbbf9be (diff)
downloadtoybox-0e05569e308f927cd84882f7463739681bf1a33b.tar.gz
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.)
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c8
1 files changed, 4 insertions, 4 deletions
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));