Showing
2 changed files
with
44 additions
and
4 deletions
| @@ -21,6 +21,8 @@ | @@ -21,6 +21,8 @@ | ||
| 21 | */ | 21 | */ |
| 22 | 22 | ||
| 23 | #include <stdint.h> | 23 | #include <stdint.h> |
| 24 | +#include <signal.h> | ||
| 25 | +#include <stdio.h> | ||
| 24 | 26 | ||
| 25 | #include "trbase.h" | 27 | #include "trbase.h" |
| 26 | #include "trdata.h" | 28 | #include "trdata.h" |
| @@ -28,6 +30,35 @@ | @@ -28,6 +30,35 @@ | ||
| 28 | #include "tr/event_handler.h" | 30 | #include "tr/event_handler.h" |
| 29 | #include "tr/event_dispatcher.h" | 31 | #include "tr/event_dispatcher.h" |
| 30 | 32 | ||
| 33 | +volatile TR_EventDispatcher _TR_controlDispatcher; | ||
| 34 | + | ||
| 35 | +static | ||
| 36 | +void | ||
| 37 | +terminate(int signum) | ||
| 38 | +{ | ||
| 39 | + signal(signum, SIG_IGN); | ||
| 40 | + /* | ||
| 41 | + * \todo do logging here | ||
| 42 | + */ | ||
| 43 | + puts("signal ... go"); | ||
| 44 | + TR_eventDispatcherShutdown(_TR_controlDispatcher); | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +static | ||
| 48 | +void | ||
| 49 | +init_signals(void) | ||
| 50 | +{ | ||
| 51 | + signal(SIGTERM, terminate); | ||
| 52 | + signal(SIGHUP, SIG_IGN); | ||
| 53 | + signal(SIGINT, terminate); | ||
| 54 | + signal(SIGQUIT, terminate); | ||
| 55 | + signal(SIGABRT, terminate); | ||
| 56 | + signal(SIGALRM, SIG_IGN); | ||
| 57 | + signal(SIGURG, SIG_IGN); | ||
| 58 | + | ||
| 59 | + signal(SIGPIPE, SIG_IGN); | ||
| 60 | +} | ||
| 61 | + | ||
| 31 | static | 62 | static |
| 32 | int | 63 | int |
| 33 | eventDispatcherCtor(void * _this, va_list * params) { | 64 | eventDispatcherCtor(void * _this, va_list * params) { |
| @@ -41,6 +72,11 @@ eventDispatcherCtor(void * _this, va_list * params) { | @@ -41,6 +72,11 @@ eventDispatcherCtor(void * _this, va_list * params) { | ||
| 41 | this->heartbeat = 0; | 72 | this->heartbeat = 0; |
| 42 | this->nextbeat = 0; | 73 | this->nextbeat = 0; |
| 43 | 74 | ||
| 75 | + if (! _TR_controlDispatcher) { | ||
| 76 | + _TR_controlDispatcher = this; | ||
| 77 | + init_signals(); | ||
| 78 | + } | ||
| 79 | + | ||
| 44 | return 0; | 80 | return 0; |
| 45 | } | 81 | } |
| 46 | 82 |
| @@ -39,13 +39,17 @@ doRegister(const void * _node, const void * data) | @@ -39,13 +39,17 @@ doRegister(const void * _node, const void * data) | ||
| 39 | handler_queue_hv = TR_hashGetByVal(dispatcher->handler, node->hash); | 39 | handler_queue_hv = TR_hashGetByVal(dispatcher->handler, node->hash); |
| 40 | 40 | ||
| 41 | if (handler_queue_hv) { | 41 | if (handler_queue_hv) { |
| 42 | - handler_queue = (TR_Queue)handler_queue_hv->value; | 42 | + handler_queue = *(TR_Queue *)handler_queue_hv->value; |
| 43 | } else { | 43 | } else { |
| 44 | handler_queue = TR_new(TR_Queue); | 44 | handler_queue = TR_new(TR_Queue); |
| 45 | handler_queue->free_msgs = 0; | 45 | handler_queue->free_msgs = 0; |
| 46 | - TR_hashAdd( | ||
| 47 | - dispatcher->handler, | ||
| 48 | - TR_new(TR_HashValue, node->key, node->nkey, &handler_queue, sizeof(TR_Queue))); | 46 | + handler_queue_hv = TR_new( |
| 47 | + TR_HashValue, | ||
| 48 | + node->key, | ||
| 49 | + node->nkey, | ||
| 50 | + &handler_queue, | ||
| 51 | + sizeof(TR_Queue)); | ||
| 52 | + TR_hashAdd(dispatcher->handler, handler_queue_hv); | ||
| 49 | } | 53 | } |
| 50 | 54 | ||
| 51 | TR_queuePut(handler_queue, current_handler); | 55 | TR_queuePut(handler_queue, current_handler); |
Please
register
or
login
to post a comment