summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2015-04-01 12:47:16 -0400
committerNick Mathewson <nickm@torproject.org>2015-04-01 12:47:16 -0400
commit0ddd8f06a9e0c1ff3f5b5ede7e2a274d303645ea (patch)
tree666398fc67ec7107935869c6bdf766fd9250e25a /src
parent162fd52b405918a78bf25d7e043edd16a53a2e0f (diff)
parentfa81508eb2d9a2a2ea69c2c585735aef7aaff97c (diff)
downloadtor-0ddd8f06a9e0c1ff3f5b5ede7e2a274d303645ea.tar.gz
tor-0ddd8f06a9e0c1ff3f5b5ede7e2a274d303645ea.zip
Merge remote-tracking branch 'yawning/feature15471'
Diffstat (limited to 'src')
-rw-r--r--src/common/util.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 2c3a1a1019..246a0d3940 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -95,6 +95,9 @@
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
+#if defined(HAVE_SYS_PRCTL_H) && defined(__linux__)
+#include <sys/prctl.h>
+#endif
#ifdef __clang_analyzer__
#undef MALLOC_ZERO_WORKS
@@ -4180,6 +4183,15 @@ tor_spawn_background(const char *const filename, const char **argv,
if (0 == pid) {
/* In child */
+#if defined(HAVE_SYS_PRCTL_H) && defined(__linux__)
+ /* Attempt to have the kernel issue a SIGTERM if the parent
+ * goes away. Certain attributes of the binary being execve()ed
+ * will clear this during the execve() call, but it's better
+ * than nothing.
+ */
+ prctl(PR_SET_PDEATHSIG, SIGTERM);
+#endif
+
child_state = CHILD_STATE_DUPOUT;
/* Link child stdout to the write end of the pipe */
@@ -4225,8 +4237,10 @@ tor_spawn_background(const char *const filename, const char **argv,
does not modify the arguments */
if (env)
execve(filename, (char *const *) argv, env->unixoid_environment_block);
- else
- execvp(filename, (char *const *) argv);
+ else {
+ static char *new_env[] = { NULL };
+ execve(filename, (char *const *) argv, new_env);
+ }
/* If we got here, the exec or open(/dev/null) failed */