From b67de6ba172135076b3933578bf51e6966f623ec Mon Sep 17 00:00:00 2001 From: tg Date: Fri, 27 Apr 2012 16:16:23 +0000 Subject: [PATCH] add experimental code to use sigprocmask+pause+sigprocmask ipv sigsuspend (and harden j_sigchld handler for that) to improve working on BeOS 5.0 and Coherent UNIX, found by RT --- Build.sh | 5 +++-- check.t | 4 ++-- jobs.c | 28 +++++++++++++++++++++++++--- sh.h | 4 ++-- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/Build.sh b/Build.sh index 84d1f7c..34cc670 100644 --- a/Build.sh +++ b/Build.sh @@ -1,5 +1,5 @@ #!/bin/sh -srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.551 2012/04/16 17:49:40 tg Exp $' +srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.552 2012/04/27 16:16:19 tg Exp $' #- # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # 2011, 2012 @@ -1398,7 +1398,7 @@ else #define EXTERN #define MKSH_INCLUDES_ONLY #include "sh.h" - __RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.551 2012/04/16 17:49:40 tg Exp $"); + __RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.552 2012/04/27 16:16:19 tg Exp $"); int main(void) { printf("Hello, World!\n"); return (0); } EOF case $cm in @@ -2096,6 +2096,7 @@ MKSH_NO_DEPRECATED_WARNING omit warning when deprecated stuff is run MKSH_NO_EXTERNAL_CAT omit hack to skip cat builtin when flags passed MKSH_NO_LIMITS omit ulimit code MKSH_NO_SIGSETJMP define if sigsetjmp is broken or not available +MKSH_NO_SIGSUSPEND use sigprocmask+pause instead of sigsuspend MKSH_SMALL omit some code, optimise hard for size (slower) MKSH_S_NOVI=1 disable Vi editing mode (default if MKSH_SMALL) MKSH_TYPEDEF_SIG_ATOMIC_T define to e.g. 'int' if sig_atomic_t is missing diff --git a/check.t b/check.t index fd28e6b..b617e69 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.533 2012/04/22 21:50:29 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.534 2012/04/27 16:16:21 tg Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ @@ -29,7 +29,7 @@ # http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD expected-stdout: - @(#)MIRBSD KSH R40 2012/04/22 + @(#)MIRBSD KSH R40 2012/04/27 description: Check version of shell. stdin: diff --git a/jobs.c b/jobs.c index bb38997..c04ebd2 100644 --- a/jobs.c +++ b/jobs.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.84 2012/02/06 17:49:52 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.85 2012/04/27 16:16:22 tg Exp $"); #if HAVE_KILLPG #define mksh_killpg killpg @@ -1062,6 +1062,9 @@ j_waitj(Job *j, const char *where) { int rv; +#ifdef MKSH_NO_SIGSUSPEND + sigset_t omask; +#endif /* * No auto-notify on the job we are waiting on. @@ -1078,7 +1081,14 @@ j_waitj(Job *j, while (j->state == PRUNNING || ((flags & JW_STOPPEDWAIT) && j->state == PSTOPPED)) { #ifndef MKSH_NOPROSPECTOFWORK +#ifdef MKSH_NO_SIGSUSPEND + sigprocmask(SIG_SETMASK, &sm_default, &omask); + pause(); + /* note that handlers may run here so they need to know */ + sigprocmask(SIG_SETMASK, &qmask, NULL); +#else sigsuspend(&sm_default); +#endif #else j_sigchld(SIGCHLD); #endif @@ -1244,6 +1254,12 @@ j_sigchld(int sig MKSH_A_UNUSED) pid_t pid; int status; struct rusage ru0, ru1; +#ifdef MKSH_NO_SIGSUSPEND + sigset_t omask; + + /* this handler can run while SIGCHLD is not blocked, so block it now */ + sigprocmask(SIG_BLOCK, &sm_sigchld, &omask); +#endif #ifndef MKSH_NOPROSPECTOFWORK /* @@ -1255,7 +1271,7 @@ j_sigchld(int sig MKSH_A_UNUSED) for (j = job_list; j; j = j->next) if (j->ppid == procpid && !(j->flags & JF_STARTED)) { held_sigchld = 1; - return; + goto j_sigchld_out; } #endif @@ -1272,7 +1288,7 @@ j_sigchld(int sig MKSH_A_UNUSED) * or interrupted (-1) */ if (pid <= 0) - return; + goto j_sigchld_out; getrusage(RUSAGE_CHILDREN, &ru1); @@ -1315,6 +1331,12 @@ j_sigchld(int sig MKSH_A_UNUSED) #else while (/* CONSTCOND */ 0); #endif + + j_sigchld_out: +#ifdef MKSH_NO_SIGSUSPEND + sigprocmask(SIG_SETMASK, &omask, NULL); +#endif + /* nothing */; } /* diff --git a/sh.h b/sh.h index 996f1aa..16e621e 100644 --- a/sh.h +++ b/sh.h @@ -152,9 +152,9 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.550 2012/04/22 21:50:33 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.551 2012/04/27 16:16:23 tg Exp $"); #endif -#define MKSH_VERSION "R40 2012/04/22" +#define MKSH_VERSION "R40 2012/04/27" /* arithmetic types: C implementation */ #if !HAVE_CAN_INTTYPES