summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorArne Juul <arnej@yahoo-inc.com>2017-10-05 11:34:27 +0000
committerArne Juul <arnej@yahoo-inc.com>2017-10-05 11:35:12 +0000
commit4c76bd6a4349b59865a9607fe11fc7177775e1bb (patch)
tree47706a5e0a4169b9dbab8080a3485104b13d4cf6 /vespalib
parent8432ebac9709bfaf61f45925e2bff66cf6f8f531 (diff)
add SigCatch class
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/util/CMakeLists.txt1
-rw-r--r--vespalib/src/vespa/vespalib/util/sig_catch.cpp35
-rw-r--r--vespalib/src/vespa/vespalib/util/sig_catch.h35
-rw-r--r--vespalib/src/vespa/vespalib/util/signalhandler.cpp1
-rw-r--r--vespalib/src/vespa/vespalib/util/signalhandler.h1
5 files changed, 73 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..b1ffecdf24c
--- /dev/null
+++ b/vespalib/src/vespa/vespalib/util/sig_catch.cpp
@@ -0,0 +1,35 @@
+// 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();
+ SignalHandler::CHLD.hook();
+}
+
+bool
+SigCatch::receivedStopSignal()
+{
+ return (SignalHandler::INT.check() ||
+ SignalHandler::TERM.check());
+}
+
+bool
+SigCatch::receivedChildSignal()
+{
+ return SignalHandler::CHLD.check();
+}
+
+void
+SigCatch::clearChildSignalFlag()
+{
+ SignalHandler::CHLD.clear();
+}
+
+} // 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..80a52545801
--- /dev/null
+++ b/vespalib/src/vespa/vespalib/util/sig_catch.h
@@ -0,0 +1,35 @@
+// 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();
+
+ /**
+ * Check for child process events
+ **/
+ bool receivedChildSignal();
+
+ /**
+ * Clear flag for child process events
+ **/
+ void clearChildSignalFlag();
+};
+
+} // 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;