1# 2# CDDL HEADER START 3# 4# The contents of this file are subject to the terms of the 5# Common Development and Distribution License (the "License"). 6# You may not use this file except in compliance with the License. 7# 8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9# or http://www.opensolaris.org/os/licensing. 10# See the License for the specific language governing permissions 11# and limitations under the License. 12# 13# When distributing Covered Code, include this CDDL HEADER in each 14# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15# If applicable, add the following below this CDDL HEADER, with the 16# fields enclosed by brackets "[]" replaced with your own identifying 17# information: Portions Copyright [yyyy] [name of copyright owner] 18# 19# CDDL HEADER END 20# 21 22# 23# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 24# 25 26# 27# Test whether CR #6753538 ("umask modification leaks out of a ksh93 28# subshell") has been fixed. 29# 30# Quote from CR #6753538: 31# -- snip -- 32# I discovered that Solaris 11's /bin/sh exhibits the following 33# surprising behavior: 34# 35# $ /bin/sh -c 'umask 22; (umask 0); umask' 36# 0000 37# 38# All other shells I tried print 22. 39# -- snip -- 40 41 42# test setup 43function err_exit 44{ 45 print -u2 -n "\t" 46 print -u2 -r ${Command}[$1]: "${@:2}" 47 (( Errors < 127 && Errors++ )) 48} 49alias err_exit='err_exit $LINENO' 50 51set -o nounset 52Command=${0##*/} 53integer Errors=0 54 55 56# 57# test set 1: Simple umask in subshell 58# 59x=$(${SHELL} -c 'umask 22; (umask 0); umask') 60[[ "$x" == "0022" ]] || err_exit "expected umask 0022, got $x" 61 62x=$(${SHELL} -c 'umask 20; (umask 0); umask') 63[[ "$x" == "0020" ]] || err_exit "expected umask 0020, got $x" 64 65x=$(${SHELL} -c 'umask 0; (umask 22); umask') 66[[ "$x" == "0000" ]] || err_exit "expected umask 0000, got $x" 67 68 69# 70# test set 2: Simple umask in two subshells 71# 72x=$(${SHELL} -c 'umask 22; ( (umask 10); umask 0); umask') 73[[ "$x" == "0022" ]] || err_exit "expected umask 0022, got $x" 74 75x=$(${SHELL} -c 'umask 20; ( (umask 10); umask 0); umask') 76[[ "$x" == "0020" ]] || err_exit "expected umas k 0020, got $x" 77 78x=$(${SHELL} -c 'umask 0; ( (umask 10); umask 22); umask') 79[[ "$x" == "0000" ]] || err_exit "expected umask 0000, got $x" 80 81 82# 83# test set 3: Compare normal subshell vs. subshell in seperate process 84# ($ ulimit -c 0 # forced the subshell to |fork()| 85# 86x=$(${SHELL} -c 'umask 22; ( umask 0); umask') || err_exit "shell failed." 87y=$(${SHELL} -c 'umask 22; (ulimit -c 0 ; umask 0); umask') || err_exit "shell failed." 88[[ "$x" == "$y" ]] || err_exit "$x != $y" 89 90x=$(${SHELL} -c 'umask 20; ( umask 0); umask') || err_exit "shell failed." 91y=$(${SHELL} -c 'umask 20; (ulimit -c 0 ; umask 0); umask') || err_exit "shell failed." 92[[ "$x" == "$y" ]] || err_exit "$x != $y" 93 94x=$(${SHELL} -c 'umask 0; ( umask 20); umask') || err_exit "shell failed." 95y=$(${SHELL} -c 'umask 0; (ulimit -c 0 ; umask 20); umask') || err_exit "shell failed." 96[[ "$x" == "$y" ]] || err_exit "$x != $y" 97 98 99# tests done 100exit $((Errors)) 101