diff options
| author | Sebastien Braun | 2010-10-06 15:08:03 +0200 |
|---|---|---|
| committer | Sebastien Braun | 2010-10-06 15:08:03 +0200 |
| commit | 6afd810d1954018791456a7cebca0d275c50ed95 (patch) | |
| tree | 64d7b3e560dde3049c6c3056387c14f10066c666 /src/input/pvsPrivInputSignalHandler.cpp | |
| parent | Implement administratively configured user privileges (diff) | |
| download | pvs-6afd810d1954018791456a7cebca0d275c50ed95.tar.gz pvs-6afd810d1954018791456a7cebca0d275c50ed95.tar.xz pvs-6afd810d1954018791456a7cebca0d275c50ed95.zip | |
Refactor signal handling in pvsprivinputd
Only use one socketpair and delegate the actual decision of what to do
when a specific signal is received to a special object.
Diffstat (limited to 'src/input/pvsPrivInputSignalHandler.cpp')
| -rw-r--r-- | src/input/pvsPrivInputSignalHandler.cpp | 69 |
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); + } +} |
