summaryrefslogtreecommitdiffstats
path: root/process.cpp
diff options
context:
space:
mode:
authorRainer Keller <rainer.keller@digia.com>2013-04-17 11:02:59 +0200
committerRainer Keller <rainer.keller@digia.com>2013-04-17 11:02:59 +0200
commit676eb8c6c31abaecc3d1f06da06a8e54a2a0deae (patch)
tree9b64ed5d79a333f0bb6fabccb8b8da8d0bcd472a /process.cpp
parent3b9ef02e4e4b4fbb3068c64eb85dba4d881cbeec (diff)
Handle SIGINT and SIGKILL
Diffstat (limited to 'process.cpp')
-rw-r--r--process.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/process.cpp b/process.cpp
index da7abf4..e3cd861 100644
--- a/process.cpp
+++ b/process.cpp
@@ -6,6 +6,14 @@
#include <QSocketNotifier>
#include <sys/socket.h>
#include <signal.h>
+#include <fcntl.h>
+
+static int pipefd[2];
+
+static void signalhandler(int)
+{
+ write(pipefd[1], " ", 1);
+}
Process::Process()
: QObject(0)
@@ -19,10 +27,21 @@ Process::Process()
connect(mProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finished(int, QProcess::ExitStatus)));
connect(mProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(error(QProcess::ProcessError)));
connect(mProcess, SIGNAL(finished(int, QProcess::ExitStatus)), qApp, SLOT(quit()));
+
+ if (pipe2(pipefd, O_CLOEXEC) != 0)
+ qWarning("Could not create pipe");
+
+ QSocketNotifier *n = new QSocketNotifier(pipefd[0], QSocketNotifier::Read, this);
+ connect(n, SIGNAL(activated(int)), this, SLOT(stop()));
+
+ signal(SIGINT, signalhandler);
+ signal(SIGKILL, signalhandler);
}
Process::~Process()
{
+ close(pipefd[0]);
+ close(pipefd[1]);
}
void Process::readyReadStandardOutput()