[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
fatal-signal: Remove dependency upon xalloc
From: |
Bruno Haible |
Subject: |
fatal-signal: Remove dependency upon xalloc |
Date: |
Mon, 22 Mar 2021 02:53:50 +0100 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-203-generic; KDE/5.18.0; x86_64; ; ) |
I need to use the module 'clean-temp' and, with it, the module 'fatal-signal'
in a library under GPLv2+ (namely, GNU libffcall). To this effect, functions
in this module should not call xalloc_die() (since that is under GPLv3+)
but instead return an error indicator.
This patch is the first part of the change.
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.
diff --git a/NEWS b/NEWS
index 77cf565..98931a3 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 885d5ab..268aa48 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 15aa522..ba5fb53 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 3bcf8a9..e8c69f1 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 72099a3..d2d2133 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 88a1eaa..bbf5de2 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 8551ce5..2eca006 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 c56956c..d3bb099 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 a6fdd5b..85d748d 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 7ffe832..f727111 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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- fatal-signal: Remove dependency upon xalloc,
Bruno Haible <=