aboutsummaryrefslogtreecommitdiff
path: root/jim-exec.c
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2014-01-05 20:20:17 +1000
committerSteve Bennett <steveb@workware.net.au>2014-01-15 07:46:33 +1000
commitea26d87c159d2f411bf70c108b4b4cf346994b76 (patch)
treea35c600a79bd2957404d99e91407cdf3448ba34a /jim-exec.c
parenta4c0bf120c291bfb69bd161cdc237a751e53f2c7 (diff)
downloadjimtcl-ea26d87c159d2f411bf70c108b4b4cf346994b76.zip
jimtcl-ea26d87c159d2f411bf70c108b4b4cf346994b76.tar.gz
jimtcl-ea26d87c159d2f411bf70c108b4b4cf346994b76.tar.bz2
exec: better handling of SIGPIPE
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'jim-exec.c')
-rw-r--r--jim-exec.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/jim-exec.c b/jim-exec.c
index 08f7985..90a4f60 100644
--- a/jim-exec.c
+++ b/jim-exec.c
@@ -945,17 +945,6 @@ badargs:
}
#else
/*
- * Disable SIGPIPE signals: if they were allowed, this process
- * might go away unexpectedly if children misbehave. This code
- * can potentially interfere with other application code that
- * expects to handle SIGPIPEs; what's really needed is an
- * arbiter for signals to allow them to be "shared".
- */
- if (table->info == NULL) {
- (void)signal(SIGPIPE, SIG_IGN);
- }
-
- /*
* Make a new process and enter it into the table if the fork
* is successful.
*/
@@ -975,10 +964,13 @@ badargs:
close(i);
}
+ /* Restore SIGPIPE behaviour */
+ (void)signal(SIGPIPE, SIG_DFL);
+
execvpe(arg_array[firstArg], &arg_array[firstArg], Jim_GetEnviron());
/* Need to prep an error message before vfork(), just in case */
- fprintf(stderr, "couldn't exec \"%s\"", arg_array[firstArg]);
+ fprintf(stderr, "couldn't exec \"%s\"\n", arg_array[firstArg]);
_exit(127);
}
#endif
@@ -1135,6 +1127,21 @@ int Jim_execInit(Jim_Interp *interp)
{
if (Jim_PackageProvide(interp, "exec", "1.0", JIM_ERRMSG))
return JIM_ERR;
+
+#ifdef SIGPIPE
+ /*
+ * Disable SIGPIPE signals: if they were allowed, this process
+ * might go away unexpectedly if children misbehave. This code
+ * can potentially interfere with other application code that
+ * expects to handle SIGPIPEs.
+ *
+ * By doing this in the init function, applications can override
+ * this later. Note that child processes have SIGPIPE restored
+ * to the default after vfork().
+ */
+ (void)signal(SIGPIPE, SIG_IGN);
+#endif
+
Jim_CreateCommand(interp, "exec", Jim_ExecCmd, JimAllocWaitInfoTable(), JimFreeWaitInfoTable);
return JIM_OK;
}