summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2013-12-08 15:53:44 +0000
committerrandomdan <randomdan@localhost>2013-12-08 15:53:44 +0000
commit55bd437eb5650da4524377cc3a03b42d19825afb (patch)
treef5396ceb709e9377fdb05ab54781d05c7ed61a1e
parentAssume, don't force, relative paths to scripts (allows absolute root paths) (diff)
downloadproject2-55bd437eb5650da4524377cc3a03b42d19825afb.tar.bz2
project2-55bd437eb5650da4524377cc3a03b42d19825afb.tar.xz
project2-55bd437eb5650da4524377cc3a03b42d19825afb.zip
Change signal handling to be more helpful and proper
-rw-r--r--project2/daemon/p2daemonAppEngine.cpp46
-rw-r--r--project2/daemon/p2daemonAppEngine.h5
2 files changed, 39 insertions, 12 deletions
diff --git a/project2/daemon/p2daemonAppEngine.cpp b/project2/daemon/p2daemonAppEngine.cpp
index 2330b88..942ab9f 100644
--- a/project2/daemon/p2daemonAppEngine.cpp
+++ b/project2/daemon/p2daemonAppEngine.cpp
@@ -29,12 +29,11 @@ DaemonAppEngine::~DaemonAppEngine()
void
DaemonAppEngine::shutdown(int)
{
- if (signal(SIGINT, SIG_DFL) == SIG_ERR) {
- Logger()->message(LOG_WARNING, "Failed to remove signal handler");
- }
- if (signal(SIGTERM, SIG_DFL) == SIG_ERR) {
- Logger()->message(LOG_WARNING, "Failed to remove signal handler");
- }
+ DefaultSignalHandler(SIGINT);
+ DefaultSignalHandler(SIGUSR1);
+ DefaultSignalHandler(SIGUSR2);
+ DefaultSignalHandler(SIGQUIT);
+ DefaultSignalHandler(SIGTERM);
Logger()->message(LOG_INFO, "Shutting down daemon.");
daemon->shutdown();
@@ -44,15 +43,38 @@ DaemonAppEngine::shutdown(int)
void
DaemonAppEngine::process() const
{
- if (signal(SIGINT, &shutdown) == SIG_ERR) {
- Logger()->message(LOG_WARNING, "Failed to add signal handler");
- }
- if (signal(SIGTERM, &shutdown) == SIG_ERR) {
- Logger()->message(LOG_WARNING, "Failed to add signal handler");
- }
+ IgnoreSignal(SIGINT);
+ IgnoreSignal(SIGUSR1);
+ IgnoreSignal(SIGUSR2);
+ AddSignalHandler(SIGQUIT, &shutdown);
+ AddSignalHandler(SIGTERM, &shutdown);
Logger()->message(LOG_INFO, "Starting daemon.");
daemon->run();
Logger()->message(LOG_INFO, "Daemon exitted.");
}
+void
+DaemonAppEngine::IgnoreSignal(int signum)
+{
+ if (signal(signum, SIG_IGN) == SIG_ERR) {
+ Logger()->messagef(LOG_WARNING, "%s: Failed to ignore signal %d", __PRETTY_FUNCTION__, signum);
+ }
+}
+
+void
+DaemonAppEngine::DefaultSignalHandler(int signum)
+{
+ if (signal(signum, SIG_DFL) == SIG_ERR) {
+ Logger()->messagef(LOG_WARNING, "%s: Failed to restore default signal %d handler", __PRETTY_FUNCTION__, signum);
+ }
+}
+
+void
+DaemonAppEngine::AddSignalHandler(int signum, sighandler_t handler)
+{
+ if (signal(signum, handler) == SIG_ERR) {
+ Logger()->messagef(LOG_WARNING, "%s: Failed to add signal %d handler", __PRETTY_FUNCTION__, signum);
+ }
+}
+
diff --git a/project2/daemon/p2daemonAppEngine.h b/project2/daemon/p2daemonAppEngine.h
index e6632f2..42eddc7 100644
--- a/project2/daemon/p2daemonAppEngine.h
+++ b/project2/daemon/p2daemonAppEngine.h
@@ -17,6 +17,11 @@ class DaemonAppEngine {
static Glib::ustring reqPlatform;
static std::string daemonType;
+ protected:
+ static void IgnoreSignal(int signum);
+ static void DefaultSignalHandler(int signum);
+ static void AddSignalHandler(int signum, sighandler_t handler);
+
private:
static void shutdown(int);
static DaemonPtr daemon;