Module: sems Branch: master Commit: 5a57721513506a54e0d1aa32e5025f94858831f7 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=5a57721513506a54e0d1aa32e5025f94858831f7
Author: Stefan Sayer <[email protected]> Committer: Stefan Sayer <[email protected]> Date: Wed Sep 22 16:25:24 2010 +0200 implements SIGUSR1/SIGUSR2 handling, custom use SIGUSR1/SIGUSR2 can e.g. be used in DSM calls or systemDSMs --- apps/dsm/DSMCall.cpp | 9 +++++++++ apps/dsm/DSMCall.h | 2 ++ core/AmEvent.h | 6 +++++- core/sems.cpp | 19 ++++++++++++++----- doc/dsm/examples/test_systemevents.dsm | 23 +++++++++++++++++++++++ doc/src/doc_signals.h | 1 + 6 files changed, 54 insertions(+), 6 deletions(-) diff --git a/apps/dsm/DSMCall.cpp b/apps/dsm/DSMCall.cpp index 9d0fcf7..f5002ca 100644 --- a/apps/dsm/DSMCall.cpp +++ b/apps/dsm/DSMCall.cpp @@ -332,6 +332,15 @@ void DSMCall::onSipReply(const AmSipReply& reply, int old_dlg_status, const stri } } +void DSMCall::onSystemEvent(AmSystemEvent* ev) { + map<string, string> params; + params["type"] = AmSystemEvent::getDescription(ev->sys_event); + engine.runEvent(this, this, DSMCondition::System, ¶ms); + if (params["processed"] != DSM_TRUE) { + AmB2BCallerSession::onSystemEvent(ev); + } +} + void DSMCall::process(AmEvent* event) { diff --git a/apps/dsm/DSMCall.h b/apps/dsm/DSMCall.h index c320858..b1f0bf1 100644 --- a/apps/dsm/DSMCall.h +++ b/apps/dsm/DSMCall.h @@ -85,6 +85,8 @@ public: void onSipRequest(const AmSipRequest& req); void onSipReply(const AmSipReply& reply, int old_dlg_status, const string& trans_method); + void onSystemEvent(AmSystemEvent* ev); + void process(AmEvent* event); UACAuthCred* getCredentials(); diff --git a/core/AmEvent.h b/core/AmEvent.h index a207b57..2a83dfd 100644 --- a/core/AmEvent.h +++ b/core/AmEvent.h @@ -73,7 +73,9 @@ struct AmPluginEvent: public AmEvent struct AmSystemEvent : public AmEvent { enum EvType { - ServerShutdown = 0 + ServerShutdown = 0, + User1, + User2 }; EvType sys_event; @@ -89,6 +91,8 @@ struct AmSystemEvent : public AmEvent static const char* getDescription(EvType t) { switch (t) { case ServerShutdown: return "ServerShutdown"; + case User1: return "User1"; + case User2: return "User2"; default: return "Unknown"; } } diff --git a/core/sems.cpp b/core/sems.cpp index 6d6ed18..0b52e04 100644 --- a/core/sems.cpp +++ b/core/sems.cpp @@ -201,10 +201,12 @@ static AmCondition<bool> is_shutting_down(false); static void signal_handler(int sig) { - WARN("Signal %s (%d) received.\n", strsignal(sig), sig); - - if ( sig == SIGHUP) { - AmSessionContainer::instance()->broadcastShutdown(); + if (sig == SIGUSR1 || sig == SIGUSR2) { + DBG("brodcasting User event to %u sessions...\n", + AmSession::getSessionNum()); + AmEventDispatcher::instance()-> + broadcast(new AmSystemEvent(sig == SIGUSR1? + AmSystemEvent::User1 : AmSystemEvent::User2)); return; } @@ -216,6 +218,13 @@ static void signal_handler(int sig) return; } + WARN("Signal %s (%d) received.\n", strsignal(sig), sig); + + if (sig == SIGHUP) { + AmSessionContainer::instance()->broadcastShutdown(); + return; + } + if (main_pid == getpid()) { if(!is_shutting_down.get()) { is_shutting_down.set(true); @@ -233,7 +242,7 @@ static void signal_handler(int sig) int set_sighandler(void (*handler)(int)) { static int sigs[] = { - SIGHUP, SIGPIPE, SIGINT, SIGTERM, SIGCHLD, 0 + SIGHUP, SIGPIPE, SIGINT, SIGTERM, SIGCHLD, SIGUSR1, SIGUSR2, 0 }; for (int* sig = sigs; *sig; sig++) { diff --git a/doc/dsm/examples/test_systemevents.dsm b/doc/dsm/examples/test_systemevents.dsm new file mode 100644 index 0000000..ceea01c --- /dev/null +++ b/doc/dsm/examples/test_systemevents.dsm @@ -0,0 +1,23 @@ +-- example for system events processing from script +initial state ignore_shutdown; + +transition "got USR1" ignore_shutdown - system(#type=="User1") / logParams(1) -> ignore_shutdown; +transition "got USR2, quit on shutdown" ignore_shutdown - system(#type=="User2") / logParams(1) -> quit_shutdown; +transition "got shutdown" ignore_shutdown - system(#type=="ServerShutdown") / { + logParams(1); + set(#processed="true"); +} -> ignore_shutdown; + + +state quit_shutdown; +transition "got shutdown" quit_shutdown - system(#type=="ServerShutdown") / { + logParams(1); + -- send BYE and stop + stop(true); + set(#processed="true"); + -- or we could just not set #processed, then DSM would to it +} -> end; + +state end; + +transition "hangup" (ignore_shutdown, quit_shutdown) - hangup / stop(false) -> end; diff --git a/doc/src/doc_signals.h b/doc/src/doc_signals.h index d00729d..5033b38 100644 --- a/doc/src/doc_signals.h +++ b/doc/src/doc_signals.h @@ -7,6 +7,7 @@ to the process. \li SIGHUP - broadcast shutdown, usually sends BYE and stops all calls. The server does not terminate. \li SIGTERM, SIGINT - broadcast shutdown (usually sends BYE and stops all calls), and stop. + \li SIGUSR1, SIGUSR2 - broadcast a system event with id User1 or User2, can for example be used in DSM with system(#type=="User2") condition \section see_also See also _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
