diff options
-rw-r--r-- | byterun/signals.c | 87 | ||||
-rwxr-xr-x | config/autoconf | 21 | ||||
-rw-r--r-- | otherlibs/graph/open.c | 2 | ||||
-rw-r--r-- | otherlibs/unix/kill.c | 2 |
4 files changed, 67 insertions, 45 deletions
diff --git a/byterun/signals.c b/byterun/signals.c index e585b4931..27c17e80e 100644 --- a/byterun/signals.c +++ b/byterun/signals.c @@ -36,9 +36,11 @@ static void execute_signal(signal_number) void handle_signal(signal_number) int signal_number; { +#ifndef POSIX_SIGNALS #ifndef BSD_SIGNALS signal(signal_number, handle_signal); #endif +#endif if (async_signal_mode){ leave_blocking_section (); execute_signal(signal_number); @@ -72,61 +74,61 @@ void leave_blocking_section() } #ifndef SIGABRT -#define SIGABRT 0 +#define SIGABRT -1 #endif #ifndef SIGALRM -#define SIGALRM 0 +#define SIGALRM -1 #endif #ifndef SIGFPE -#define SIGFPE 0 +#define SIGFPE -1 #endif #ifndef SIGHUP -#define SIGHUP 0 +#define SIGHUP -1 #endif #ifndef SIGILL -#define SIGILL 0 +#define SIGILL -1 #endif #ifndef SIGINT -#define SIGINT 0 +#define SIGINT -1 #endif #ifndef SIGKILL -#define SIGKILL 0 +#define SIGKILL -1 #endif #ifndef SIGPIPE -#define SIGPIPE 0 +#define SIGPIPE -1 #endif #ifndef SIGQUIT -#define SIGQUIT 0 +#define SIGQUIT -1 #endif #ifndef SIGSEGV -#define SIGSEGV 0 +#define SIGSEGV -1 #endif #ifndef SIGTERM -#define SIGTERM 0 +#define SIGTERM -1 #endif #ifndef SIGUSR1 -#define SIGUSR1 0 +#define SIGUSR1 -1 #endif #ifndef SIGUSR2 -#define SIGUSR2 0 +#define SIGUSR2 -1 #endif #ifndef SIGCHLD -#define SIGCHLD 0 +#define SIGCHLD -1 #endif #ifndef SIGCONT -#define SIGCONT 0 +#define SIGCONT -1 #endif #ifndef SIGSTOP -#define SIGSTOP 0 +#define SIGSTOP -1 #endif #ifndef SIGTSTP -#define SIGTSTP 0 +#define SIGTSTP -1 #endif #ifndef SIGTTIN -#define SIGTTIN 0 +#define SIGTTIN -1 #endif #ifndef SIGTTOU -#define SIGTTOU 0 +#define SIGTTOU -1 #endif int posix_signals[] = { @@ -135,37 +137,52 @@ int posix_signals[] = { SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU }; +#ifndef NSIG +#define NSIG 32 +#endif + value install_signal_handler(signal_number, action) /* ML */ value signal_number, action; { - int sig = Int_val(signal_number); - if (sig < 0) { - sig = posix_signals[-sig-1]; - if (sig == 0) invalid_argument("Sys.signal: unavailable signal"); - } - switch(Tag_val(action)) { - case 0: /* Signal_default */ - signal(sig, SIG_DFL); + int sig; + void (*act)(); +#ifdef POSIX_SIGNALS + struct sigaction sigact; +#endif + + sig = Int_val(signal_number); + if (sig < 0) sig = posix_signals[-sig-1]; + if (sig < 0 || sig >= NSIG) + invalid_argument("Sys.signal: unavailable signal"); + switch(action) { + case Val_int(0): /* Signal_default */ + act = SIG_DFL; break; - case 1: /* Signal_ignore */ - signal(sig, SIG_IGN); + case Val_int(1): /* Signal_ignore */ + act = SIG_IGN; break; - case 2: /* Signal_handle */ + default: /* Signal_handle */ if (signal_handlers == 0) { int i; Push_roots(r, 1); r[0] = action; - signal_handlers = alloc_tuple(32); + signal_handlers = alloc_tuple(NSIG); action = r[0]; Pop_roots(); - for (i = 0; i < 32; i++) Field(signal_handlers, i) = Val_int(0); + for (i = 0; i < NSIG; i++) Field(signal_handlers, i) = Val_int(0); register_global_root(&signal_handlers); } modify(&Field(signal_handlers, sig), Field(action, 0)); - signal(sig, handle_signal); + act = handle_signal; break; - default: - Assert(0); } +#ifdef POSIX_SIGNALS + sigact.sa_handler = act; + sigemptyset(&sigact.sa_mask); + sigact.sa_flags = 0; + sigaction(sig, &sigact, NULL); +#else + signal(sig, act); +#endif return Val_unit; } diff --git a/config/autoconf b/config/autoconf index 91f876a75..53566af7b 100755 --- a/config/autoconf +++ b/config/autoconf @@ -26,7 +26,7 @@ touch s.h m.h Makefile.h # Check the sizes of data types echo "Checking the sizes of integers and pointers..." -set `sh ./runtest sizes.c` +set `sh runtest sizes.c` case "$1,$2,$3" in 4,4,4) echo "OK, this is a regular 32 bit architecture.";; 4,8,8) echo "Wow! A 64 bit architecture!" @@ -51,7 +51,7 @@ esac # Determine endianness -sh ./runtest endian.c +sh runtest endian.c case $? in 0) echo "This is a big-endian architecture." echo "#define BIG_ENDIAN" >> m.h;; @@ -67,7 +67,7 @@ esac # Determine alignment constraints -sh ./runtest dblalign.c +sh runtest dblalign.c case $? in 0) echo "Doubles can be word-aligned.";; 1) echo "Doubles must be doubleword-aligned." @@ -81,18 +81,18 @@ esac # Find a good byte move function -if sh ./runtest -Dcopy=memmove -Dreverse bytecopy.c; then +if sh runtest -Dcopy=memmove -Dreverse bytecopy.c; then echo "Function \"memmove\" is provided and handles overlapping moves correctly." echo "#define HAS_MEMMOVE" >> s.h fi -if sh ./runtest -Dcopy=bcopy bytecopy.c; then +if sh runtest -Dcopy=bcopy bytecopy.c; then echo "Function \"bcopy\" is provided and handles overlapping moves correctly." echo "#define HAS_BCOPY" >> s.h fi # Check for _longjmp and _setjmp -sh ./runtest setjmp.c +sh runtest setjmp.c case $? in 0) echo "_setjmp and _longjmp appear to work. Good!" echo "#define HAS__SETJMP" >> s.h;; @@ -101,7 +101,10 @@ esac # Check the semantics of signal handlers -if sh ./runtest signals.c; then +if sh hasgot sigaction sigprocmask; then + echo "POSIX signal handling found." + echo "#define POSIX_SIGNALS" >> s.h +elif sh runtest signals.c; then echo "Signals have the BSD semantics." echo "#define BSD_SIGNALS" >> s.h else @@ -203,7 +206,7 @@ if sh hasgot waitpid; then echo "#define HAS_WAITPID" >> s.h fi -if test -f /usr/include/sys/param.h && sh ./runtest getgroups.c; then +if test -f /usr/include/sys/param.h && sh runtest getgroups.c; then echo "getgroups() found." echo "#define HAS_GETGROUPS" >> s.h fi @@ -221,7 +224,7 @@ if test -f /usr/bin/uname; then "OSF1 V3."*) testasyncio=false;; esac fi -if $testasyncio && sh ./runtest async_io.c; then +if $testasyncio && sh runtest async_io.c; then echo "Asynchronous I/O are supported." echo "#define HAS_ASYNC_IO" >> s.h fi diff --git a/otherlibs/graph/open.c b/otherlibs/graph/open.c index 3906ae29e..a2b605a8a 100644 --- a/otherlibs/graph/open.c +++ b/otherlibs/graph/open.c @@ -130,6 +130,7 @@ value gr_open_graph(arg) /* If possible, request that system calls be restarted after the EVENT_SIGNAL signal. */ +#ifdef POSIX_SIGNALS #ifdef SA_RESTART { struct sigaction action; sigaction(EVENT_SIGNAL, NULL, &action); @@ -137,6 +138,7 @@ value gr_open_graph(arg) sigaction(EVENT_SIGNAL, &action, NULL); } #endif +#endif #ifdef USE_ASYNC_IO /* If BSD-style asynchronous I/O are supported: diff --git a/otherlibs/unix/kill.c b/otherlibs/unix/kill.c index d9ff474bc..de84a044f 100644 --- a/otherlibs/unix/kill.c +++ b/otherlibs/unix/kill.c @@ -25,7 +25,7 @@ value unix_kill(pid, signal) /* ML */ sig = Int_val(signal); if (sig < 0) { sig = posix_signals[-sig-1]; - if (sig == 0) invalid_argument("Unix.kill: unavailable signal"); + if (sig < 0) invalid_argument("Sys.signal: unavailable signal"); } if (kill(Int_val(pid), sig) == -1) uerror("kill", Nothing); |