+2008-05-12 Guillem Jover <guillem@debian.org>
+
+ * dselect/method.cc: Include <dpkg-priv.h>. 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 <dpkg-priv.h> and stop including <signal.h>.
+ (cu_restorescriptsignals, script_catchsignals): Move to ...
+ * lib/subproc.c (cu_subproc_signals, setup_subproc_signals): ... here.
+ New file.
+
2008-05-12 Guillem Jover <guillem@debian.org>
* lib/Makefile.am (libdpkg_a_SOURCES): Add 'dpkg-priv.h' and 'path.c'.
[ 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
#include <dpkg.h>
#include <dpkg-db.h>
}
+#include <dpkg-priv.h>
#include "dselect.h"
#include "method.h"
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<NCATCHSIGNALS; i++)
- if (sigaction(catchsignals[i],&uncatchsignal[i],0))
- fprintf(stderr,_("error un-catching signal %d: %s\n"),
- catchsignals[i],strerror(errno));
-}
-
urqresult falliblesubprocess(const char *exepath, const char *name,
const char *const *args) {
pid_t c1, cr;
int status, i, c;
- struct sigaction catchsig;
cursesoff();
- 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(catchsignals[i],&catchsig,&uncatchsignal[i]))
- ohshite(_("unable to ignore signal %d before running %.250s"),
- catchsignals[i], name);
- push_cleanup(cu_restoresignals,~0, 0,0, 0);
+ setup_subproc_signals(name);
if (!(c1= m_fork())) {
- cu_restoresignals(0,0);
+ cu_subproc_signals(0, 0);
execvp(exepath,(char* const*) args);
ohshite(_("unable to run %.250s process `%.250s'"),name,exepath);
}
parsedump.h \
path.c \
showpkg.c \
+ subproc.c \
tarfn.c tarfn.h \
triglib.c \
trigdeferred.l \
void rtrim_slash_slashdot(char *path);
+/* Subprocess handling. */
+
+void setup_subproc_signals(const char *name);
+void cu_subproc_signals(int argc, void **argv);
+
#ifdef __cplusplus
}
#endif
--- /dev/null
+/*
+ * libdpkg - Debian packaging suite library routines
+ * subproc.c - subprocess helper routines
+ *
+ * Copyright (C) 1995 Ian Jackson <ian@chiark.greenend.org.uk>
+ *
+ * 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 <config.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+
+#include <dpkg.h>
+#include <dpkg-priv.h>
+
+#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++;
+ }
+ }
+}
+
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
-#include <signal.h>
#include <time.h>
#include <dpkg.h>
#include <dpkg-db.h>
+#include <dpkg-priv.h>
#include "filesdb.h"
#include "main.h"
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<NSCRIPTCATCHSIGNALS; i++) {
- if (sigaction(script_catchsignallist[i], &script_uncatchsignal[i], NULL)) {
- fprintf(stderr,_("error un-catching signal %s: %s\n"),
- strsignal(script_catchsignallist[i]),strerror(errno));
- onerr_abort++;
- }
- }
-}
-
-static void script_catchsignals(void) {
- 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<NSCRIPTCATCHSIGNALS; i++)
- if (sigaction(script_catchsignallist[i],&catchsig,&script_uncatchsignal[i]))
- ohshite(_("unable to ignore signal %s before running script"),
- strsignal(script_catchsignallist[i]));
- push_cleanup(cu_restorescriptsignals, ~0, NULL, 0, 0);
- onerr_abort--;
-}
-
void
post_postinst_tasks(struct pkginfo *pkg, enum pkgstatus new_status)
{
execv(scriptexec,(char * const *)narglist);
ohshite(desc,name);
}
- script_catchsignals(); /* This does a push_cleanup() */
+ setup_subproc_signals(name); /* This does a push_cleanup() */
r= waitsubproc(c1,name,warn);
pop_cleanup(ehflag_normaltidy);