summaryrefslogtreecommitdiffstats
path: root/src/input/pvsPrivInputSignalHandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/input/pvsPrivInputSignalHandler.cpp')
-rw-r--r--src/input/pvsPrivInputSignalHandler.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/input/pvsPrivInputSignalHandler.cpp b/src/input/pvsPrivInputSignalHandler.cpp
new file mode 100644
index 0000000..b09c335
--- /dev/null
+++ b/src/input/pvsPrivInputSignalHandler.cpp
@@ -0,0 +1,69 @@
+/*
+ # Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg
+ #
+ # This program is free software distributed under the GPL version 2.
+ # See http://openslx.org/COPYING
+ #
+ # If you have any feedback please consult http://openslx.org/feedback and
+ # send your suggestions, praise, or complaints to feedback@openslx.org
+ #
+ # General information about OpenSLX can be found at http://openslx.org/
+ # --------------------------------------------------------------------------
+ # pvsPrivInputSignalHandler.cpp:
+ # - Handle signals forwarded over a file descriptor - implementation
+ # --------------------------------------------------------------------------
+ */
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <signal.h>
+#include <cerrno>
+#include "pvsPrivInputSocket.h"
+#include "pvsPrivInputSignalHandler.h"
+
+void PVSPrivInputSignalHandler::signalReceived(int sigfd)
+{
+ int signum;
+
+ pid_t pid;
+ uid_t uid;
+ gid_t gid;
+ int err;
+ size_t siz = sizeof(signum);
+
+ if(!pvsPrivInputRecvMessage(sigfd, &signum, siz, pid, uid, gid, &err))
+ {
+ qWarning("Should have received a signal but could not read message: %s", strerror(err));
+ return;
+ }
+
+ if(siz != sizeof(signum))
+ {
+ qWarning("Sould have received a message of size %d bytes but got %d bytes instead. Discarding message.", (int)sizeof(signum), (int)siz);
+ return;
+ }
+
+ if(!_allowUnauthenticatedKilling && pid != getpid())
+ {
+ qCritical("SOMETHING STRANGE IS GOING ON!\nReceived signal %d from PID %d\nPlease kill me instead of sending me signal notifications.", signum, (int)pid);
+ return;
+ }
+
+ switch(signum)
+ {
+ case SIGINT:
+ qDebug("Caught SIGINT. Quitting.");
+ emit terminate();
+ break;
+ case SIGTERM:
+ qDebug("Caught SIGTERM. Quitting.");
+ emit terminate();
+ break;
+ case SIGHUP:
+ qDebug("Caught SIGHUP. Reloading configuration.");
+ emit reloadConfiguration();
+ break;
+ default:
+ qWarning("Received signal %d, but don't know how to handle it.", signum);
+ }
+}