134f9b3eRoland Mainz#
234f9b3eRoland Mainz# CDDL HEADER START
334f9b3eRoland Mainz#
434f9b3eRoland Mainz# The contents of this file are subject to the terms of the
534f9b3eRoland Mainz# Common Development and Distribution License (the "License").
634f9b3eRoland Mainz# You may not use this file except in compliance with the License.
734f9b3eRoland Mainz#
834f9b3eRoland Mainz# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
934f9b3eRoland Mainz# or http://www.opensolaris.org/os/licensing.
1034f9b3eRoland Mainz# See the License for the specific language governing permissions
1134f9b3eRoland Mainz# and limitations under the License.
1234f9b3eRoland Mainz#
1334f9b3eRoland Mainz# When distributing Covered Code, include this CDDL HEADER in each
1434f9b3eRoland Mainz# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1534f9b3eRoland Mainz# If applicable, add the following below this CDDL HEADER, with the
1634f9b3eRoland Mainz# fields enclosed by brackets "[]" replaced with your own identifying
1734f9b3eRoland Mainz# information: Portions Copyright [yyyy] [name of copyright owner]
1834f9b3eRoland Mainz#
1934f9b3eRoland Mainz# CDDL HEADER END
2034f9b3eRoland Mainz#
2134f9b3eRoland Mainz
2234f9b3eRoland Mainz#
233e14f97Roger A. Faulkner# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
2434f9b3eRoland Mainz#
2534f9b3eRoland Mainz
2634f9b3eRoland Mainz#
2734f9b3eRoland Mainz# This test checks whether a background process called in a subshell can
2834f9b3eRoland Mainz# cause it to wait for the child process instead of exiting.
2934f9b3eRoland Mainz#
3034f9b3eRoland Mainz# This was reported as CR #6881017 ("Subshell doesn't exit, holds pipe
3134f9b3eRoland Mainz# open preventing callers from exiting"):
3234f9b3eRoland Mainz# ------------ snip ------------
3334f9b3eRoland Mainz# The following scenario hangs with snv_122, 100% reproducible:
3434f9b3eRoland Mainz# 
3534f9b3eRoland Mainz# Create a script hangit:
3634f9b3eRoland Mainz# -----
3734f9b3eRoland Mainz# #!/bin/ksh
3834f9b3eRoland Mainz# ( sleep 100000 </dev/null >/dev/null 2>&1 & )
3934f9b3eRoland Mainz# exit 0
4034f9b3eRoland Mainz# -----
4134f9b3eRoland Mainz# 
4234f9b3eRoland Mainz# Run the following command:
4334f9b3eRoland Mainz# hangit | tee -a /tmp/log
4434f9b3eRoland Mainz# 
4534f9b3eRoland Mainz# The hang can be eliminated either by removing the "exit 0" line (?!?), or by
4634f9b3eRoland Mainz# redirecting the subshell output to /dev/null.
4734f9b3eRoland Mainz# 
4834f9b3eRoland Mainz# This is pretty nasty. I've whittled it down to this simple case but am seeing
4934f9b3eRoland Mainz# it in a much more subtle and complex environment where there are several
5034f9b3eRoland Mainz# intermediate calling scripts which have exited and eventually the parent pipes
5134f9b3eRoland Mainz# the output and hangs on the open pipe. It was hard to track down.
5234f9b3eRoland Mainz# ------------ snip ------------
5334f9b3eRoland Mainz#
5434f9b3eRoland Mainz
5534f9b3eRoland Mainz# test setup
5634f9b3eRoland Mainzfunction err_exit
5734f9b3eRoland Mainz{
5834f9b3eRoland Mainz	print -u2 -n "\t"
5934f9b3eRoland Mainz	print -u2 -r ${Command}[$1]: "${@:2}"
603e14f97Roger A. Faulkner	(( Errors < 127 && Errors++ ))
6134f9b3eRoland Mainz}
6234f9b3eRoland Mainzalias err_exit='err_exit $LINENO'
6334f9b3eRoland Mainz
6434f9b3eRoland Mainzset -o nounset
6534f9b3eRoland MainzCommand=${0##*/}
6634f9b3eRoland Mainzinteger Errors=0
6734f9b3eRoland Mainz
6834f9b3eRoland Mainzfloat tstart tstop tdiff
6934f9b3eRoland Mainz
7034f9b3eRoland Mainz# run test with 10 second timeout
7134f9b3eRoland Mainz(( tstart=SECONDS ))
7234f9b3eRoland Mainz$SHELL -c '( sleep 10 </dev/null >/dev/null 2>&1 & ) ; exit 0' | cat >/dev/null
7334f9b3eRoland Mainz(( tstop=SECONDS ))
7434f9b3eRoland Mainz
7534f9b3eRoland Mainz# we remove two seconds below to make sure we don't run into issues
7634f9b3eRoland Mainz# with smaller xntpd adjustments
7734f9b3eRoland Mainz(( tdiff=tstop-tstart ))
7834f9b3eRoland Mainz(( tdiff < (10.-2.) )) || err_exit "test run needed ${tdiff} seconds to complete (instead of < 8.)"
7934f9b3eRoland Mainz
8034f9b3eRoland Mainz# tests done
8134f9b3eRoland Mainzexit $((Errors))
82