aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/util/CMakeLists.txt1
-rw-r--r--vespalib/src/vespa/vespalib/util/sig_catch.cpp22
-rw-r--r--vespalib/src/vespa/vespalib/util/sig_catch.h25
-rw-r--r--vespalib/src/vespa/vespalib/util/signalhandler.cpp1
-rw-r--r--vespalib/src/vespa/vespalib/util/signalhandler.h1
5 files changed, 50 insertions, 0 deletions
diff --git a/vespalib/src/vespa/vespalib/util/CMakeLists.txt b/vespalib/src/vespa/vespalib/util/CMakeLists.txt
index 6d08c3b1126..58739ee4df6 100644
--- a/vespalib/src/vespa/vespalib/util/CMakeLists.txt
+++ b/vespalib/src/vespa/vespalib/util/CMakeLists.txt
@@ -37,6 +37,7 @@ vespa_add_library(vespalib_vespalib_util OBJECT
rwlock.cpp
sequence.cpp
sha1.cpp
+ sig_catch.cpp
signalhandler.cpp
simple_thread_bundle.cpp
slaveproc.cpp
diff --git a/vespalib/src/vespa/vespalib/util/sig_catch.cpp b/vespalib/src/vespa/vespalib/util/sig_catch.cpp
new file mode 100644
index 00000000000..48bf8fbb05d
--- /dev/null
+++ b/vespalib/src/vespa/vespalib/util/sig_catch.cpp
@@ -0,0 +1,22 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "sig_catch.h"
+#include "signalhandler.h"
+
+namespace vespalib {
+
+SigCatch::SigCatch()
+{
+ SignalHandler::PIPE.ignore();
+ SignalHandler::INT.hook();
+ SignalHandler::TERM.hook();
+}
+
+bool
+SigCatch::receivedStopSignal()
+{
+ return (SignalHandler::INT.check() ||
+ SignalHandler::TERM.check());
+}
+
+} // namespace vespalib
diff --git a/vespalib/src/vespa/vespalib/util/sig_catch.h b/vespalib/src/vespa/vespalib/util/sig_catch.h
new file mode 100644
index 00000000000..96c74ee4d07
--- /dev/null
+++ b/vespalib/src/vespa/vespalib/util/sig_catch.h
@@ -0,0 +1,25 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+namespace vespalib {
+
+/**
+ * @brief Use this class for simple common-case signal handling.
+ **/
+
+class SigCatch
+{
+public:
+ /**
+ * Constructor installs signal handlers.
+ **/
+ SigCatch();
+
+ /**
+ * Check if a signal to stop has been received.
+ **/
+ bool receivedStopSignal();
+};
+
+} // namespace vespalib
diff --git a/vespalib/src/vespa/vespalib/util/signalhandler.cpp b/vespalib/src/vespa/vespalib/util/signalhandler.cpp
index 6bc7fcd17df..21543ef10d8 100644
--- a/vespalib/src/vespa/vespalib/util/signalhandler.cpp
+++ b/vespalib/src/vespa/vespalib/util/signalhandler.cpp
@@ -25,6 +25,7 @@ Shutdown shutdown;
SignalHandler SignalHandler::HUP(SIGHUP);
SignalHandler SignalHandler::INT(SIGINT);
SignalHandler SignalHandler::TERM(SIGTERM);
+SignalHandler SignalHandler::CHLD(SIGCHLD);
SignalHandler SignalHandler::PIPE(SIGPIPE);
SignalHandler SignalHandler::SEGV(SIGSEGV);
SignalHandler SignalHandler::ABRT(SIGABRT);
diff --git a/vespalib/src/vespa/vespalib/util/signalhandler.h b/vespalib/src/vespa/vespalib/util/signalhandler.h
index 6b233b2e690..f34ddba5530 100644
--- a/vespalib/src/vespa/vespalib/util/signalhandler.h
+++ b/vespalib/src/vespa/vespalib/util/signalhandler.h
@@ -67,6 +67,7 @@ public:
static SignalHandler HUP;
static SignalHandler INT;
static SignalHandler TERM;
+ static SignalHandler CHLD;
static SignalHandler PIPE;
static SignalHandler SEGV;
static SignalHandler ABRT;