diff options
author | H. Peter Anvin <hpa@zytor.com> | 2002-08-17 07:18:33 +0000 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2002-08-17 07:18:33 +0000 |
commit | e2d728a3d0c60a1aa72dcb785027abd38918ced8 (patch) | |
tree | ad2d3664379f98b19e8c96a763383bc6ce8e54de | |
parent | a794998b4bcd3fe5c956d0ddb81156433443a8d0 (diff) | |
download | klibc-e2d728a3d0c60a1aa72dcb785027abd38918ced8.tar.gz |
Create own bsd_signal() stub.klibc-0.46
-rw-r--r-- | ash/Makefile | 4 | ||||
-rw-r--r-- | ash/main.c | 2 | ||||
-rw-r--r-- | ash/redir.c | 10 | ||||
-rw-r--r-- | ash/trap.c | 24 | ||||
-rw-r--r-- | ash/trap.h | 3 |
5 files changed, 30 insertions, 13 deletions
diff --git a/ash/Makefile b/ash/Makefile index 5fc5912ad0adc..0f55e2233eb9c 100644 --- a/ash/Makefile +++ b/ash/Makefile @@ -1,5 +1,3 @@ -# Makefile,v 1.7 1993/08/09 04:58:18 mycroft Exp - PROG= sh SRCS= builtins.c cd.c dirent.c bltin/echo.c error.c eval.c exec.c expand.c \ input.c jobs.c mail.c main.c memalloc.c miscbltin.c \ @@ -26,7 +24,7 @@ STRIP = strip -R .comment -R .note HOST_CC = gcc HOST_CFLAGS = -g -I. -DSHELL -HOST_LDFLAGS = -s +HOST_LDFLAGS = HOST_LIBS = CLEANFILES =\ diff --git a/ash/main.c b/ash/main.c index 704254c19e5a1..8b3b5b0789b77 100644 --- a/ash/main.c +++ b/ash/main.c @@ -105,7 +105,7 @@ main(argc, argv) char **argv; { monitor(4, etext, profile_buf, sizeof profile_buf, 50); #endif #ifdef linux - signal(SIGCHLD,SIG_DFL); + bsd_signal(SIGCHLD,SIG_DFL); #endif /* linux */ state = 0; if (setjmp(jmploc.loc)) { diff --git a/ash/redir.c b/ash/redir.c index c2105248637ef..24c4ceaa9bcf6 100644 --- a/ash/redir.c +++ b/ash/redir.c @@ -231,13 +231,13 @@ openhere(redir) } if (forkshell((struct job *)NULL, (union node *)NULL, FORK_NOJOB) == 0) { close(pip[0]); - signal(SIGINT, SIG_IGN); - signal(SIGQUIT, SIG_IGN); - signal(SIGHUP, SIG_IGN); + bsd_signal(SIGINT, SIG_IGN); + bsd_signal(SIGQUIT, SIG_IGN); + bsd_signal(SIGHUP, SIG_IGN); #ifdef SIGTSTP - signal(SIGTSTP, SIG_IGN); + bsd_signal(SIGTSTP, SIG_IGN); #endif - signal(SIGPIPE, SIG_DFL); + bsd_signal(SIGPIPE, SIG_DFL); if (redir->type == NHERE) xwrite(pip[1], redir->nhere.doc->narg.text, len); else diff --git a/ash/trap.c b/ash/trap.c index 09f619e04f519..f36c1b09ed259 100644 --- a/ash/trap.c +++ b/ash/trap.c @@ -188,7 +188,7 @@ setsignal(signo) { * There is a race condition here if action is not S_IGN. * A signal can be ignored that shouldn't be. */ - if ((int)(sigact = signal(signo, SIG_IGN)) == -1) + if ((int)(sigact = bsd_signal(signo, SIG_IGN)) == -1) error("Signal system call failed"); if (sigact == SIG_IGN) { *t = S_HARD_IGN; @@ -204,7 +204,7 @@ setsignal(signo) { case S_IGN: sigact = SIG_IGN; break; } *t = action; - return (int)signal(signo, sigact); + return (int)bsd_signal(signo, sigact); } @@ -215,7 +215,7 @@ setsignal(signo) { void ignoresig(signo) { if (sigmode[signo] != S_IGN && sigmode[signo] != S_HARD_IGN) { - signal(signo, SIG_IGN); + bsd_signal(signo, SIG_IGN); } sigmode[signo] = S_HARD_IGN; } @@ -244,7 +244,7 @@ SHELLPROC { void onsig(signo) { - signal(signo, onsig); + bsd_signal(signo, onsig); if (signo == SIGINT && trap[SIGINT] == NULL) { onint(); return; @@ -325,3 +325,19 @@ l1: handler = &loc2; /* probably unnecessary */ #endif l2: _exit(status); } + +/* + * Emulation of the BSD signal() call + */ +__sighandler_t bsd_signal(int signum, __sighandler_t handler) +{ + struct sigaction act; + int rv; + + memset(&act, 0, sizeof act); + act.sa_handler = handler; + act.sa_flags = SA_RESTART; + + return sigaction(signum, &act, &act) + ? SIG_ERR : act.sa_handler; +} diff --git a/ash/trap.h b/ash/trap.h index 16e8d874063e7..a7d18d2ac532c 100644 --- a/ash/trap.h +++ b/ash/trap.h @@ -37,6 +37,8 @@ * trap.h,v 1.4 1993/08/01 18:58:34 mycroft Exp */ +#include <signal.h> + extern int pendingsigs; #ifdef __STDC__ @@ -46,6 +48,7 @@ void ignoresig(int); void dotrap(void); void setinteractive(int); void exitshell(int); +__sighandler_t bsd_signal(int, __sighandler_t); #else void clear_traps(); int setsignal(); |