blob: b09c335be28ae6287b9d00a1c9a98eec710f4efc (
plain) (
tree)
|
|
/*
# 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);
}
}
|