[147224] trunk/base/src/pextlib1.0/system.c
raimue at macports.org
raimue at macports.org
Thu Mar 31 08:53:21 PDT 2016
Revision: 147224
https://trac.macports.org/changeset/147224
Author: raimue at macports.org
Date: 2016-03-31 08:53:21 -0700 (Thu, 31 Mar 2016)
Log Message:
-----------
pextlib/system: ignore signals SIGINT/SIGQUIT
When a SIGINT/SIGQUIT was generated by the user during execution of a program,
both the program and the waiting parent tclsh process got interrupted by
a signal. However, the handler in the tclsh only generated an unpleasant error
message that a SIGINT/SIGQUIT was received.
With this change, only the child will handle the signal, hopefully ending its
execution. If the program handles SIGINT/SIGQUIT, it might still just terminate
with a normal exit code, so there is no chance for us to determine that it was
killed by a signal.
Modified Paths:
--------------
trunk/base/src/pextlib1.0/system.c
Modified: trunk/base/src/pextlib1.0/system.c
===================================================================
--- trunk/base/src/pextlib1.0/system.c 2016-03-31 15:33:52 UTC (rev 147223)
+++ trunk/base/src/pextlib1.0/system.c 2016-03-31 15:53:21 UTC (rev 147224)
@@ -56,6 +56,7 @@
#include <unistd.h>
#include <limits.h>
#include <errno.h>
+#include <signal.h>
#include "system.h"
#include "sip_copy_proc.h"
@@ -187,6 +188,22 @@
}
}
+ /*
+ * Ignore SIGINT and SIGQUIT, just like system(3)
+ *
+ * system(3) also blocks SIGCHLD during the execution of the program.
+ * However, that would make our wait(2) call more complicated. As we are
+ * not relying on delivery of SIGCHLD anywhere else, we just do not change
+ * the handling here at all.
+ */
+ struct sigaction sa, old_sa_int, old_sa_quit;
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_handler = SIG_IGN;
+ sigemptyset(&sa.sa_mask);
+ sigaction(SIGINT, &sa, &old_sa_int);
+ sigaction(SIGQUIT, &sa, &old_sa_quit);
+
+ /* fork a new process */
pid = fork();
switch (pid) {
case -1: /* error */
@@ -229,6 +246,10 @@
}
}
+ /* restore original signal handling */
+ sigaction(SIGINT, &old_sa_int, NULL);
+ sigaction(SIGQUIT, &old_sa_quit, NULL);
+
/* XXX ugly string constants */
if (sandbox) {
args[0] = "sandbox-exec";
@@ -342,6 +363,10 @@
}
}
+ /* restore original signal handling */
+ sigaction(SIGINT, &old_sa_int, NULL);
+ sigaction(SIGQUIT, &old_sa_quit, NULL);
+
if (odup) {
/* Cleanup. */
close(fdset[0]);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20160331/6dd68ed0/attachment.html>
More information about the macports-changes
mailing list