From 9ad38b46d9805cad071a4d7aaa370809eb2cee40 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 22 Mar 2021 02:50:07 +0100 Subject: [PATCH] fatal-signal: Remove dependency upon xalloc. * lib/fatal-signal.h (at_fatal_signal): Change return type to 'int'. * lib/fatal-signal.c: Don't include xalloc.h. (at_fatal_signal): Return an error indicator. * modules/fatal-signal (Depends-on): Remove xalloc. * NEWS: Mention the change. * lib/term-style-control.c: Include xalloc.h. (ensure_other_signal_handlers): Test return value of at_fatal_signal. * lib/clean-temp.c (do_init_clean_temp): Likewise. * lib/wait-process.c (register_slave_subprocess): Likewise. * modules/term-style-control (Depends-on): Add xalloc-die. * modules/clean-temp (Depends-on): Likewise. * modules/wait-process (Depends-on): Likewise. --- ChangeLog | 16 ++++++++++++++++ NEWS | 3 +++ lib/clean-temp.c | 3 ++- lib/fatal-signal.c | 18 ++++++++++++++---- lib/fatal-signal.h | 6 ++++-- lib/term-style-control.c | 4 +++- lib/wait-process.c | 3 ++- modules/clean-temp | 1 + modules/fatal-signal | 1 - modules/term-style-control | 1 + modules/wait-process | 1 + 11 files changed, 47 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index faf7927f33..14f80bdf56 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2021-03-21 Bruno Haible + + fatal-signal: Remove dependency upon xalloc. + * lib/fatal-signal.h (at_fatal_signal): Change return type to 'int'. + * lib/fatal-signal.c: Don't include xalloc.h. + (at_fatal_signal): Return an error indicator. + * modules/fatal-signal (Depends-on): Remove xalloc. + * NEWS: Mention the change. + * lib/term-style-control.c: Include xalloc.h. + (ensure_other_signal_handlers): Test return value of at_fatal_signal. + * lib/clean-temp.c (do_init_clean_temp): Likewise. + * lib/wait-process.c (register_slave_subprocess): Likewise. + * modules/term-style-control (Depends-on): Add xalloc-die. + * modules/clean-temp (Depends-on): Likewise. + * modules/wait-process (Depends-on): Likewise. + 2021-03-21 Paul Eggert diacrit: remove diff --git a/NEWS b/NEWS index 77cf565ec9..98931a345a 100644 --- a/NEWS +++ b/NEWS @@ -60,6 +60,9 @@ User visible incompatible changes Date Modules Changes +2021-03-21 fatal-signal The function at_fatal_signal now returns an error + indicator. + 2021-03-21 diacrit This deprecated module is removed. 2021-03-07 mbrtowc For single-locale optimizations, you now need to diff --git a/lib/clean-temp.c b/lib/clean-temp.c index 885d5ab349..268aa48208 100644 --- a/lib/clean-temp.c +++ b/lib/clean-temp.c @@ -385,7 +385,8 @@ do_init_clean_temp (void) /* Initialize the data used by the cleanup handler. */ init_fatal_signal_set (); /* Register the cleanup handler. */ - at_fatal_signal (&cleanup_action); + if (at_fatal_signal (&cleanup_action) < 0) + xalloc_die (); } /* Ensure that do_init_clean_temp is called once only. */ diff --git a/lib/fatal-signal.c b/lib/fatal-signal.c index 15aa522982..ba5fb53caa 100644 --- a/lib/fatal-signal.c +++ b/lib/fatal-signal.c @@ -29,7 +29,6 @@ #include "glthread/lock.h" #include "thread-optim.h" #include "sig-handler.h" -#include "xalloc.h" #define SIZEOF(a) (sizeof(a) / sizeof(a[0])) @@ -211,7 +210,7 @@ gl_lock_define_initialized (static, at_fatal_signal_lock) /* Register a cleanup function to be executed when a catchable fatal signal occurs. */ -void +int at_fatal_signal (action_t action) { bool mt = gl_multithreaded (); @@ -226,6 +225,8 @@ at_fatal_signal (action_t action) cleanup_initialized = true; } + int ret = 0; + if (actions_count == actions_allocated) { /* Extend the actions array. Note that we cannot use xrealloc(), @@ -235,9 +236,15 @@ at_fatal_signal (action_t action) size_t old_actions_allocated = actions_allocated; size_t new_actions_allocated = 2 * actions_allocated; actions_entry_t *new_actions = - XNMALLOC (new_actions_allocated, actions_entry_t); - size_t k; + (actions_entry_t *) + malloc (new_actions_allocated * sizeof (actions_entry_t)); + if (new_actions == NULL) + { + ret = -1; + goto done; + } + size_t k; /* Don't use memcpy() here, because memcpy takes non-volatile arguments and is therefore not guaranteed to complete all memory stores before the next statement. */ @@ -263,7 +270,10 @@ at_fatal_signal (action_t action) actions[actions_count].action = action; actions_count++; + done: if (mt) gl_lock_unlock (at_fatal_signal_lock); + + return ret; } diff --git a/lib/fatal-signal.h b/lib/fatal-signal.h index 3bcf8a9333..e8c69f1cb6 100644 --- a/lib/fatal-signal.h +++ b/lib/fatal-signal.h @@ -56,8 +56,10 @@ 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 (_GL_ASYNC_SAFE void (*function) (int sig)); + or not. + + Return 0 upon success, or -1 if there was a memory allocation problem. */ +extern int at_fatal_signal (_GL_ASYNC_SAFE void (*function) (int sig)); /* Sometimes it is necessary to block the usually fatal signals while the diff --git a/lib/term-style-control.c b/lib/term-style-control.c index 72099a3e95..d2d2133186 100644 --- a/lib/term-style-control.c +++ b/lib/term-style-control.c @@ -46,6 +46,7 @@ #include "sig-handler.h" #include "full-write.h" #include "same-inode.h" +#include "xalloc.h" #define SIZEOF(a) (sizeof(a) / sizeof(a[0])) @@ -813,7 +814,8 @@ ensure_other_signal_handlers (void) if (!signal_handlers_installed) { /* Install the handlers for the fatal signals. */ - at_fatal_signal (fatal_signal_handler); + if (at_fatal_signal (fatal_signal_handler) < 0) + xalloc_die (); #if defined SIGCONT diff --git a/lib/wait-process.c b/lib/wait-process.c index 88a1eaa15a..bbf5de2a05 100644 --- a/lib/wait-process.c +++ b/lib/wait-process.c @@ -121,7 +121,8 @@ register_slave_subprocess (pid_t child) if (!cleanup_slaves_registered) { atexit (cleanup_slaves); - at_fatal_signal (cleanup_slaves_action); + if (at_fatal_signal (cleanup_slaves_action) < 0) + xalloc_die (); cleanup_slaves_registered = true; } diff --git a/modules/clean-temp b/modules/clean-temp index 8551ce5f69..2eca0060a7 100644 --- a/modules/clean-temp +++ b/modules/clean-temp @@ -21,6 +21,7 @@ tmpdir mkdtemp rmdir xalloc +xalloc-die xmalloca linkedhash-list linked-list diff --git a/modules/fatal-signal b/modules/fatal-signal index c56956c575..d3bb0991a3 100644 --- a/modules/fatal-signal +++ b/modules/fatal-signal @@ -9,7 +9,6 @@ m4/sig_atomic_t.m4 Depends-on: c99 -xalloc stdbool unistd sigaction diff --git a/modules/term-style-control b/modules/term-style-control index a6fdd5ba3e..85d748d75e 100644 --- a/modules/term-style-control +++ b/modules/term-style-control @@ -13,6 +13,7 @@ sigprocmask full-write fstat same-inode +xalloc-die configure.ac: AC_REQUIRE([AC_C_INLINE]) diff --git a/modules/wait-process b/modules/wait-process index 7ffe8322ce..f7271111e7 100644 --- a/modules/wait-process +++ b/modules/wait-process @@ -11,6 +11,7 @@ Depends-on: fatal-signal error xalloc +xalloc-die gettext-h stdbool stdlib -- 2.39.5