sd: remove 'ssd' driver support
[unleashed/tickless.git] / usr / src / lib / libshell / common / tests / exit.sh
blob47e05aa6ebbbb28ccd8debd3c84b8de44855c346
1 ########################################################################
2 # #
3 # This software is part of the ast package #
4 # Copyright (c) 1982-2010 AT&T Intellectual Property #
5 # and is licensed under the #
6 # Common Public License, Version 1.0 #
7 # by AT&T Intellectual Property #
8 # #
9 # A copy of the License is available at #
10 # http://www.opensource.org/licenses/cpl1.0.txt #
11 # (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) #
12 # #
13 # Information and Software Systems Research #
14 # AT&T Research #
15 # Florham Park NJ #
16 # #
17 # David Korn <dgk@research.att.com> #
18 # #
19 ########################################################################
20 function err_exit
22 print -u2 -n "\t"
23 print -u2 -r ${Command}[$1]: "${@:2}"
24 let Errors+=1
26 alias err_exit='err_exit $LINENO'
28 Command=${0##*/}
29 integer Errors=0
31 tmp=$(mktemp -dt) || { err_exit mktemp -dt failed; exit 1; }
32 trap "cd /; rm -rf $tmp" EXIT
34 function abspath
36 base=$(basename $SHELL)
37 cd ${SHELL%/$base}
38 newdir=$(pwd)
39 cd ~-
40 print $newdir/$base
42 #test for proper exit of shell
43 builtin getconf
44 ABSHELL=$(abspath)
45 cd $tmp || { err_exit "cd $tmp failed"; exit 1; }
46 print exit 0 >.profile
47 ${ABSHELL} <<!
48 HOME=$PWD \
49 PATH=$PATH \
50 SHELL=$ABSSHELL \
52 v=$(getconf LIBPATH)
53 for v in ${v//,/ }
54 do v=${v#*:}
55 v=${v%%:*}
56 eval [[ \$$v ]] && eval print -n \" \"\$v=\"\$$v\"
57 done
58 ) \
59 exec -c -a -ksh ${ABSHELL} -c "exit 1" 1>/dev/null 2>&1
61 status=$(echo $?)
62 if [[ -o noprivileged && $status != 0 ]]
63 then err_exit 'exit in .profile is ignored'
64 elif [[ -o privileged && $status == 0 ]]
65 then err_exit 'privileged .profile not ignored'
67 if [[ $(trap 'code=$?; echo $code; trap 0; exit $code' 0; exit 123) != 123 ]]
68 then err_exit 'exit not setting $?'
70 cat > run.sh <<- "EOF"
71 trap 'code=$?; echo $code; trap 0; exit $code' 0
72 ( trap 0; exit 123 )
73 EOF
74 if [[ $($SHELL ./run.sh) != 123 ]]
75 then err_exit 'subshell trap on exit overwrites parent trap'
77 cd ~- || err_exit "cd back failed"
78 $SHELL -c 'builtin -f cmd getconf; getconf --"?-version"; exit 0' >/dev/null 2>&1 || err_exit 'ksh plugin exit failed -- was ksh built with CCFLAGS+=$(CC.EXPORT.DYNAMIC)?'
80 exit $((Errors))