changed signalhandling to FbTk SignalHandler

This commit is contained in:
fluxgen 2002-08-14 00:01:10 +00:00
parent 76a1c5c161
commit fdd8313050
2 changed files with 68 additions and 26 deletions

View file

@ -22,7 +22,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// $Id: fluxbox.cc,v 1.66 2002/08/13 21:19:00 fluxgen Exp $
// $Id: fluxbox.cc,v 1.67 2002/08/14 00:01:10 fluxgen Exp $
#include "fluxbox.hh"
@ -111,12 +111,15 @@
# include <libgen.h>
#endif // HAVE_LIBGEN_H
#include <sys/wait.h>
#include <iostream>
#include <string>
#include <memory>
#include <algorithm>
using namespace std;
using namespace FbTk;
#ifndef HAVE_BASENAME
namespace {
@ -314,6 +317,18 @@ key(0)
abort();
}
//setup signals
SignalHandler *sigh = SignalHandler::instance();
sigh->registerHandler(SIGSEGV, this);
sigh->registerHandler(SIGFPE, this);
sigh->registerHandler(SIGTERM, this);
sigh->registerHandler(SIGINT, this);
sigh->registerHandler(SIGCHLD, this);
sigh->registerHandler(SIGHUP, this);
sigh->registerHandler(SIGUSR1, this);
sigh->registerHandler(SIGUSR2, this);
//singleton pointer
singleton = this;
BaseDisplay::GrabGuard gg(*this);
@ -324,7 +339,7 @@ key(0)
if (! XSupportsLocale())
fprintf(stderr, "X server does not support locale\n");
if (XSetLocaleModifiers("") == NULL)
if (XSetLocaleModifiers("") == 0)
fprintf(stderr, "cannot set locale modifiers\n");
// Set default values to member variables
@ -1562,30 +1577,56 @@ bool Fluxbox::checkNETWMAtoms(XClientMessageEvent &ce) {
}
#endif //!NEWWMSPEC
Bool Fluxbox::handleSignal(int sig) {
void Fluxbox::handleSignal(int sig) {
I18n *i18n = I18n::instance();
static int re_enter = 0;
switch (sig) {
case SIGCHLD: // we don't want the child process to kill us
waitpid(-1, 0, WNOHANG | WUNTRACED);
break;
case SIGHUP:
load_rc();
break;
case SIGUSR1:
reload_rc();
break;
case SIGUSR2:
rereadMenu();
break;
case SIGSEGV:
case SIGFPE:
case SIGINT:
case SIGTERM:
shutdown();
break;
default:
return False;
fprintf(stderr,
i18n->getMessage(
FBNLS::BaseDisplaySet, FBNLS::BaseDisplaySignalCaught,
"%s: signal %d caught\n"),
getApplicationName(), sig);
if (! isStartup() && ! re_enter) {
re_enter = 1;
fprintf(stderr,
i18n->getMessage(
FBNLS::BaseDisplaySet, FBNLS::BaseDisplayShuttingDown,
"shutting down\n"));
shutdown();
}
return True;
fprintf(stderr,
i18n->getMessage(
FBNLS::BaseDisplaySet, FBNLS::BaseDisplayAborting,
"aborting... dumping core\n"));
abort();
break;
}
}

View file

@ -22,7 +22,7 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// $Id: fluxbox.hh,v 1.24 2002/08/13 21:18:17 fluxgen Exp $
// $Id: fluxbox.hh,v 1.25 2002/08/14 00:00:16 fluxgen Exp $
#ifndef FLUXBOX_HH
#define FLUXBOX_HH
@ -40,12 +40,12 @@
#include "Slit.hh"
#endif // SLIT
#include "SignalHandler.hh"
#include <X11/Xlib.h>
#include <X11/Xresource.h>
#ifdef HAVE_STDIO_H
# include <stdio.h>
#endif // HAVE_STDIO_H
#include <cstdio>
#ifdef TIME_WITH_SYS_TIME
#include <sys/time.h>
@ -67,7 +67,7 @@
main class for the window manager.
singleton type
*/
class Fluxbox : public BaseDisplay, public TimeoutHandler {
class Fluxbox : public BaseDisplay, public TimeoutHandler, public FbTk::SignalHandler::EventHandler {
public:
Fluxbox(int argc, char **argv, const char * dpy_name= 0, const char *rc = 0);
virtual ~Fluxbox();
@ -148,7 +148,8 @@ public:
void rereadMenu();
void checkMenu();
virtual Bool handleSignal(int);
/// handle any signal sent to the application
void handleSignal(int signum);
virtual void timeout();