From 09bdab61fb1d3cc8c54d5b4ed555c1ec2987a85c Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Mon, 12 May 2008 06:50:12 +0300 Subject: [PATCH] Refactor subprocess signal setup --- ChangeLog | 13 +++++++++ debian/changelog | 1 + dselect/method.cc | 26 +++--------------- lib/Makefile.am | 1 + lib/dpkg-priv.h | 5 ++++ lib/subproc.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++ src/help.c | 36 ++----------------------- 7 files changed, 93 insertions(+), 57 deletions(-) create mode 100644 lib/subproc.c diff --git a/ChangeLog b/ChangeLog index 4389f4fd..14c2286a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2008-05-12 Guillem Jover + + * dselect/method.cc: Include . Use setup_subproc_signals + and cu_subproc_signals instead of cu_restoresignals and duped code + in falliblesubprocess. + * lib/Makefile.am (libdpkg_a_SOURCES): Add 'subproc.c'. + * ib/dpkg-priv.h (setup_subproc_signals): New prototype. + (cu_subproc_signals): Likewise. + * src/help.c: Include and stop including . + (cu_restorescriptsignals, script_catchsignals): Move to ... + * lib/subproc.c (cu_subproc_signals, setup_subproc_signals): ... here. + New file. + 2008-05-12 Guillem Jover * lib/Makefile.am (libdpkg_a_SOURCES): Add 'dpkg-priv.h' and 'path.c'. diff --git a/debian/changelog b/debian/changelog index de1a44e0..970615aa 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,6 +3,7 @@ dpkg (1.15.0) UNRELEASED; urgency=low [ Guillem Jover ] * Do not suggest manually changing the alternative symlinks on update-alternative's verbose mode. Closes: #412487 + * Refactor subprocess signal setup. [ Raphael Hertzog ] * Enhance dpkg-shlibdeps's error message when a library can't be found to diff --git a/dselect/method.cc b/dselect/method.cc index 0efcce3e..ee313f36 100644 --- a/dselect/method.cc +++ b/dselect/method.cc @@ -44,6 +44,7 @@ extern "C" { #include #include } +#include #include "dselect.h" #include "method.h" @@ -133,38 +134,17 @@ static enum urqresult lockmethod(void) { return urqr_normal; } -static int catchsignals[]= { SIGQUIT, SIGINT, 0 }; -#define NCATCHSIGNALS ((signed)(sizeof(catchsignals)/sizeof(int))-1) -static struct sigaction uncatchsignal[NCATCHSIGNALS]; - -void cu_restoresignals(int, void**) { - int i; - for (i=0; i + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2, + * or (at your option) any later version. + * + * This is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with dpkg; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include + +#include +#include +#include +#include + +#include +#include + +#define NCATCHSIGNALS (int)(sizeof(catch_signals) / sizeof(int) - 1) +static int catch_signals[] = { SIGQUIT, SIGINT, 0 }; +static struct sigaction uncatch_signals[NCATCHSIGNALS]; + +void +setup_subproc_signals(const char *name) +{ + int i; + struct sigaction catchsig; + + onerr_abort++; + memset(&catchsig, 0, sizeof(catchsig)); + catchsig.sa_handler = SIG_IGN; + sigemptyset(&catchsig.sa_mask); + catchsig.sa_flags = 0; + for (i = 0; i < NCATCHSIGNALS; i++) + if (sigaction(catch_signals[i], &catchsig, &uncatch_signals[i])) + ohshite(_("unable to ignore signal %s before running %.250s"), + strsignal(catch_signals[i]), name); + push_cleanup(cu_subproc_signals, ~0, NULL, 0, 0); + onerr_abort--; +} + +void +cu_subproc_signals(int argc, void **argv) +{ + int i; + + for (i = 0; i < NCATCHSIGNALS; i++) { + if (sigaction(catch_signals[i], &uncatch_signals[i], NULL)) { + fprintf(stderr, _("error un-catching signal %s: %s\n"), + strsignal(catch_signals[i]), strerror(errno)); + onerr_abort++; + } + } +} + diff --git a/src/help.c b/src/help.c index 81e9c516..1a9ea0f0 100644 --- a/src/help.c +++ b/src/help.c @@ -28,11 +28,11 @@ #include #include #include -#include #include #include #include +#include #include "filesdb.h" #include "main.h" @@ -193,38 +193,6 @@ static char *const *buildarglist(const char *scriptname, ...) { return arglist; } -#define NSCRIPTCATCHSIGNALS (int)(sizeof(script_catchsignallist)/sizeof(int)-1) -static int script_catchsignallist[]= { SIGQUIT, SIGINT, 0 }; -static struct sigaction script_uncatchsignal[NSCRIPTCATCHSIGNALS]; - -static void cu_restorescriptsignals(int argc, void **argv) { - int i; - for (i=0; i