From cfb1e34b08d9b72751fbf338e273f6797ede4d7b Mon Sep 17 00:00:00 2001 From: mainzelm Date: Thu, 21 Dec 2000 13:25:21 +0000 Subject: [PATCH] Rewrote signal checks and added handler for all scsh interrupts. --- c/unix/event.c | 207 +++++++++++++++--------------------------------- scsh/scsh_aux.c | 83 +++++++++---------- 2 files changed, 108 insertions(+), 182 deletions(-) diff --git a/c/unix/event.c b/c/unix/event.c index 9a69f8f..0e9820b 100644 --- a/c/unix/event.c +++ b/c/unix/event.c @@ -13,6 +13,8 @@ #include "c-mods.h" #include "scheme48vm.h" #include "event.h" +#include "../scsh/scsh_aux.h" +#include "../scsh/signals1.h" /* turning interrupts and I/O readiness into events */ @@ -25,18 +27,7 @@ static void when_alarm_interrupt(); static void when_sigpipe_interrupt(); //JMG: -static void when_child_interrupt(); -static void when_hup_interrupt(); -static void when_cont_interrupt(); -static void when_quit_interrupt(); -static void when_term_interrupt(); -static void when_tstp_interrupt(); -static void when_usr1_interrupt(); -static void when_usr2_interrupt(); - - - - +static void when_scsh_interrupt(); bool s48_setcatcher(int signum, void (*catcher)(int)); @@ -56,13 +47,42 @@ s48_sysdep_init(void) } //JMG: for scsh - if (!s48_setcatcher(SIGCHLD, when_child_interrupt) - || !s48_setcatcher(SIGHUP, when_hup_interrupt)) { - fprintf(stderr, - "Failed to install signal handler for SIGCHLD, errno = %d\n", - errno); - exit(1); - } + s48_setcatcher(SIGCHLD, when_scsh_interrupt); + s48_setcatcher(SIGCONT, when_scsh_interrupt); + s48_setcatcher(SIGHUP, when_scsh_interrupt); + s48_setcatcher(SIGQUIT, when_scsh_interrupt); + s48_setcatcher(SIGTERM, when_scsh_interrupt); + s48_setcatcher(SIGTSTP, when_scsh_interrupt); + s48_setcatcher(SIGUSR1, when_scsh_interrupt); + s48_setcatcher(SIGUSR2, when_scsh_interrupt); +#ifdef SIGINFO + s48_setcatcher(SIGINFO, when_scsh_interrupt); +#endif +#ifdef SIGIO + s48_setcatcher(SIGIO, when_scsh_interrupt); +#endif +#ifdef SIGPOLL + s48_setcatcher(SIGPOLL, when_scsh_interrupt); +#endif +#ifdef SIGPROF + s48_setcatcher(SIGPROF, when_scsh_interrupt); +#endif +#ifdef SIGPWR + s48_setcatcher(SIGPWR, when_scsh_interrupt); +#endif +#ifdef SIGVTALRM + s48_setcatcher(SIGVTALRM, when_scsh_interrupt); +#endif +#ifdef SIGWINCH + s48_setcatcher(SIGWINCH, when_scsh_interrupt); +#endif +#ifdef SIGXCPU + s48_setcatcher(SIGXCPU, when_scsh_interrupt); +#endif +#ifdef SIGXFSZ + s48_setcatcher(SIGXFSZ, when_scsh_interrupt); +#endif + s48_start_alarm_interrupts(); } @@ -76,15 +96,21 @@ s48_setcatcher(int signum, void (*catcher)(int)) { struct sigaction sa; - if (sigaction(signum, (struct sigaction *)NULL, &sa) != 0) - return (FALSE); - if (sa.sa_handler == SIG_IGN) - return (TRUE); + if (sigaction(signum, (struct sigaction *)NULL, &sa) != 0){ + fprintf(stderr, "Failed to get sigaction for signal %d\n", signum); + exit(1); + } + // JMG: what's the point of not setting the handler in this case? + // if (sa.sa_handler == SIG_IGN) + // return (TRUE); sa.sa_handler = catcher; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; - if (sigaction(signum, &sa, (struct sigaction *)NULL) != 0) - return (FALSE); + if (sigaction(signum, &sa, (struct sigaction *)NULL) != 0){ + fprintf(stderr, "Failed to define handler for signal %d\n", signum); + exit(1); + } + return (TRUE); } @@ -617,88 +643,18 @@ queue_ready_ports(bool wait, long seconds, long ticks) //JMG: for scsh -static int child_interrupt_count = 0; +static long interrupt_count[32]; -static void -when_child_interrupt(int ign) +static void when_scsh_interrupt(int signo) { - child_interrupt_count += 1; + interrupt_count[sig2int[signo]] +=1; NOTE_EVENT; return; } -static int hup_interrupt_count = 0; - -static void -when_hup_interrupt(int ign) -{ - hup_interrupt_count += 1; - NOTE_EVENT; - return; -} - -static int cont_interrupt_count = 0; - -static void -when_cont_interrupt(int ign) -{ - cont_interrupt_count += 1; - NOTE_EVENT; - return; -} - -static int quit_interrupt_count = 0; - -static void -when_quit_interrupt(int ign) -{ - quit_interrupt_count += 1; - NOTE_EVENT; - return; -} - -static int term_interrupt_count = 0; - -static void -when_term_interrupt(int ign) -{ - term_interrupt_count += 1; - NOTE_EVENT; - return; -} -static int tstp_interrupt_count = 0; - -static void -when_tstp_interrupt(int ign) -{ - tstp_interrupt_count += 1; - NOTE_EVENT; - return; -} -static int usr1_interrupt_count = 0; - -static void -when_usr1_interrupt(int ign) -{ - usr1_interrupt_count += 1; - NOTE_EVENT; - return; -} -static int usr2_interrupt_count = 0; - -static void -when_usr2_interrupt(int ign) -{ - usr2_interrupt_count += 1; - NOTE_EVENT; - return; -} - - /* - * This procedure is called periodically by the VM (if you uncomment the - * call to it in s48_get_next_event() in c/unix/event.c). + * This procedure is called periodically by the VM . * * s48_set_os_signal() is a VM procedure. The two arguments are the type * of interrupt and one other value which can be used to return whatever @@ -718,50 +674,19 @@ when_usr2_interrupt(int ign) * The handler is called with all interrupts disabled. They are * reenabled when the handler returns (or if done by hand). */ -enum scsh_os_signal{ - scsh_os_signal_io_completion, - scsh_os_signal_post_gc, - scsh_os_signal_keyboard, - scsh_os_signal_alarm, - scsh_os_signal_chld , - scsh_os_signal_cont, - scsh_os_signal_hup, - scsh_os_signal_quit, - scsh_os_signal_term, - scsh_os_signal_tstp, - scsh_os_signal_usr1, - scsh_os_signal_usr2, - scsh_os_signal_info, - scsh_os_signal_io, - scsh_os_signal_poll, - scsh_os_signal_prof, - scsh_os_signal_pwr, - scsh_os_signal_urg, - scsh_os_signal_vtalrm, - scsh_os_signal_winch, - scsh_os_signal_xcpu, - scsh_os_signal_xfsz -}; int s48_os_signal_pending(void) { - if (child_interrupt_count > 0) { - // fprintf(stderr, "cld c %d", child_interrupt_count); - block_interrupts(); - --child_interrupt_count; - allow_interrupts(); - s48_set_os_signal(S48_UNSAFE_ENTER_FIXNUM(scsh_os_signal_chld), - S48_UNSAFE_ENTER_FIXNUM(SIGCHLD)); - return TRUE; + int i; + for (i = 0; i < max_sig; i++){ + if (interrupt_count[i] > 0){ + block_interrupts(); + --interrupt_count[i]; + allow_interrupts(); + s48_set_os_signal(S48_UNSAFE_ENTER_FIXNUM(i), + S48_UNSAFE_ENTER_FIXNUM(0)); + return TRUE; + } } - else if (hup_interrupt_count > 0){ - fprintf(stderr, "hup c %d", hup_interrupt_count); - block_interrupts(); - --hup_interrupt_count; - allow_interrupts(); - s48_set_os_signal(S48_UNSAFE_ENTER_FIXNUM(scsh_os_signal_hup), - S48_UNSAFE_ENTER_FIXNUM(SIGHUP)); - return TRUE; - } - else return FALSE; + return FALSE; } diff --git a/scsh/scsh_aux.c b/scsh/scsh_aux.c index 12a5c3b..da0a1f5 100644 --- a/scsh/scsh_aux.c +++ b/scsh/scsh_aux.c @@ -1,53 +1,54 @@ +/* Copyright (c) 2000 by Martin Gasbichler + See file COPYING. */ + #include "scsh_aux.h" #include -#ifndef SIGURG - #define SIGURG 9999 -#endif -#ifndef SIGXCPU - #define SIGXCPU 9999 -#endif -#ifndef SIGXFSZ - #define SIGXFSZ 9999 -#endif -#ifndef SIGVTALRM - #define SIGVTALRM 9999 -#endif -#ifndef SIGPROF - #define SIGPROF 9999 -#endif -#ifndef SIGWINCH - #define SIGWINCH 9999 -#endif -#ifndef SIGIO - #define SIGIO 9999 -#endif -#ifndef SIGPWR - #define SIGPWR 9999 -#endif int main(int argc, char* argv[]){ int signr = atoi(argv[1]); switch (signr) { - case SIGHUP : printf("scshint_hup"); break; - case SIGINT : printf("scshint_keyboard"); break; - case SIGQUIT : printf("scshint_quit"); break; - case SIGUSR1 : printf("scshint_usr1"); break; - case SIGUSR2 : printf("scshint_usr2"); break; - case SIGALRM : printf("scshint_alarm"); break; - case SIGTERM : printf("scshint_term"); break; - case SIGCHLD : printf("scshint_chld"); break; - case SIGCONT : printf("scshint_cont"); break; - case SIGTSTP : printf("scshint_tstp"); break; - case SIGURG : printf("scshint_urg"); break; - case SIGXCPU : printf("scshint_xcpu"); break; - case SIGXFSZ : printf("scshint_xfsz"); break; + case SIGINT : printf("scshint_keyboard"); break; + case SIGALRM : printf("scshint_alarm"); break; + case SIGCHLD : printf("scshint_chld"); break; + case SIGCONT : printf("scshint_cont"); break; + case SIGHUP : printf("scshint_hup"); break; + case SIGQUIT : printf("scshint_quit"); break; + case SIGTERM : printf("scshint_term"); break; + case SIGTSTP : printf("scshint_tstp"); break; + case SIGUSR1 : printf("scshint_usr1"); break; + case SIGUSR2 : printf("scshint_usr2"); break; +#ifdef SIGINFO + case SIGINFO : printf("scshint_info"); break; +#endif +#ifdef SIGIO + case SIGIO : printf("scshint_io"); break; +#endif +#ifdef SIGPOLL + case SIGPOLL : printf("scshint_poll"); break; +#endif +#ifdef SIGPROF + case SIGPROF : printf("scshint_prof"); break; +#endif +#ifdef SIGPWR + case SIGPWR : printf("scshint_pwr"); break; +#endif +#ifdef SIGURG + case SIGURG : printf("scshint_urg"); break; +#endif +#ifdef SIGVTALRM case SIGVTALRM : printf("scshint_vtalrm"); break; - case SIGPROF : printf("scshint_prof"); break; - case SIGWINCH : printf("scshint_winch"); break; - case SIGIO : printf("scshint_io"); break;/* aka SIGPOLL*/ - case SIGPWR : printf("scshint_pwr"); break; +#endif +#ifdef SIGWINCH + case SIGWINCH : printf("scshint_winch"); break; +#endif +#ifdef SIGXCPU + case SIGXCPU : printf("scshint_xcpu"); break; +#endif +#ifdef SIGXFSZ + case SIGXFSZ : printf("scshint_xfsz"); break; +#endif default: printf("-1");} return 0;