diff options
author | Bruno Haible <bruno@clisp.org> | 2019-03-16 22:56:21 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2019-03-16 22:56:21 +0100 |
commit | 3cd207e1d0fd2df81cb276ccb4bb04bab86ce9f0 (patch) | |
tree | 65bab37fb921841e6b22c228962e08dc9156bbad /lib | |
parent | eac483310026d1e242989fc8a306e3db5d63efee (diff) | |
download | gnulib-3cd207e1d0fd2df81cb276ccb4bb04bab86ce9f0.tar.gz |
fatal-signal: Pass the signal number to the action.
* lib/fatal-signal.h (at_fatal_signal): Change the signature.
* lib/fatal-signal.c (action_t): Take the signal number as parameter.
(fatal_signal_handler): Pass the signal number to the action.
* lib/clean-temp.c (cleanup_action): Renamed from cleanup. Take the
signal number as parameter.
(create_temp_dir): Update.
* lib/wait-process.c (cleanup_slaves_action): New function.
(register_slave_subprocess): Update at_fatal_signal invocation.
* NEWS: Mention the change.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/clean-temp.c | 4 | ||||
-rw-r--r-- | lib/fatal-signal.c | 4 | ||||
-rw-r--r-- | lib/fatal-signal.h | 2 | ||||
-rw-r--r-- | lib/wait-process.c | 10 |
4 files changed, 14 insertions, 6 deletions
diff --git a/lib/clean-temp.c b/lib/clean-temp.c index c8d9bb7c97..0cb4a7e406 100644 --- a/lib/clean-temp.c +++ b/lib/clean-temp.c @@ -181,7 +181,7 @@ string_hash (const void *x) /* The signal handler. It gets called asynchronously. */ static void -cleanup () +cleanup_action (int sig _GL_UNUSED) { size_t i; @@ -279,7 +279,7 @@ create_temp_dir (const char *prefix, const char *parentdir, if (old_allocated == 0) /* First use of this facility. Register the cleanup handler. */ - at_fatal_signal (&cleanup); + at_fatal_signal (&cleanup_action); else { /* Don't use memcpy() here, because memcpy takes non-volatile diff --git a/lib/fatal-signal.c b/lib/fatal-signal.c index 3bf43b087b..7f12f12c16 100644 --- a/lib/fatal-signal.c +++ b/lib/fatal-signal.c @@ -107,7 +107,7 @@ init_fatal_signals (void) /* ========================================================================= */ -typedef void (*action_t) (void); +typedef void (*action_t) (int sig); /* Type of an entry in the actions array. The 'action' field is accessed from within the fatal_signal_handler(), @@ -162,7 +162,7 @@ fatal_signal_handler (int sig) actions_count = n; action = actions[n].action; /* Execute the action. */ - action (); + action (sig); } /* Now execute the signal's default action. diff --git a/lib/fatal-signal.h b/lib/fatal-signal.h index 22680e7ca4..c7d8e35d62 100644 --- a/lib/fatal-signal.h +++ b/lib/fatal-signal.h @@ -51,7 +51,7 @@ extern "C" { The cleanup function is executed asynchronously. It is unspecified whether during its execution the catchable fatal signals are blocked or not. */ -extern void at_fatal_signal (void (*function) (void)); +extern void at_fatal_signal (void (*function) (int sig)); /* Sometimes it is necessary to block the usually fatal signals while the diff --git a/lib/wait-process.c b/lib/wait-process.c index 84c0e86b1f..b51e2447a0 100644 --- a/lib/wait-process.c +++ b/lib/wait-process.c @@ -102,6 +102,14 @@ cleanup_slaves (void) } } +/* The cleanup action, taking a signal argument. + It gets called asynchronously. */ +static void +cleanup_slaves_action (int sig _GL_UNUSED) +{ + cleanup_slaves (); +} + /* Register a subprocess as being a slave process. This means that the subprocess will be terminated when its creator receives a catchable fatal signal or exits normally. Registration ends when wait_subprocess() @@ -113,7 +121,7 @@ register_slave_subprocess (pid_t child) if (!cleanup_slaves_registered) { atexit (cleanup_slaves); - at_fatal_signal (cleanup_slaves); + at_fatal_signal (cleanup_slaves_action); cleanup_slaves_registered = true; } |