1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-24 23:14:14 +00:00
cde/src/cmd/ksh93/tests/sigchld.sh
Johnothan King a065558291
Fix more compiler warnings, typos and other minor issues (#260)
Many of these changes are minor typo fixes. The other changes
(which are mostly compiler warning fixes) are:

NEWS:
- The --globcasedetect shell option works on older Linux kernels
  when used with FAT32/VFAT file systems, so remove the note about
  it only working with 5.2+ kernels.

src/cmd/ksh93/COMPATIBILITY:
- Update the documentation on function scoping with an addition
  from ksh93v- (this does apply to ksh93u+).

src/cmd/ksh93/edit/emacs.c:
- Check for '_AST_ksh_release', not 'AST_ksh_release'.

src/cmd/INIT/mamake.c,
src/cmd/INIT/ratz.c,
src/cmd/INIT/release.c,
src/cmd/builtin/pty.c:
- Add more uses of UNREACHABLE() and noreturn, this time for the
  build system and pty.

src/cmd/builtin/pty.c,
src/cmd/builtin/array.c,
src/cmd/ksh93/sh/name.c,
src/cmd/ksh93/sh/nvtype.c,
src/cmd/ksh93/sh/suid_exec.c:
- Fix six -Wunused-variable warnings (the name.c nv_arrayptr()
  fixes are also in ksh93v-).
- Remove the unused 'tableval' function to fix a -Wunused-function
  warning.

src/cmd/ksh93/sh/lex.c:
- Remove unused 'SHOPT_DOS' code, which isn't enabled anywhere.
  https://github.com/att/ast/issues/272#issuecomment-354363112

src/cmd/ksh93/bltins/misc.c,
src/cmd/ksh93/bltins/trap.c,
src/cmd/ksh93/bltins/typeset.c:
- Add dictionary generator function declarations for former
  aliases that are now builtins (re: 1fbbeaa1, ef1621c1, 3ba4900e).
- For consistency with the rest of the codebase, use '(void)'
  instead of '()' for print_cpu_times.

src/cmd/ksh93/sh/init.c,
src/lib/libast/path/pathshell.c:
- Move the otherwise unused EXE macro to pathshell() and only
  search for 'sh.exe' on Windows.

src/cmd/ksh93/sh/xec.c,
src/lib/libast/include/ast.h:
- Add an empty definition for inline when compiling with C89.
  This allows the timeval_to_double() function to be inlined.

src/cmd/ksh93/include/shlex.h:
- Remove the unused 'PIPESYM2' macro.

src/cmd/ksh93/tests/pty.sh:
- Add '# err_exit #' to count the regression test added in
  commit 113a9392.

src/lib/libast/disc/sfdcdio.c:
- Move diordwr, dioread, diowrite and dioexcept behind
  '#ifdef F_DIOINFO' to fix one -Wunused-variable warning and
  multiple -Wunused-function warnings (sfdcdio() only uses these
  functions when F_DIOINFO is defined).

src/lib/libast/string/fmtdev.c:
- Fix two -Wimplicit-function-declaration warnings on Linux by
  including sys/sysmacros.h in fmtdev().
2021-04-08 19:58:07 +01:00

152 lines
4.6 KiB
Bash
Executable file

########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1982-2012 AT&T Intellectual Property #
# and is licensed under the #
# Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property #
# #
# A copy of the License is available at #
# http://www.eclipse.org/org/documents/epl-v10.html #
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
# #
# Information and Software Systems Research #
# AT&T Research #
# Florham Park NJ #
# #
# David Korn <dgk@research.att.com> #
# #
########################################################################
. "${SHTESTS_COMMON:-${0%/*}/_common}"
float DELAY=${1:-0.2}
integer FOREGROUND=10 BACKGROUND=2
s=$($SHELL -c '
integer i foreground=0 background=0
float delay='$DELAY' d=0 s=0
set --errexit
trap "(( background++ ))" CHLD
(( d = delay ))
for ((i = 0; i < '$BACKGROUND'; i++))
do sleep $d &
(( d *= 4 ))
(( s += d ))
done
for ((i = 0; i < '$FOREGROUND'; i++))
do (( foreground++ ))
sleep $delay
(( s -= delay ))
$SHELL -c : > /dev/null # foreground does not generate SIGCHLD
done
if (( (s += delay) < 1 ))
then (( s = 1 ))
fi
sleep $s
wait
print foreground=$foreground background=$background
') || err_exit "test loop failed"
eval $s
(( foreground == FOREGROUND )) || err_exit "expected '$FOREGROUND foreground' -- got '$foreground' (DELAY=$DELAY)"
(( background == BACKGROUND )) || err_exit "expected '$BACKGROUND background' -- got '$background' (DELAY=$DELAY)"
set --noerrexit
if [[ ${.sh.version} == Version?*([[:upper:]])J* ]]
then
jobmax=4
got=$($SHELL -c '
JOBMAX='$jobmax' JOBCOUNT=$(('$jobmax'*2))
integer running=0 maxrunning=0
trap "((running--))" CHLD
for ((i=0; i<JOBCOUNT; i++))
do sleep .5 &
if ((++running > maxrunning))
then ((maxrunning=running))
fi
done
wait
print running=$running maxrunning=$maxrunning
')
exp='running=0 maxrunning='$jobmax
[[ $got == $exp ]] || err_exit "SIGCHLD trap queueing failed -- expected '$exp', got '$got'"
got=$($SHELL -c '
typeset -A proc
trap "
print \${proc[\$!].name} \${proc[\$!].status} \$?
unset proc[\$!]
" CHLD
{ sleep .3; print a; exit 1; } &
proc[$!]=( name=a status=1 )
{ sleep .2; print b; exit 2; } &
proc[$!]=( name=b status=2 )
{ sleep .1; print c; exit 3; } &
proc[$!]=( name=c status=3 )
while (( ${#proc[@]} ))
do sleep -s
done
')
exp='c\nc 3 3\nb\nb 2 2\na\na 1 1'
[[ $got == $exp ]] || err_exit "SIGCHLD trap queueing failed -- expected $(printf %q "$exp"), got $(printf %q "$got")"
fi
{
got=$( ( sleep .1;print $'\n') | $SHELL -c 'function handler { : ;}
trap handler CHLD; sleep .03 & IFS= read; print good')
} 2> /dev/null
[[ $got == good ]] || err_exit 'SIGCLD handler effects read behavior'
set -- $(
(
$SHELL -xc $'
trap \'wait $!; print $! $?\' CHLD
{ sleep 0.01; exit 9; } &
print $!
sleep 0.05
'
) 2>/dev/null; print $?
)
if (( $# != 4 ))
then err_exit "CHLD trap failed -- expected 4 args, got $#"
elif (( $4 != 0 ))
then err_exit "CHLD trap failed -- exit code $4"
elif (( $1 != $2 ))
then err_exit "child pid mismatch -- got '$1' != '$2'"
elif (( $3 != 9 ))
then err_exit "child status mismatch -- expected '9', got '$3'"
fi
trap '' CHLD
integer d
for ((d=0; d < 2000; d++))
do if print foo | grep bar
then break
fi
done
(( d==2000 )) || err_exit "trap '' CHLD causes side effects d=$d"
trap - CHLD
x=$($SHELL 2> /dev/null -ic '/dev/null/notfound; sleep .05 & sleep .1;jobs')
[[ $x == *Done* ]] || err_exit 'SIGCHLD blocked after notfound'
x=$($SHELL 2> /dev/null -ic 'kill -0 12345678901234567876; sleep .05 & sleep .1;jobs')
[[ $x == *Done* ]] || err_exit 'SIGCHLD blocked after error message'
print 'set -o monitor;sleep .05 & sleep .1;jobs' > $tmp/foobar
chmod +x $tmp/foobar
x=$($SHELL -c "echo | $tmp/foobar")
[[ $x == *Done* ]] || err_exit 'SIGCHLD blocked for script at end of pipeline'
exit $((Errors<125?Errors:125))