summaryrefslogtreecommitdiffstats
path: root/configd
diff options
context:
space:
mode:
authorArne Juul <arnej@yahoo-inc.com>2017-10-09 10:57:19 +0000
committerArne Juul <arnej@yahoo-inc.com>2017-10-09 10:57:19 +0000
commit3c7957089c31e706b488056e2124a753e31365f7 (patch)
tree6cd20d22988b34a688060af0372448d98ad52686 /configd
parent10ef678f43f23abfae0766ef88d5003e259bb658 (diff)
use vespalib::SignalHandler
Diffstat (limited to 'configd')
-rw-r--r--configd/src/apps/sentinel/sentinel.cpp56
-rw-r--r--configd/src/apps/sentinel/service.cpp11
2 files changed, 23 insertions, 44 deletions
diff --git a/configd/src/apps/sentinel/sentinel.cpp b/configd/src/apps/sentinel/sentinel.cpp
index 45bbbe19cf3..bb05f9e40ad 100644
--- a/configd/src/apps/sentinel/sentinel.cpp
+++ b/configd/src/apps/sentinel/sentinel.cpp
@@ -4,6 +4,7 @@
#include <csignal>
#include <unistd.h>
#include <sys/time.h>
+#include <vespa/vespalib/util/signalhandler.h>
#include <vespa/defaults.h>
#include "config-handler.h"
@@ -14,13 +15,11 @@ using namespace config;
constexpr uint64_t CONFIG_TIMEOUT_MS = 3 * 60 * 1000;
-static int sigPermanent(int sig, void(*handler)(int));
-
-static void gracefulShutdown(int sig);
-static void sigchldHandler(int sig);
-
-sig_atomic_t stop = 0;
-static sig_atomic_t pendingWait = 0;
+static bool stop()
+{
+ return (vespalib::SignalHandler::INT.check() ||
+ vespalib::SignalHandler::TERM.check());
+}
int
main(int argc, char **argv)
@@ -49,10 +48,11 @@ main(int argc, char **argv)
EV_STARTED("config-sentinel");
- sigPermanent(SIGPIPE, SIG_IGN);
- sigPermanent(SIGTERM, gracefulShutdown);
- sigPermanent(SIGINT, gracefulShutdown);
- sigPermanent(SIGCHLD, sigchldHandler);
+ vespalib::SignalHandler::PIPE.ignore();
+ vespalib::SignalHandler::TERM.hook();
+ vespalib::SignalHandler::INT.hook();
+ vespalib::SignalHandler::CHLD.hook();
+
if (setenv("LC_ALL", "C", 1) != 0) {
LOG(error, "Unable to set locale");
exit(EXIT_FAILURE);
@@ -80,15 +80,15 @@ main(int argc, char **argv)
struct timeval lastTv;
gettimeofday(&lastTv, nullptr);
- while (!stop) {
+ while (!stop()) {
try {
- pendingWait = 0;
+ vespalib::SignalHandler::CHLD.clear();
handler.doWork(); // Check for child procs & commands
} catch (InvalidConfigException& ex) {
LOG(warning, "Configuration problem: (ignoring): %s",
ex.what());
}
- if (!pendingWait) {
+ if (!vespalib::SignalHandler::CHLD.check()) {
int maxNum = 0;
fd_set fds;
FD_ZERO(&fds);
@@ -98,7 +98,7 @@ main(int argc, char **argv)
tv.tv_sec = 1;
tv.tv_usec = 0;
- if (!pendingWait) {
+ if (!vespalib::SignalHandler::CHLD.check()) {
select(maxNum, &fds, nullptr, nullptr, &tv);
}
}
@@ -118,29 +118,3 @@ main(int argc, char **argv)
EV_STOPPING("config-sentinel", "normal exit");
return rv;
}
-
-static void
-gracefulShutdown(int sig)
-{
- (void)sig;
- stop = 1;
-}
-
-static void
-sigchldHandler(int sig)
-{
- (void)sig;
- pendingWait = 1;
-}
-
-static int
-sigPermanent(int sig, void(*handler)(int))
-{
- struct sigaction sa;
-
- memset(&sa, 0, sizeof(sa));
- sigemptyset(&sa.sa_mask);
- sa.sa_flags = 0; // no SA_RESTART!
- sa.sa_handler = handler;
- return sigaction(sig, &sa, nullptr);
-}
diff --git a/configd/src/apps/sentinel/service.cpp b/configd/src/apps/sentinel/service.cpp
index fc1f768f989..2f13a05eb4f 100644
--- a/configd/src/apps/sentinel/service.cpp
+++ b/configd/src/apps/sentinel/service.cpp
@@ -3,6 +3,7 @@
#include "service.h"
#include "output-connection.h"
#include <vespa/vespalib/util/stringfmt.h>
+#include <vespa/vespalib/util/signalhandler.h>
#include <csignal>
#include <unistd.h>
@@ -13,7 +14,11 @@
LOG_SETUP(".service");
#include <vespa/log/llparser.h>
-extern sig_atomic_t stop;
+static bool stop()
+{
+ return (vespalib::SignalHandler::INT.check() ||
+ vespalib::SignalHandler::TERM.check());
+}
using vespalib::make_string;
@@ -212,7 +217,7 @@ Service::start()
static_cast<int>(getpid()));
signal(SIGTERM, SIG_DFL);
signal(SIGINT, SIG_DFL);
- if (stop) {
+ if (stop()) {
kill(getpid(), SIGTERM);
}
if (_restartPenalty > 0) {
@@ -315,7 +320,7 @@ Service::youExited(int status)
} else if (_state == KILLING) {
setState(KILLED);
}
- if (_isAutomatic && _config->autorestart && !stop) {
+ if (_isAutomatic && _config->autorestart && !stop()) {
// ### Implement some rate limiting here maybe?
LOG(debug, "%s: Has autorestart flag, restarting.", name().c_str());
setState(READY);