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

This commit is contained in:
tg 2012-04-27 16:16:23 +00:00
parent 5204e7cc4f
commit b67de6ba17
4 changed files with 32 additions and 9 deletions

View File

@ -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

View File

@ -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:

28
jobs.c
View File

@ -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 */;
}
/*

4
sh.h
View File

@ -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