bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* fatal-signal: Add function that lists the fatal signals
@ 2019-03-16 16:56 Bruno Haible
  0 siblings, 0 replies; only message in thread
From: Bruno Haible @ 2019-03-16 16:56 UTC (permalink / raw)
  To: bug-gnulib

Some users of the 'fatal-signal' module want to block / unblock
not only the fatal signals, but also some other signals. Of course
a single sigaction() call is preferred to multiple ones. For this use-case,
it makes sense to add an accessor for the list of signals.

This accessor returns a list of signals, not a sigset_t, because it is not
clear to me, reading POSIX, whether cloning a sigset_t by simple assignment
is allowed. (Maybe POSIX allows a sigset_t to contain embedded pointers?)
Also, iterating through a list of 5 or 6 elements is probably more efficient
than iterating through a bitmap of 256 or 1024 bits.


2019-03-16  Bruno Haible  <bruno@clisp.org>

	fatal-signal: Add function that lists the fatal signals.
	* lib/fatal-signal.h (get_fatal_signals): New declaration.
	* lib/fatal-signal.c (get_fatal_signals): New function.

diff --git a/lib/fatal-signal.h b/lib/fatal-signal.h
index a2e60d3..22680e7 100644
--- a/lib/fatal-signal.h
+++ b/lib/fatal-signal.h
@@ -71,6 +71,12 @@ extern void block_fatal_signals (void);
 extern void unblock_fatal_signals (void);
 
 
+/* Return the list of signals that block_fatal_signals/unblock_fatal_signals
+   would block or unblock.
+   Fills signals[0..count-1] and returns count.  */
+extern unsigned int get_fatal_signals (int signals[64]);
+
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/fatal-signal.c b/lib/fatal-signal.c
index 1fe31d1..3bf43b0 100644
--- a/lib/fatal-signal.c
+++ b/lib/fatal-signal.c
@@ -284,3 +284,20 @@ unblock_fatal_signals (void)
   init_fatal_signal_set ();
   sigprocmask (SIG_UNBLOCK, &fatal_signal_set, NULL);
 }
+
+
+unsigned int
+get_fatal_signals (int signals[64])
+{
+  init_fatal_signal_set ();
+
+  {
+    int *p = signals;
+    size_t i;
+
+    for (i = 0; i < num_fatal_signals; i++)
+      if (fatal_signals[i] >= 0)
+        *p++ = fatal_signals[i];
+    return p - signals;
+  }
+}



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-03-16 17:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-16 16:56 fatal-signal: Add function that lists the fatal signals Bruno Haible

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).