[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Replacement for the sigs_to_ignore hack in timeout.c
From: |
Eric Blake |
Subject: |
Re: [PATCH] Replacement for the sigs_to_ignore hack in timeout.c |
Date: |
Mon, 13 Oct 2008 22:18:48 -0600 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.17) Gecko/20080914 Thunderbird/2.0.0.17 Mnenhy/0.7.5.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Eric Blake on 10/10/2008 7:15 AM:
>> I've wanted to get rid of "signal" uses for ages.
>> Are you interested in doing it?
>
> Yes, I'll tackle this.
Round 1: csplit. The use of signal here mirrors what Bruno's fatal-signal
module in gnulib provides, although the set of signals masked is
different. Which would you prefer, a patch that swaps over to
fatal-signal usage (leaving at least SIGPOLL and SIGALRM unprotected), or
this patch? I'm kind of leaning towards simplifying this file by using
fatal-signal, but had already written this, and wanted some feedback.
I think the SA_NODEFER | SA_RESETHAND combo is correct here; the handler
is for one-shot cleanup of temporary files, so we want the handler to be
reset to SIG_DFL on nested signal. POSIX requires that portable programs
request SA_NODEFER alongside SA_RESETHAND, but we also include the signal
in the block mask, so a nested signal won't fire until after the handler
completes. I think we are safe assuming that upon return from a signal
handler, a signal that is no longer blocked will fire.
$ git pull git://repo.or.cz/coreutils/ericb.git signal
- --
Don't work too hard, make some time for fun as well!
Eric Blake address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkj0HagACgkQ84KuGfSFAYDlqgCgjxLJHUN0KhgXmMEaejyBCgxm
sBEAnRFK4bdSrNxKpTvtR6KBQkBbcsCY
=PBR6
-----END PGP SIGNATURE-----
>From 8c6dca936672e76f67c09e669bca803e80d64ef7 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Mon, 13 Oct 2008 22:04:51 -0600
Subject: [PATCH] csplit: prefer sigaction over signal
* bootstrap.conf (gnulib_modules): Import sigaction.
* src/csplit.c (sigprocmask, siginterrupt) [SA_NOCLDSTOP]: Delete
workarounds.
(interrupt_handler, main): Drop use of signal. Rely on sigaction
to block fatal signal during cleanup, and to restore it to default
in case of nested signals.
Signed-off-by: Eric Blake <address@hidden>
---
bootstrap.conf | 2 +-
src/csplit.c | 30 ++++--------------------------
2 files changed, 5 insertions(+), 27 deletions(-)
diff --git a/bootstrap.conf b/bootstrap.conf
index b3eec48..6405955 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -84,7 +84,7 @@ gnulib_modules="
safe-read same
save-cwd savedir savewd
selinux-at
- settime sig2str ssize_t stat-macros
+ settime sig2str sigaction ssize_t stat-macros
stat-time stdbool stdlib-safer stpcpy
stpncpy
strftime
diff --git a/src/csplit.c b/src/csplit.c
index 55489c3..b50a650 100644
--- a/src/csplit.c
+++ b/src/csplit.c
@@ -34,17 +34,6 @@
#include "stdio--.h"
#include "xstrtol.h"
-/* Use SA_NOCLDSTOP as a proxy for whether the sigaction machinery is
- present. */
-#ifndef SA_NOCLDSTOP
-# define SA_NOCLDSTOP 0
-# define sigprocmask(How, Set, Oset) /* empty */
-# define sigset_t int
-# if ! HAVE_SIGINTERRUPT
-# define siginterrupt(sig, flag) /* empty */
-# endif
-#endif
-
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "csplit"
@@ -238,12 +227,10 @@ xalloc_die (void)
static void
interrupt_handler (int sig)
{
- if (! SA_NOCLDSTOP)
- signal (sig, SIG_IGN);
-
delete_all_files (true);
-
- signal (sig, SIG_DFL);
+ /* The signal has been reset to SIG_DFL, but blocked during this
+ handler. Force the default action of this signal once the
+ handler returns and the block is removed. */
raise (sig);
}
@@ -1421,7 +1408,6 @@ main (int argc, char **argv)
};
enum { nsigs = sizeof sig / sizeof sig[0] };
-#if SA_NOCLDSTOP
struct sigaction act;
sigemptyset (&caught_signals);
@@ -1434,19 +1420,11 @@ main (int argc, char **argv)
act.sa_handler = interrupt_handler;
act.sa_mask = caught_signals;
- act.sa_flags = 0;
+ act.sa_flags = SA_NODEFER | SA_RESETHAND;
for (i = 0; i < nsigs; i++)
if (sigismember (&caught_signals, sig[i]))
sigaction (sig[i], &act, NULL);
-#else
- for (i = 0; i < nsigs; i++)
- if (signal (sig[i], SIG_IGN) != SIG_IGN)
- {
- signal (sig[i], interrupt_handler);
- siginterrupt (sig[i], 1);
- }
-#endif
}
split_file ();
--
1.6.0.2
- Re: [PATCH] Replacement for the sigs_to_ignore hack in timeout.c, (continued)
- Re: [PATCH] Replacement for the sigs_to_ignore hack in timeout.c, Jim Meyering, 2008/10/11
- Re: [PATCH] Replacement for the sigs_to_ignore hack in timeout.c, Giuseppe Scrivano, 2008/10/11
- Re: [PATCH] Replacement for the sigs_to_ignore hack in timeout.c, Andreas Schwab, 2008/10/11
- Re: [PATCH] Replacement for the sigs_to_ignore hack in timeout.c, Giuseppe Scrivano, 2008/10/11
- Re: [PATCH] Replacement for the sigs_to_ignore hack in timeout.c, Andreas Schwab, 2008/10/11
- Re: [PATCH] Replacement for the sigs_to_ignore hack in timeout.c, Eric Blake, 2008/10/10
- Re: [PATCH] Replacement for the sigs_to_ignore hack in timeout.c,
Eric Blake <=
- Re: [PATCH] Replacement for the sigs_to_ignore hack in timeout.c, Jim Meyering, 2008/10/16
- Re: [PATCH] Replacement for the sigs_to_ignore hack in timeout.c, Eric Blake, 2008/10/16
- Re: [PATCH] Replacement for the sigs_to_ignore hack in timeout.c, Bruno Haible, 2008/10/18
- Re: [PATCH] Replacement for the sigs_to_ignore hack in timeout.c, Eric Blake, 2008/10/16
- Re: [PATCH] Replacement for the sigs_to_ignore hack in timeout.c, Jim Meyering, 2008/10/16
- Re: [PATCH] Replacement for the sigs_to_ignore hack in timeout.c, Bruno Haible, 2008/10/18
- Re: [PATCH] Replacement for the sigs_to_ignore hack in timeout.c, Paul Eggert, 2008/10/16
Re: [PATCH] Replacement for the sigs_to_ignore hack in timeout.c, Pádraig Brady, 2008/10/10