summaryrefslogtreecommitdiffstats
path: root/logd
diff options
context:
space:
mode:
authorArne Juul <arnej@yahoo-inc.com>2017-10-09 10:16:51 +0000
committerArne Juul <arnej@yahoo-inc.com>2017-10-09 10:16:51 +0000
commit10ef678f43f23abfae0766ef88d5003e259bb658 (patch)
tree9126c7692ffb4d82e301dd54c9a75c98d3399031 /logd
parentd6267b2b9aff7fcc1d3bf55703501ab5c6484f20 (diff)
use vespalib::SigCatch
Diffstat (limited to 'logd')
-rw-r--r--logd/src/apps/logd/main.cpp25
-rw-r--r--logd/src/logd/CMakeLists.txt1
-rw-r--r--logd/src/logd/sigterm.cpp27
-rw-r--r--logd/src/logd/sigterm.h6
-rw-r--r--logd/src/logd/watch.cpp7
5 files changed, 13 insertions, 53 deletions
diff --git a/logd/src/apps/logd/main.cpp b/logd/src/apps/logd/main.cpp
index caeaf83c7cc..00654060107 100644
--- a/logd/src/apps/logd/main.cpp
+++ b/logd/src/apps/logd/main.cpp
@@ -1,7 +1,6 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <logd/errhandle.h>
-#include <logd/sigterm.h>
#include <logd/service.h>
#include <logd/forward.h>
#include <logd/conf.h>
@@ -9,6 +8,7 @@
#include <vespa/config/common/exceptions.h>
#include <csignal>
#include <unistd.h>
+#include <vespa/vespalib/util/sig_catch.h>
#include <vespa/log/log.h>
LOG_SETUP("logdemon");
@@ -24,7 +24,7 @@ int main(int, char**)
EV_STARTED("logdemon");
- hook_signals();
+ vespalib::SigCatch catcher;
const char *cfid = getenv("VESPA_CONFIG_ID");
@@ -50,7 +50,7 @@ int main(int, char**)
LOG(debug, "connection exception: %s", ex.what());
subscriber.closeConn();
}
- if (gotSignaled()) {
+ if (catcher.receivedStopSignal()) {
throw SigTermException("caught signal");
}
if (sleepcount < 60) {
@@ -60,10 +60,10 @@ int main(int, char**)
}
LOG(debug, "sleep %d...", sleepcount);
for (int i = 0; i < sleepcount; i++) {
- sleep(1);
- if (gotSignaled()) {
- throw SigTermException("caught signal");
- }
+ sleep(1);
+ if (catcher.receivedStopSignal()) {
+ throw SigTermException("caught signal");
+ }
}
}
} catch (config::ConfigRuntimeException & ex) {
@@ -75,15 +75,8 @@ int main(int, char**)
EV_STOPPING("logdemon", "bad config");
return 1;
} catch (SigTermException& ex) {
- if (gotSignalNumber() == SIGTERM) {
- LOG(debug, "stopping on SIGTERM");
- EV_STOPPING("logdemon", "done ok.");
- } else {
- LOG(warning, "stopping on signal %d", gotSignalNumber());
- char buf[100];
- snprintf(buf, sizeof buf, "got signal %d", gotSignalNumber());
- EV_STOPPING("logdemon", buf);
- }
+ LOG(debug, "stopping on SIGTERM");
+ EV_STOPPING("logdemon", "done ok.");
return 0;
} catch (MsgException& ex) {
LOG(error, "stopping on error: %s", ex.what());
diff --git a/logd/src/logd/CMakeLists.txt b/logd/src/logd/CMakeLists.txt
index be3fe2d1794..b436ef52876 100644
--- a/logd/src/logd/CMakeLists.txt
+++ b/logd/src/logd/CMakeLists.txt
@@ -8,7 +8,6 @@ vespa_add_library(logd STATIC
service.cpp
cmdbuf.cpp
perform.cpp
- sigterm.cpp
DEPENDS
)
vespa_generate_config(logd ../main/resources/configdefinitions/logd.def)
diff --git a/logd/src/logd/sigterm.cpp b/logd/src/logd/sigterm.cpp
deleted file mode 100644
index 8fe7665865f..00000000000
--- a/logd/src/logd/sigterm.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include "sigterm.h"
-#include <vespa/vespalib/util/signalhandler.h>
-
-void hook_signals()
-{
- vespalib::SignalHandler::INT.hook();
- vespalib::SignalHandler::TERM.hook();
- vespalib::SignalHandler::PIPE.ignore();
-}
-
-bool gotSignaled()
-{
- return (vespalib::SignalHandler::INT.check() ||
- vespalib::SignalHandler::TERM.check());
-}
-
-int gotSignalNumber()
-{
- if (vespalib::SignalHandler::TERM.check()) {
- return SIGTERM;
- }
- if (vespalib::SignalHandler::INT.check()) {
- return SIGINT;
- }
- return 0;
-}
diff --git a/logd/src/logd/sigterm.h b/logd/src/logd/sigterm.h
deleted file mode 100644
index 79b0eb7b781..00000000000
--- a/logd/src/logd/sigterm.h
+++ /dev/null
@@ -1,6 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#pragma once
-// setup for catching signals
-extern void hook_signals();
-extern bool gotSignaled();
-extern int gotSignalNumber();
diff --git a/logd/src/logd/watch.cpp b/logd/src/logd/watch.cpp
index 0558d0b4548..ad866938ab6 100644
--- a/logd/src/logd/watch.cpp
+++ b/logd/src/logd/watch.cpp
@@ -1,7 +1,6 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "errhandle.h"
-#include "sigterm.h"
#include "service.h"
#include "forward.h"
#include "conf.h"
@@ -13,6 +12,7 @@
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/time.h>
+#include <vespa/vespalib/util/sig_catch.h>
LOG_SETUP("");
@@ -196,6 +196,7 @@ Watcher::watchfile()
_forwarder.sendMode();
+ vespalib::SigCatch catcher;
int sleepcount = 0;
time_t created = 0;
@@ -342,11 +343,11 @@ Watcher::watchfile()
}
}
- if (gotSignaled()) {
+ if (catcher.receivedStopSignal()) {
throw SigTermException("caught signal");
}
snooze(tickStart);
- if (gotSignaled()) {
+ if (catcher.receivedStopSignal()) {
throw SigTermException("caught signal");
}
if (++sleepcount > 99) {