2002-08-14 00:01:57 +00:00
|
|
|
// signaltest.cc for testing signal handler in fluxbox
|
2005-01-24 18:43:01 +00:00
|
|
|
// Copyright (c) 2002 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
|
2002-08-14 00:01:57 +00:00
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the "Software"),
|
|
|
|
// to deal in the Software without restriction, including without limitation
|
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
// Software is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2004-05-02 21:27:15 +00:00
|
|
|
#include "../FbTk/SignalHandler.hh"
|
2002-08-14 00:01:57 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
2004-08-31 15:26:40 +00:00
|
|
|
#ifdef HAVE_CASSERT
|
|
|
|
#include <cassert>
|
|
|
|
#else
|
|
|
|
#include <assert.h>
|
|
|
|
#endif
|
2002-08-14 00:01:57 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace FbTk;
|
|
|
|
|
2004-05-02 21:27:15 +00:00
|
|
|
class IntSig:public SignalEventHandler {
|
2002-08-14 00:01:57 +00:00
|
|
|
public:
|
2002-12-01 13:42:15 +00:00
|
|
|
void handleSignal(int signum) {
|
|
|
|
assert(signum == SIGINT);
|
|
|
|
cerr<<"Signal SIGINT!"<<endl;
|
|
|
|
exit(0);
|
|
|
|
}
|
2002-08-14 00:01:57 +00:00
|
|
|
};
|
|
|
|
|
2004-05-02 21:27:15 +00:00
|
|
|
class AllSig:public SignalEventHandler {
|
2002-08-14 00:01:57 +00:00
|
|
|
public:
|
2002-12-01 13:42:15 +00:00
|
|
|
void handleSignal(int signum) {
|
|
|
|
switch (signum) {
|
2004-05-02 21:27:15 +00:00
|
|
|
case SIGSEGV:
|
|
|
|
cerr<<"SIGSEGV";
|
|
|
|
break;
|
2002-12-01 13:42:15 +00:00
|
|
|
case SIGTERM:
|
|
|
|
cerr<<"SIGTERM";
|
|
|
|
break;
|
|
|
|
case SIGUSR1:
|
|
|
|
cerr<<"SIGUSR1";
|
|
|
|
break;
|
|
|
|
case SIGUSR2:
|
|
|
|
cerr<<"SIGUSR2";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cerr<<"signum = "<<signum;
|
|
|
|
}
|
|
|
|
cerr<<endl;
|
|
|
|
if (signum == SIGTERM)
|
|
|
|
exit(1); // end program
|
|
|
|
}
|
2002-08-14 00:01:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2004-05-02 21:27:15 +00:00
|
|
|
SignalHandler &sigh = SignalHandler::instance();
|
|
|
|
|
2002-12-01 13:42:15 +00:00
|
|
|
IntSig handler;
|
|
|
|
AllSig allhand;
|
2002-08-14 00:01:57 +00:00
|
|
|
|
2004-05-02 21:27:15 +00:00
|
|
|
sigh.registerHandler(SIGINT, &handler);
|
|
|
|
sigh.registerHandler(SIGSEGV, &allhand);
|
|
|
|
sigh.registerHandler(SIGTERM, &allhand);
|
|
|
|
sigh.registerHandler(SIGUSR1, &allhand);
|
|
|
|
sigh.registerHandler(SIGUSR2, &allhand);
|
|
|
|
|
2002-12-01 13:42:15 +00:00
|
|
|
cerr<<"Send signals to me :)"<<endl;
|
|
|
|
while (1) {
|
2002-08-14 00:01:57 +00:00
|
|
|
|
2002-12-01 13:42:15 +00:00
|
|
|
}
|
2002-08-14 00:01:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|