From 4afe7caf6b5899c7865a05daea96b542c7da293d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Tue, 8 May 2012 17:15:54 +0000 Subject: [PATCH] [INTERPRETER] * BUG: Disable debugging messages from signal management routines. [GB.SIGNAL] * NEW: Call previous signal handlers automatically when a specific signal is catched. git-svn-id: svn://localhost/gambas/trunk@4722 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- main/gbx/gbx_signal.c | 14 ++++++++++++-- main/lib/signal/csignal.c | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/main/gbx/gbx_signal.c b/main/gbx/gbx_signal.c index e6ffb89f1..fcd89c5da 100644 --- a/main/gbx/gbx_signal.c +++ b/main/gbx/gbx_signal.c @@ -28,6 +28,8 @@ #include "gbx_api.h" #include "gbx_signal.h" +//#define DEBUG_ME 1 + static SIGNAL_HANDLER *_handlers = NULL; static int _pipe[2]; static int _count = 0; @@ -36,8 +38,10 @@ void SIGNAL_install(SIGNAL_HANDLER *handler, int signum, void (*callback)(int, s { struct sigaction action; + #ifdef DEBUG_ME fprintf(stderr, "SIGNAL_install: %d %p\n", signum, callback); - + #endif + handler->signum = signum; action.sa_flags = SA_SIGINFO; @@ -50,8 +54,10 @@ void SIGNAL_install(SIGNAL_HANDLER *handler, int signum, void (*callback)(int, s void SIGNAL_uninstall(SIGNAL_HANDLER *handler, int signum) { + #ifdef DEBUG_ME fprintf(stderr, "SIGNAL_uninstall: %d\n", signum); - + #endif + while (handler->callbacks) SIGNAL_unregister(handler->signum, handler->callbacks); @@ -172,7 +178,9 @@ SIGNAL_CALLBACK *SIGNAL_register(int signum, void (*callback)(int, intptr_t), in cb->callback = callback; cb->data = data; + #ifdef DEBUG_ME fprintf(stderr, "SIGNAL_register: %d -> %p\n", signum, cb); + #endif return cb; } @@ -193,7 +201,9 @@ void SIGNAL_unregister(int signum, SIGNAL_CALLBACK *cb) if (cb == handler->callbacks) handler->callbacks = cb->next; + #ifdef DEBUG_ME fprintf(stderr, "SIGNAL_unregister: %d %p\n", signum, cb); + #endif FREE(&cb, "SIGNAL_unregister_callback"); diff --git a/main/lib/signal/csignal.c b/main/lib/signal/csignal.c index ef1feb224..c4a2bfec0 100644 --- a/main/lib/signal/csignal.c +++ b/main/lib/signal/csignal.c @@ -182,9 +182,40 @@ static void add_handler(int num, struct sigaction *action) static void handle_signal(int num, siginfo_t *info, void *context) { + SIGNAL_HANDLER *sh; char cnum = (char)num; - if (write(_pipe_signal[1], &cnum, 1) != 1) - return; + int save_errno; + + save_errno = errno; + + for(;;) + { + if (write(_pipe_signal[1], &cnum, 1) == 1) + break; + + if (errno != EINTR) + break; + } + + // Call old signal handler + + sh = find_handler(num); + + if (sh->action.sa_handler != SIG_DFL && sh->action.sa_handler != SIG_IGN) + { + if (sh->action.sa_flags & SA_SIGINFO) + { + //fprintf(stderr, "Calling old action %p\n", _old_SIGCHLD_action.sa_sigaction); + (*sh->action.sa_sigaction)(num, info, context); + } + else + { + //fprintf(stderr, "Calling old handler %p\n", _old_SIGCHLD_action.sa_handler); + (*sh->action.sa_handler)(num); + } + } + + errno = save_errno; } BEGIN_METHOD_VOID(Signal_Reset)