/* * Localwebfaker - Web sites faker for LAN * Copyright (C) 2007-2009 Lucas J. González * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see #include int MyDaemon::sigintFd[2]; int MyDaemon::sighupFd[2]; int MyDaemon::sigtermFd[2]; MyDaemon::MyDaemon(QObject *parent) : QObject( parent ) { if (::socketpair(AF_UNIX, SOCK_STREAM, 0, sigintFd)) qFatal("Couldn't create INT socketpair"); if (::socketpair(AF_UNIX, SOCK_STREAM, 0, sighupFd)) qFatal("Couldn't create HUP socketpair"); if (::socketpair(AF_UNIX, SOCK_STREAM, 0, sigtermFd)) qFatal("Couldn't create TERM socketpair"); snInt = new QSocketNotifier(sigintFd[1], QSocketNotifier::Read, this); connect(snInt, SIGNAL(activated(int)), this, SLOT(handleSigInt())); snHup = new QSocketNotifier(sighupFd[1], QSocketNotifier::Read, this); connect(snHup, SIGNAL(activated(int)), this, SLOT(handleSigHup())); snTerm = new QSocketNotifier(sigtermFd[1], QSocketNotifier::Read, this); connect(snTerm, SIGNAL(activated(int)), this, SLOT(handleSigTerm())); // ... } void MyDaemon::intSignalHandler(int) { int a = 1 ; ::write(sigintFd[0], &a, sizeof(a)) ; } void MyDaemon::hupSignalHandler(int) { char a = 1; ::write(sighupFd[0], &a, sizeof(a)); } void MyDaemon::termSignalHandler(int) { char a = 1; ::write(sigtermFd[0], &a, sizeof(a)); } void MyDaemon::handleSigInt() { snInt->setEnabled(false); char tmp; ::read(sigintFd[1], &tmp, sizeof(tmp)); // Acciones QT std::cout << "got a SIGINT signal !! " << std::endl ; // snInt->setEnabled(true); } void MyDaemon::handleSigTerm() { snTerm->setEnabled(false); char tmp; ::read(sigtermFd[1], &tmp, sizeof(tmp)); // Acciones QT std::cout << "got a SIGTERM signal !! " << std::endl ; snTerm->setEnabled(true); } void MyDaemon::handleSigHup() { snHup->setEnabled(false); char tmp; ::read(sighupFd[1], &tmp, sizeof(tmp)); // Acciones QT std::cout << "got a SIGHUP signal !! " << std::endl ; snHup->setEnabled(true); }