]> Savannah Git Hosting - gnulib.git/commitdiff
fatal-signal: Remove dependency upon xalloc.
authorBruno Haible <bruno@clisp.org>
Mon, 22 Mar 2021 01:50:07 +0000 (02:50 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 22 Mar 2021 01:50:07 +0000 (02:50 +0100)
* 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
NEWS
lib/clean-temp.c
lib/fatal-signal.c
lib/fatal-signal.h
lib/term-style-control.c
lib/wait-process.c
modules/clean-temp
modules/fatal-signal
modules/term-style-control
modules/wait-process

index faf7927f337a8858388657dcb6ba1826b6f68afe..14f80bdf56a1f84bd8d7ad8a586c5f77cc784369 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2021-03-21  Bruno Haible  <bruno@clisp.org>
+
+       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  <eggert@cs.ucla.edu>
 
        diacrit: remove
diff --git a/NEWS b/NEWS
index 77cf565ec994781221d8dee039eb7be92468e0c6..98931a345a745e7da603be3b9d8b8858c4d68717 100644 (file)
--- 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
index 885d5ab3493f83b2e3bd1dc3ad1b569e417057f7..268aa48208d0931c9a8d99549c05a659da6a59a2 100644 (file)
@@ -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.  */
index 15aa5229824aeef2e877b91fbec4f62230784c55..ba5fb53caadef9a6ff8e09d980ec9354361323bb 100644 (file)
@@ -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;
 }
 
 
index 3bcf8a9333f2fb6a5ece94ab2b564210e537c7c8..e8c69f1cb689f02502eddbd8712e07f45c670f32 100644 (file)
@@ -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
index 72099a3e95cf8ec2f7513f8d99c4d8182b67177e..d2d21331860ce48a74898e08fd30957ea3d3044e 100644 (file)
@@ -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
 
index 88a1eaa15a2cb9df7aa9ebbb2688595419c3413e..bbf5de2a05df71b104a4520ae935baa71325c338 100644 (file)
@@ -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;
     }
 
index 8551ce5f69c78e0440195d610ce61188b56a02ed..2eca0060a727206dbb409e9b9e4cee20574196b7 100644 (file)
@@ -21,6 +21,7 @@ tmpdir
 mkdtemp
 rmdir
 xalloc
+xalloc-die
 xmalloca
 linkedhash-list
 linked-list
index c56956c5758b05abeb0d7a9118c788dbb5c3b8f0..d3bb0991a3923f6b784fc4dd678694676735ec2d 100644 (file)
@@ -9,7 +9,6 @@ m4/sig_atomic_t.m4
 
 Depends-on:
 c99
-xalloc
 stdbool
 unistd
 sigaction
index a6fdd5ba3e85833f5b12b34f74186a0eed65f182..85d748d75e2677de703d8b5ff00cba9150d16e6f 100644 (file)
@@ -13,6 +13,7 @@ sigprocmask
 full-write
 fstat
 same-inode
+xalloc-die
 
 configure.ac:
 AC_REQUIRE([AC_C_INLINE])
index 7ffe8322ce7d618a52bc8dc42bcb0ee869864e95..f7271111e77c12a859dd2ef20618eb95f795667f 100644 (file)
@@ -11,6 +11,7 @@ Depends-on:
 fatal-signal
 error
 xalloc
+xalloc-die
 gettext-h
 stdbool
 stdlib