Date: Sun, 21 Dec 2014 23:10:00 +0000 (UTC) From: Jilles Tjoelker <jilles@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r276038 - head/bin/sh Message-ID: <201412212310.sBLNA0jX026257@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jilles Date: Sun Dec 21 23:09:59 2014 New Revision: 276038 URL: https://svnweb.freebsd.org/changeset/base/276038 Log: sh: Move some code from onint() to onsig(), making onint() noreturn. As a result, the INTON macro which is used many times generates fewer bytes of code. Modified: head/bin/sh/error.c head/bin/sh/error.h head/bin/sh/trap.c head/bin/sh/trap.h Modified: head/bin/sh/error.c ============================================================================== --- head/bin/sh/error.c Sun Dec 21 22:18:30 2014 (r276037) +++ head/bin/sh/error.c Sun Dec 21 23:09:59 2014 (r276038) @@ -90,13 +90,14 @@ exraise(int e) /* - * Called from trap.c when a SIGINT is received. (If the user specifies - * that SIGINT is to be trapped or ignored using the trap builtin, then - * this routine is not called.) Suppressint is nonzero when interrupts - * are held using the INTOFF macro. If SIGINTs are not suppressed and - * the shell is not a root shell, then we want to be terminated if we - * get here, as if we were terminated directly by a SIGINT. Arrange for - * this here. + * Called from trap.c when a SIGINT is received and not suppressed, or when + * an interrupt is pending and interrupts are re-enabled using INTON. + * (If the user specifies that SIGINT is to be trapped or ignored using the + * trap builtin, then this routine is not called.) Suppressint is nonzero + * when interrupts are held using the INTOFF macro. If SIGINTs are not + * suppressed and the shell is not a root shell, then we want to be + * terminated if we get here, as if we were terminated directly by a SIGINT. + * Arrange for this here. */ void @@ -104,16 +105,6 @@ onint(void) { sigset_t sigs; - /* - * The !in_dotrap here is safe. The only way we can arrive here - * with in_dotrap set is that a trap handler set SIGINT to SIG_DFL - * and killed itself. - */ - - if (suppressint && !in_dotrap) { - intpending++; - return; - } intpending = 0; sigemptyset(&sigs); sigprocmask(SIG_SETMASK, &sigs, NULL); @@ -130,6 +121,7 @@ onint(void) else { signal(SIGINT, SIG_DFL); kill(getpid(), SIGINT); + _exit(128 + SIGINT); } } Modified: head/bin/sh/error.h ============================================================================== --- head/bin/sh/error.h Sun Dec 21 22:18:30 2014 (r276037) +++ head/bin/sh/error.h Sun Dec 21 23:09:59 2014 (r276038) @@ -75,11 +75,12 @@ extern volatile sig_atomic_t intpending; #define is_int_on() suppressint #define SETINTON(s) suppressint = (s) #define FORCEINTON {suppressint = 0; if (intpending) onint();} +#define SET_PENDING_INT intpending = 1 #define CLEAR_PENDING_INT intpending = 0 #define int_pending() intpending void exraise(int) __dead2; -void onint(void); +void onint(void) __dead2; void warning(const char *, ...) __printflike(1, 2); void error(const char *, ...) __printf0like(1, 2) __dead2; void exerror(int, const char *, ...) __printf0like(2, 3) __dead2; Modified: head/bin/sh/trap.c ============================================================================== --- head/bin/sh/trap.c Sun Dec 21 22:18:30 2014 (r276037) +++ head/bin/sh/trap.c Sun Dec 21 23:09:59 2014 (r276038) @@ -75,7 +75,7 @@ __FBSDID("$FreeBSD$"); static char sigmode[NSIG]; /* current value of signal */ volatile sig_atomic_t pendingsig; /* indicates some signal received */ volatile sig_atomic_t pendingsig_waitcmd; /* indicates SIGINT/SIGQUIT received */ -int in_dotrap; /* do we execute in a trap handler? */ +static int in_dotrap; /* do we execute in a trap handler? */ static char *volatile trap[NSIG]; /* trap handler commands */ static volatile sig_atomic_t gotsig[NSIG]; /* indicates specified signal received */ @@ -380,7 +380,15 @@ onsig(int signo) { if (signo == SIGINT && trap[SIGINT] == NULL) { - onint(); + /* + * The !in_dotrap here is safe. The only way we can arrive + * here with in_dotrap set is that a trap handler set SIGINT to + * SIG_DFL and killed itself. + */ + if (suppressint && !in_dotrap) + SET_PENDING_INT; + else + onint(); return; } Modified: head/bin/sh/trap.h ============================================================================== --- head/bin/sh/trap.h Sun Dec 21 22:18:30 2014 (r276037) +++ head/bin/sh/trap.h Sun Dec 21 23:09:59 2014 (r276038) @@ -35,7 +35,6 @@ extern volatile sig_atomic_t pendingsig; extern volatile sig_atomic_t pendingsig_waitcmd; -extern int in_dotrap; void clear_traps(void); int have_traps(void);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201412212310.sBLNA0jX026257>