7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# CDDL HEADER START
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# The contents of this file are subject to the terms of the
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# Common Development and Distribution License (the "License").
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# You may not use this file except in compliance with the License.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# See the License for the specific language governing permissions
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# and limitations under the License.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# When distributing Covered Code, include this CDDL HEADER in each
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# If applicable, add the following below this CDDL HEADER, with the
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# fields enclosed by brackets "[]" replaced with your own identifying
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# information: Portions Copyright [yyyy] [name of copyright owner]
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# CDDL HEADER END
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# This test checks whether ksh93 (like ksh88) generates calls a
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# CHLD/SIGCHLD trap for background jobs and _not_ for foreground jobs.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# This was reported as CR #6722134 ("*ksh93* (20080624_snapshot)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# doesn't execute CHLD trap"):
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# With "set -o monitor" on and "set -o notify" off, ksh88 executes the CHLD
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# trap while waiting for interactive input when a background job completes.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# ksh93 appears not to execute the CHLD trap when a background job terminates.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# Probably related: I noticed that with no CHLD trap set, but -o monitor and
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# -o notify set, there should be a similar asynchronous job completion notice.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# It works in ksh88 but not in this ksh93 build.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinset -o errexit
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chintrap "print got_child" SIGCHLD
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinfor ((i=0 ; i < 15 ; i++)) ; do
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin # external, non-background command for which a SIGCHLD should
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin # _not_ be fired
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinprint "loop finished"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$s" == ~(Er)$'14\nloop finished\ndone' ]] || err_exit "Expected '14\nloop finished\ndone' at the end of the output, got ${s}."
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$s" == ~(El)$'0\n1\n2' ]] || err_exit "Expected '0\n1\n2' as at the beginning of the output, got ${s}."
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin(( count=$(fgrep "got_child" <<< "$s" | wc -l) )) || err_exit "counting failed."
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin(( count == 2 )) || err_exit "Expected count==2, got count==${count}."
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin## (same as test "one" except that this test has one more "sleep" child)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinset -o errexit
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chintrap "print got_child" SIGCHLD
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinfor ((i=0 ; i < 15 ; i++)) ; do
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin # external, non-background command for which a SIGCHLD should
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin # _not_ be fired
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinprint "loop finished"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$s" == ~(Er)$'14\nloop finished\ndone' ]] || err_exit "Expected '14\nloop finished\ndone' at the end of the output, got ${s}."
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$s" == ~(El)$'0\n1\n2' ]] || err_exit "Expected '0\n1\n2' as at the beginning of the output, got ${s}."
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin(( count=$(fgrep "got_child" <<< "$s" | wc -l) )) || err_exit "counting failed."
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin(( count == 3 )) || err_exit "Expected count==3, got count==${count}."