summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Christian <andrew.christian@nokia.com>2012-03-30 09:19:18 -0400
committerChris Craig <ext-chris.craig@nokia.com>2012-03-30 16:28:58 +0200
commitdde384243669a4225258112000f16aa9a87fbac5 (patch)
tree29b9ba97a14cc320f5268a98a6d05f5147cc2ba1
parent3d9b40cdaa6aa742f1ed3f86f7bfb52f8443a2f3 (diff)
Always set parent death signal to SIGTERM under Linux
Change-Id: Ib6b625893159c55cfb6d43a6e6e963abc85a0322 Reviewed-by: Lasse Holmstedt <lasse.holmstedt@nokia.com> Reviewed-by: Alexey Shilov <alexey.shilov@nokia.com> Reviewed-by: Chris Craig <ext-chris.craig@nokia.com>
-rw-r--r--src/core/forklauncher.cpp7
-rw-r--r--src/core/prefork.cpp2
-rw-r--r--src/core/unixsandboxprocess.cpp8
3 files changed, 16 insertions, 1 deletions
diff --git a/src/core/forklauncher.cpp b/src/core/forklauncher.cpp
index 99b4ebc..90ab4e4 100644
--- a/src/core/forklauncher.cpp
+++ b/src/core/forklauncher.cpp
@@ -64,6 +64,10 @@
#include "processinfo.h"
#include "procutils.h"
+#if defined(Q_OS_LINUX)
+#include <sys/prctl.h>
+#endif
+
#if defined(Q_OS_MAC) && !defined(QT_NO_CORESERVICES)
// Shared libraries don't have direct access to environ until runtime
# include <crt_externs.h>
@@ -443,6 +447,9 @@ bool ChildProcess::doFork()
close(fd2[1]);
close(fd3[0]);
close(fd3[1]);
+#if defined(Q_OS_LINUX)
+ ::prctl(PR_SET_PDEATHSIG, SIGTERM); // Ask to be killed when parent dies
+#endif
return true;
}
diff --git a/src/core/prefork.cpp b/src/core/prefork.cpp
index ec50b29..3484c4f 100644
--- a/src/core/prefork.cpp
+++ b/src/core/prefork.cpp
@@ -229,7 +229,7 @@ int Prefork::makeChild(int start)
::close(fd2[0]);
::close(fd2[1]);
#if defined(Q_OS_LINUX)
- ::prctl(PR_SET_PDEATHSIG, SIGHUP); // Ask to be killed when parent dies
+ ::prctl(PR_SET_PDEATHSIG, SIGTERM); // Ask to be killed when parent dies
#endif
launch(start, end); // This function never returns
}
diff --git a/src/core/unixsandboxprocess.cpp b/src/core/unixsandboxprocess.cpp
index e0fe254..4361a59 100644
--- a/src/core/unixsandboxprocess.cpp
+++ b/src/core/unixsandboxprocess.cpp
@@ -46,6 +46,8 @@
#include <sys/types.h>
#include <unistd.h>
#include <grp.h>
+#include <sys/prctl.h>
+#include <signal.h>
#endif
#include <pwd.h>
@@ -72,6 +74,8 @@ UnixSandboxProcess::UnixSandboxProcess(qint64 uid, qint64 gid, QObject *parent)
/*!
Set up child process UID, GID, and supplementary group list.
Also set the child process to be in its own process group and fix the umask.
+ Under Linux, the child process will be set to receive a SIGTERM signal
+ when the parent process dies.
The creator of the child process may have specified a UID and/or a
GID for the child process. Here are the currently supported cases:
@@ -121,6 +125,10 @@ UnixSandboxProcess::UnixSandboxProcess(qint64 uid, qint64 gid, QObject *parent)
void UnixSandboxProcess::setupChildProcess()
{
+#if defined(Q_OS_LINUX)
+ if (::prctl(PR_SET_PDEATHSIG, SIGTERM))
+ qFatal("UnixSandboxProcess prctl unable to set death signal: %s", strerror(errno));
+#endif
if (::setpgid(0,0))
qFatal("UnixSandboxProcess setpgid(): %s", strerror(errno));