Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/ksh93/tests/exit.sh
1810 views
1
########################################################################
2
# #
3
# This software is part of the ast package #
4
# Copyright (c) 1982-2011 AT&T Intellectual Property #
5
# and is licensed under the #
6
# Eclipse Public License, Version 1.0 #
7
# by AT&T Intellectual Property #
8
# #
9
# A copy of the License is available at #
10
# http://www.eclipse.org/org/documents/epl-v10.html #
11
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
12
# #
13
# Information and Software Systems Research #
14
# AT&T Research #
15
# Florham Park NJ #
16
# #
17
# David Korn <[email protected]> #
18
# #
19
########################################################################
20
function err_exit
21
{
22
print -u2 -n "\t"
23
print -u2 -r ${Command}[$1]: "${@:2}"
24
let Errors+=1
25
}
26
alias err_exit='err_exit $LINENO'
27
28
Command=${0##*/}
29
integer Errors=0
30
31
tmp=$(mktemp -dt) || { err_exit mktemp -dt failed; exit 1; }
32
trap "cd /; rm -rf $tmp" EXIT
33
34
function abspath
35
{
36
base=$(basename $SHELL)
37
cd ${SHELL%/$base}
38
newdir=$(pwd)
39
cd ~-
40
print $newdir/$base
41
}
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 \
51
$(
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
60
!
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'
66
fi
67
if [[ $(trap 'code=$?; echo $code; trap 0; exit $code' 0; exit 123) != 123 ]]
68
then err_exit 'exit not setting $?'
69
fi
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'
76
fi
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)?'
79
80
exit $((Errors<125?Errors:125))
81
82