17c2fbfb3SApril Chin# 27c2fbfb3SApril Chin# CDDL HEADER START 37c2fbfb3SApril Chin# 47c2fbfb3SApril Chin# The contents of this file are subject to the terms of the 57c2fbfb3SApril Chin# Common Development and Distribution License (the "License"). 67c2fbfb3SApril Chin# You may not use this file except in compliance with the License. 77c2fbfb3SApril Chin# 87c2fbfb3SApril Chin# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c2fbfb3SApril Chin# or http://www.opensolaris.org/os/licensing. 107c2fbfb3SApril Chin# See the License for the specific language governing permissions 117c2fbfb3SApril Chin# and limitations under the License. 127c2fbfb3SApril Chin# 137c2fbfb3SApril Chin# When distributing Covered Code, include this CDDL HEADER in each 147c2fbfb3SApril Chin# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c2fbfb3SApril Chin# If applicable, add the following below this CDDL HEADER, with the 167c2fbfb3SApril Chin# fields enclosed by brackets "[]" replaced with your own identifying 177c2fbfb3SApril Chin# information: Portions Copyright [yyyy] [name of copyright owner] 187c2fbfb3SApril Chin# 197c2fbfb3SApril Chin# CDDL HEADER END 207c2fbfb3SApril Chin# 217c2fbfb3SApril Chin 227c2fbfb3SApril Chin# 233e14f97fSRoger A. Faulkner# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 247c2fbfb3SApril Chin# 257c2fbfb3SApril Chin 267c2fbfb3SApril Chin# 277c2fbfb3SApril Chin# This test checks whether ksh93 (like ksh88) generates calls a 287c2fbfb3SApril Chin# CHLD/SIGCHLD trap for background jobs and _not_ for foreground jobs. 297c2fbfb3SApril Chin# 307c2fbfb3SApril Chin# This was reported as CR #6722134 ("*ksh93* (20080624_snapshot) 317c2fbfb3SApril Chin# doesn't execute CHLD trap"): 327c2fbfb3SApril Chin# -- snip -- 337c2fbfb3SApril Chin# With "set -o monitor" on and "set -o notify" off, ksh88 executes the CHLD 347c2fbfb3SApril Chin# trap while waiting for interactive input when a background job completes. 357c2fbfb3SApril Chin# ksh93 appears not to execute the CHLD trap when a background job terminates. 367c2fbfb3SApril Chin# Probably related: I noticed that with no CHLD trap set, but -o monitor and 377c2fbfb3SApril Chin# -o notify set, there should be a similar asynchronous job completion notice. 387c2fbfb3SApril Chin# It works in ksh88 but not in this ksh93 build. 397c2fbfb3SApril Chin# -- snip -- 407c2fbfb3SApril Chin# 417c2fbfb3SApril Chin 4234f9b3eeSRoland Mainz# test setup 437c2fbfb3SApril Chinfunction err_exit 447c2fbfb3SApril Chin{ 457c2fbfb3SApril Chin print -u2 -n "\t" 467c2fbfb3SApril Chin print -u2 -r ${Command}[$1]: "${@:2}" 473e14f97fSRoger A. Faulkner (( Errors < 127 && Errors++ )) 487c2fbfb3SApril Chin} 497c2fbfb3SApril Chinalias err_exit='err_exit $LINENO' 507c2fbfb3SApril Chin 5134f9b3eeSRoland Mainzset -o nounset 5234f9b3eeSRoland MainzCommand=${0##*/} 537c2fbfb3SApril Chininteger Errors=0 547c2fbfb3SApril Chin 5534f9b3eeSRoland Mainz 567c2fbfb3SApril Chin## 577c2fbfb3SApril Chin## test one: 587c2fbfb3SApril Chin## 597c2fbfb3SApril Chins="$($SHELL -c ' 607c2fbfb3SApril Chinset -o errexit 617c2fbfb3SApril Chininteger i 627c2fbfb3SApril Chin 637c2fbfb3SApril Chintrap "print got_child" SIGCHLD 647c2fbfb3SApril Chin 657c2fbfb3SApril Chinsleep 5 & 667c2fbfb3SApril Chinsleep 7 & 677c2fbfb3SApril Chinfor ((i=0 ; i < 15 ; i++)) ; do 687c2fbfb3SApril Chin print $i 697c2fbfb3SApril Chin sleep 1 70*b30d1939SAndy Fiddaman 717c2fbfb3SApril Chin # external, non-background command for which a SIGCHLD should 727c2fbfb3SApril Chin # _not_ be fired 737c2fbfb3SApril Chin /bin/true >/dev/null 747c2fbfb3SApril Chindone 757c2fbfb3SApril Chinprint "loop finished" 767c2fbfb3SApril Chinwait 777c2fbfb3SApril Chinprint "done" 787c2fbfb3SApril Chin' 2>&1 )" || err_exit "test loop failed." 797c2fbfb3SApril Chin 807c2fbfb3SApril Chin[[ "$s" == ~(Er)$'14\nloop finished\ndone' ]] || err_exit "Expected '14\nloop finished\ndone' at the end of the output, got ${s}." 817c2fbfb3SApril Chin[[ "$s" == ~(El)$'0\n1\n2' ]] || err_exit "Expected '0\n1\n2' as at the beginning of the output, got ${s}." 827c2fbfb3SApril Chin 837c2fbfb3SApril Chininteger count 847c2fbfb3SApril Chin(( count=$(fgrep "got_child" <<< "$s" | wc -l) )) || err_exit "counting failed." 857c2fbfb3SApril Chin(( count == 2 )) || err_exit "Expected count==2, got count==${count}." 867c2fbfb3SApril Chin 877c2fbfb3SApril Chin 887c2fbfb3SApril Chin## 897c2fbfb3SApril Chin## test two: 907c2fbfb3SApril Chin## (same as test "one" except that this test has one more "sleep" child) 917c2fbfb3SApril Chin## 927c2fbfb3SApril Chins="$($SHELL -c ' 937c2fbfb3SApril Chinset -o errexit 947c2fbfb3SApril Chininteger i 957c2fbfb3SApril Chin 967c2fbfb3SApril Chintrap "print got_child" SIGCHLD 977c2fbfb3SApril Chin 987c2fbfb3SApril Chinsleep 5 & 997c2fbfb3SApril Chinsleep 7 & 1007c2fbfb3SApril Chinsleep 9 & 1017c2fbfb3SApril Chinfor ((i=0 ; i < 15 ; i++)) ; do 1027c2fbfb3SApril Chin print $i 1037c2fbfb3SApril Chin sleep 1 104*b30d1939SAndy Fiddaman 1057c2fbfb3SApril Chin # external, non-background command for which a SIGCHLD should 1067c2fbfb3SApril Chin # _not_ be fired 1077c2fbfb3SApril Chin /bin/true >/dev/null 1087c2fbfb3SApril Chindone 1097c2fbfb3SApril Chinprint "loop finished" 1107c2fbfb3SApril Chinwait 1117c2fbfb3SApril Chinprint "done" 1127c2fbfb3SApril Chin' 2>&1 )" || err_exit "test loop failed." 1137c2fbfb3SApril Chin 1147c2fbfb3SApril Chin[[ "$s" == ~(Er)$'14\nloop finished\ndone' ]] || err_exit "Expected '14\nloop finished\ndone' at the end of the output, got ${s}." 1157c2fbfb3SApril Chin[[ "$s" == ~(El)$'0\n1\n2' ]] || err_exit "Expected '0\n1\n2' as at the beginning of the output, got ${s}." 1167c2fbfb3SApril Chin 1177c2fbfb3SApril Chin(( count=$(fgrep "got_child" <<< "$s" | wc -l) )) || err_exit "counting failed." 1187c2fbfb3SApril Chin(( count == 3 )) || err_exit "Expected count==3, got count==${count}." 1197c2fbfb3SApril Chin 12034f9b3eeSRoland Mainz 1217c2fbfb3SApril Chin# tests done 1227c2fbfb3SApril Chinexit $((Errors)) 123