From 10ef678f43f23abfae0766ef88d5003e259bb658 Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Mon, 9 Oct 2017 10:16:51 +0000 Subject: use vespalib::SigCatch --- logd/src/apps/logd/main.cpp | 25 +++++++++---------------- logd/src/logd/CMakeLists.txt | 1 - logd/src/logd/sigterm.cpp | 27 --------------------------- logd/src/logd/sigterm.h | 6 ------ logd/src/logd/watch.cpp | 7 ++++--- 5 files changed, 13 insertions(+), 53 deletions(-) delete mode 100644 logd/src/logd/sigterm.cpp delete mode 100644 logd/src/logd/sigterm.h 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 -#include #include #include #include @@ -9,6 +8,7 @@ #include #include #include +#include #include 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 - -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 #include #include +#include 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) { -- cgit v1.2.3