xref: /titanic_50/usr/src/test/test-runner/stf/contrib/include/logapi.shlib (revision d583b39bfb4e2571d3e41097c5c357ffe353ad45)
1*d583b39bSJohn Wren Kennedy#
2*d583b39bSJohn Wren Kennedy# CDDL HEADER START
3*d583b39bSJohn Wren Kennedy#
4*d583b39bSJohn Wren Kennedy# The contents of this file are subject to the terms of the
5*d583b39bSJohn Wren Kennedy# Common Development and Distribution License (the "License").
6*d583b39bSJohn Wren Kennedy# You may not use this file except in compliance with the License.
7*d583b39bSJohn Wren Kennedy#
8*d583b39bSJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*d583b39bSJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing.
10*d583b39bSJohn Wren Kennedy# See the License for the specific language governing permissions
11*d583b39bSJohn Wren Kennedy# and limitations under the License.
12*d583b39bSJohn Wren Kennedy#
13*d583b39bSJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
14*d583b39bSJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*d583b39bSJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
16*d583b39bSJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
17*d583b39bSJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
18*d583b39bSJohn Wren Kennedy#
19*d583b39bSJohn Wren Kennedy# CDDL HEADER END
20*d583b39bSJohn Wren Kennedy#
21*d583b39bSJohn Wren Kennedy
22*d583b39bSJohn Wren Kennedy#
23*d583b39bSJohn Wren Kennedy# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24*d583b39bSJohn Wren Kennedy# Use is subject to license terms.
25*d583b39bSJohn Wren Kennedy#
26*d583b39bSJohn Wren Kennedy# Copyright (c) 2012 by Delphix. All rights reserved.
27*d583b39bSJohn Wren Kennedy#
28*d583b39bSJohn Wren Kennedy
29*d583b39bSJohn Wren Kennedy. ${STF_TOOLS}/include/stf.shlib
30*d583b39bSJohn Wren Kennedy
31*d583b39bSJohn Wren Kennedy# Output an assertion
32*d583b39bSJohn Wren Kennedy#
33*d583b39bSJohn Wren Kennedy# $@ - assertion text
34*d583b39bSJohn Wren Kennedy
35*d583b39bSJohn Wren Kennedyfunction log_assert
36*d583b39bSJohn Wren Kennedy{
37*d583b39bSJohn Wren Kennedy	_printline ASSERTION: "$@"
38*d583b39bSJohn Wren Kennedy}
39*d583b39bSJohn Wren Kennedy
40*d583b39bSJohn Wren Kennedy# Output a comment
41*d583b39bSJohn Wren Kennedy#
42*d583b39bSJohn Wren Kennedy# $@ - comment text
43*d583b39bSJohn Wren Kennedy
44*d583b39bSJohn Wren Kennedyfunction log_note
45*d583b39bSJohn Wren Kennedy{
46*d583b39bSJohn Wren Kennedy	_printline NOTE: "$@"
47*d583b39bSJohn Wren Kennedy}
48*d583b39bSJohn Wren Kennedy
49*d583b39bSJohn Wren Kennedy# Execute and print command with status where success equals non-zero result
50*d583b39bSJohn Wren Kennedy#
51*d583b39bSJohn Wren Kennedy# $@ - command to execute
52*d583b39bSJohn Wren Kennedy#
53*d583b39bSJohn Wren Kennedy# return 0 if command fails, otherwise return 1
54*d583b39bSJohn Wren Kennedy
55*d583b39bSJohn Wren Kennedyfunction log_neg
56*d583b39bSJohn Wren Kennedy{
57*d583b39bSJohn Wren Kennedy	log_neg_expect ""  "$@"
58*d583b39bSJohn Wren Kennedy	return $?
59*d583b39bSJohn Wren Kennedy}
60*d583b39bSJohn Wren Kennedy
61*d583b39bSJohn Wren Kennedy# Execute a positive test and exit $STF_FAIL is test fails
62*d583b39bSJohn Wren Kennedy#
63*d583b39bSJohn Wren Kennedy# $@ - command to execute
64*d583b39bSJohn Wren Kennedy
65*d583b39bSJohn Wren Kennedyfunction log_must
66*d583b39bSJohn Wren Kennedy{
67*d583b39bSJohn Wren Kennedy	log_pos "$@"
68*d583b39bSJohn Wren Kennedy	(( $? != 0 )) && log_fail
69*d583b39bSJohn Wren Kennedy}
70*d583b39bSJohn Wren Kennedy
71*d583b39bSJohn Wren Kennedy# Execute a negative test and exit $STF_FAIL if test passes
72*d583b39bSJohn Wren Kennedy#
73*d583b39bSJohn Wren Kennedy# $@ - command to execute
74*d583b39bSJohn Wren Kennedy
75*d583b39bSJohn Wren Kennedyfunction log_mustnot
76*d583b39bSJohn Wren Kennedy{
77*d583b39bSJohn Wren Kennedy	log_neg "$@"
78*d583b39bSJohn Wren Kennedy	(( $? != 0 )) && log_fail
79*d583b39bSJohn Wren Kennedy}
80*d583b39bSJohn Wren Kennedy
81*d583b39bSJohn Wren Kennedy# Execute a negative test with keyword expected, and exit
82*d583b39bSJohn Wren Kennedy# $STF_FAIL if test passes
83*d583b39bSJohn Wren Kennedy#
84*d583b39bSJohn Wren Kennedy# $1 - keyword expected
85*d583b39bSJohn Wren Kennedy# $2-$@ - command to execute
86*d583b39bSJohn Wren Kennedy
87*d583b39bSJohn Wren Kennedyfunction log_mustnot_expect
88*d583b39bSJohn Wren Kennedy{
89*d583b39bSJohn Wren Kennedy	log_neg_expect "$@"
90*d583b39bSJohn Wren Kennedy	(( $? != 0 )) && log_fail
91*d583b39bSJohn Wren Kennedy}
92*d583b39bSJohn Wren Kennedy
93*d583b39bSJohn Wren Kennedy# Execute and print command with status where success equals non-zero result
94*d583b39bSJohn Wren Kennedy# or output includes expected keyword
95*d583b39bSJohn Wren Kennedy#
96*d583b39bSJohn Wren Kennedy# $1 - keyword expected
97*d583b39bSJohn Wren Kennedy# $2-$@ - command to execute
98*d583b39bSJohn Wren Kennedy#
99*d583b39bSJohn Wren Kennedy# return 0 if command fails, or the output contains the keyword expected,
100*d583b39bSJohn Wren Kennedy# return 1 otherwise
101*d583b39bSJohn Wren Kennedy
102*d583b39bSJohn Wren Kennedyfunction log_neg_expect
103*d583b39bSJohn Wren Kennedy{
104*d583b39bSJohn Wren Kennedy	typeset out=""
105*d583b39bSJohn Wren Kennedy	typeset logfile="/tmp/log.$$"
106*d583b39bSJohn Wren Kennedy	typeset ret=1
107*d583b39bSJohn Wren Kennedy	typeset expect=$1
108*d583b39bSJohn Wren Kennedy	shift
109*d583b39bSJohn Wren Kennedy
110*d583b39bSJohn Wren Kennedy	while [[ -e $logfile ]]; do
111*d583b39bSJohn Wren Kennedy		logfile="$logfile.$$"
112*d583b39bSJohn Wren Kennedy	done
113*d583b39bSJohn Wren Kennedy
114*d583b39bSJohn Wren Kennedy	"$@" 2>$logfile
115*d583b39bSJohn Wren Kennedy	typeset status=$?
116*d583b39bSJohn Wren Kennedy	out="/usr/bin/cat $logfile"
117*d583b39bSJohn Wren Kennedy
118*d583b39bSJohn Wren Kennedy	# unexpected status
119*d583b39bSJohn Wren Kennedy	if (( $status == 0 )); then
120*d583b39bSJohn Wren Kennedy		 print -u2 $($out)
121*d583b39bSJohn Wren Kennedy		_printerror "$@" "unexpectedly exited $status"
122*d583b39bSJohn Wren Kennedy	# missing binary
123*d583b39bSJohn Wren Kennedy	elif (( $status == 127 )); then
124*d583b39bSJohn Wren Kennedy		print -u2 $($out)
125*d583b39bSJohn Wren Kennedy		_printerror "$@" "unexpectedly exited $status (File not found)"
126*d583b39bSJohn Wren Kennedy	# bus error - core dump
127*d583b39bSJohn Wren Kennedy	elif (( $status == 138 )); then
128*d583b39bSJohn Wren Kennedy		print -u2 $($out)
129*d583b39bSJohn Wren Kennedy		_printerror "$@" "unexpectedly exited $status (Bus Error)"
130*d583b39bSJohn Wren Kennedy	# segmentation violation - core dump
131*d583b39bSJohn Wren Kennedy	elif (( $status == 139 )); then
132*d583b39bSJohn Wren Kennedy		print -u2 $($out)
133*d583b39bSJohn Wren Kennedy		_printerror "$@" "unexpectedly exited $status (SEGV)"
134*d583b39bSJohn Wren Kennedy	else
135*d583b39bSJohn Wren Kennedy		$out | /usr/bin/egrep -i "internal error|assertion failed" \
136*d583b39bSJohn Wren Kennedy			> /dev/null 2>&1
137*d583b39bSJohn Wren Kennedy		# internal error or assertion failed
138*d583b39bSJohn Wren Kennedy		if (( $? == 0 )); then
139*d583b39bSJohn Wren Kennedy			print -u2 $($out)
140*d583b39bSJohn Wren Kennedy			_printerror "$@" "internal error or assertion failure" \
141*d583b39bSJohn Wren Kennedy				" exited $status"
142*d583b39bSJohn Wren Kennedy		elif [[ -n $expect ]] ; then
143*d583b39bSJohn Wren Kennedy			$out | /usr/bin/grep -i "$expect" > /dev/null 2>&1
144*d583b39bSJohn Wren Kennedy			if (( $? == 0 )); then
145*d583b39bSJohn Wren Kennedy				ret=0
146*d583b39bSJohn Wren Kennedy			else
147*d583b39bSJohn Wren Kennedy				print -u2 $($out)
148*d583b39bSJohn Wren Kennedy				_printerror "$@" "unexpectedly exited $status"
149*d583b39bSJohn Wren Kennedy			fi
150*d583b39bSJohn Wren Kennedy		else
151*d583b39bSJohn Wren Kennedy			ret=0
152*d583b39bSJohn Wren Kennedy		fi
153*d583b39bSJohn Wren Kennedy
154*d583b39bSJohn Wren Kennedy		if (( $ret == 0 )); then
155*d583b39bSJohn Wren Kennedy			[[ -n $LOGAPI_DEBUG ]] && print $($out)
156*d583b39bSJohn Wren Kennedy			_printsuccess "$@" "exited $status"
157*d583b39bSJohn Wren Kennedy		fi
158*d583b39bSJohn Wren Kennedy	fi
159*d583b39bSJohn Wren Kennedy	_recursive_output $logfile "false"
160*d583b39bSJohn Wren Kennedy	return $ret
161*d583b39bSJohn Wren Kennedy}
162*d583b39bSJohn Wren Kennedy
163*d583b39bSJohn Wren Kennedy# Execute and print command with status where success equals zero result
164*d583b39bSJohn Wren Kennedy#
165*d583b39bSJohn Wren Kennedy# $@ command to execute
166*d583b39bSJohn Wren Kennedy#
167*d583b39bSJohn Wren Kennedy# return command exit status
168*d583b39bSJohn Wren Kennedy
169*d583b39bSJohn Wren Kennedyfunction log_pos
170*d583b39bSJohn Wren Kennedy{
171*d583b39bSJohn Wren Kennedy	typeset out=""
172*d583b39bSJohn Wren Kennedy	typeset logfile="/tmp/log.$$"
173*d583b39bSJohn Wren Kennedy
174*d583b39bSJohn Wren Kennedy	while [[ -e $logfile ]]; do
175*d583b39bSJohn Wren Kennedy		logfile="$logfile.$$"
176*d583b39bSJohn Wren Kennedy	done
177*d583b39bSJohn Wren Kennedy
178*d583b39bSJohn Wren Kennedy	"$@" 2>$logfile
179*d583b39bSJohn Wren Kennedy	typeset status=$?
180*d583b39bSJohn Wren Kennedy	out="/usr/bin/cat $logfile"
181*d583b39bSJohn Wren Kennedy
182*d583b39bSJohn Wren Kennedy	if (( $status != 0 )) ; then
183*d583b39bSJohn Wren Kennedy		print -u2 $($out)
184*d583b39bSJohn Wren Kennedy		_printerror "$@" "exited $status"
185*d583b39bSJohn Wren Kennedy	else
186*d583b39bSJohn Wren Kennedy		$out | /usr/bin/egrep -i "internal error|assertion failed" \
187*d583b39bSJohn Wren Kennedy			> /dev/null 2>&1
188*d583b39bSJohn Wren Kennedy		# internal error or assertion failed
189*d583b39bSJohn Wren Kennedy		if [[ $? -eq 0 ]]; then
190*d583b39bSJohn Wren Kennedy			print -u2 $($out)
191*d583b39bSJohn Wren Kennedy			_printerror "$@" "internal error or assertion failure" \
192*d583b39bSJohn Wren Kennedy				" exited $status"
193*d583b39bSJohn Wren Kennedy			status=1
194*d583b39bSJohn Wren Kennedy		else
195*d583b39bSJohn Wren Kennedy			[[ -n $LOGAPI_DEBUG ]] && print $($out)
196*d583b39bSJohn Wren Kennedy			_printsuccess "$@"
197*d583b39bSJohn Wren Kennedy		fi
198*d583b39bSJohn Wren Kennedy	fi
199*d583b39bSJohn Wren Kennedy	_recursive_output $logfile "false"
200*d583b39bSJohn Wren Kennedy	return $status
201*d583b39bSJohn Wren Kennedy}
202*d583b39bSJohn Wren Kennedy
203*d583b39bSJohn Wren Kennedy# Set an exit handler
204*d583b39bSJohn Wren Kennedy#
205*d583b39bSJohn Wren Kennedy# $@ - function(s) to perform on exit
206*d583b39bSJohn Wren Kennedy
207*d583b39bSJohn Wren Kennedyfunction log_onexit
208*d583b39bSJohn Wren Kennedy{
209*d583b39bSJohn Wren Kennedy	_CLEANUP="$@"
210*d583b39bSJohn Wren Kennedy}
211*d583b39bSJohn Wren Kennedy
212*d583b39bSJohn Wren Kennedy#
213*d583b39bSJohn Wren Kennedy# Exit functions
214*d583b39bSJohn Wren Kennedy#
215*d583b39bSJohn Wren Kennedy
216*d583b39bSJohn Wren Kennedy# Perform cleanup and exit $STF_PASS
217*d583b39bSJohn Wren Kennedy#
218*d583b39bSJohn Wren Kennedy# $@ - message text
219*d583b39bSJohn Wren Kennedy
220*d583b39bSJohn Wren Kennedyfunction log_pass
221*d583b39bSJohn Wren Kennedy{
222*d583b39bSJohn Wren Kennedy	_endlog $STF_PASS "$@"
223*d583b39bSJohn Wren Kennedy}
224*d583b39bSJohn Wren Kennedy
225*d583b39bSJohn Wren Kennedy# Perform cleanup and exit $STF_FAIL
226*d583b39bSJohn Wren Kennedy#
227*d583b39bSJohn Wren Kennedy# $@ - message text
228*d583b39bSJohn Wren Kennedy
229*d583b39bSJohn Wren Kennedyfunction log_fail
230*d583b39bSJohn Wren Kennedy{
231*d583b39bSJohn Wren Kennedy	_endlog $STF_FAIL "$@"
232*d583b39bSJohn Wren Kennedy}
233*d583b39bSJohn Wren Kennedy
234*d583b39bSJohn Wren Kennedy# Perform cleanup and exit $STF_UNRESOLVED
235*d583b39bSJohn Wren Kennedy#
236*d583b39bSJohn Wren Kennedy# $@ - message text
237*d583b39bSJohn Wren Kennedy
238*d583b39bSJohn Wren Kennedyfunction log_unresolved
239*d583b39bSJohn Wren Kennedy{
240*d583b39bSJohn Wren Kennedy	_endlog $STF_UNRESOLVED "$@"
241*d583b39bSJohn Wren Kennedy}
242*d583b39bSJohn Wren Kennedy
243*d583b39bSJohn Wren Kennedy# Perform cleanup and exit $STF_NOTINUSE
244*d583b39bSJohn Wren Kennedy#
245*d583b39bSJohn Wren Kennedy# $@ - message text
246*d583b39bSJohn Wren Kennedy
247*d583b39bSJohn Wren Kennedyfunction log_notinuse
248*d583b39bSJohn Wren Kennedy{
249*d583b39bSJohn Wren Kennedy	_endlog $STF_NOTINUSE "$@"
250*d583b39bSJohn Wren Kennedy}
251*d583b39bSJohn Wren Kennedy
252*d583b39bSJohn Wren Kennedy# Perform cleanup and exit $STF_UNSUPPORTED
253*d583b39bSJohn Wren Kennedy#
254*d583b39bSJohn Wren Kennedy# $@ - message text
255*d583b39bSJohn Wren Kennedy
256*d583b39bSJohn Wren Kennedyfunction log_unsupported
257*d583b39bSJohn Wren Kennedy{
258*d583b39bSJohn Wren Kennedy	_endlog $STF_UNSUPPORTED "$@"
259*d583b39bSJohn Wren Kennedy}
260*d583b39bSJohn Wren Kennedy
261*d583b39bSJohn Wren Kennedy# Perform cleanup and exit $STF_UNTESTED
262*d583b39bSJohn Wren Kennedy#
263*d583b39bSJohn Wren Kennedy# $@ - message text
264*d583b39bSJohn Wren Kennedy
265*d583b39bSJohn Wren Kennedyfunction log_untested
266*d583b39bSJohn Wren Kennedy{
267*d583b39bSJohn Wren Kennedy	_endlog $STF_UNTESTED "$@"
268*d583b39bSJohn Wren Kennedy}
269*d583b39bSJohn Wren Kennedy
270*d583b39bSJohn Wren Kennedy# Perform cleanup and exit $STF_UNINITIATED
271*d583b39bSJohn Wren Kennedy#
272*d583b39bSJohn Wren Kennedy# $@ - message text
273*d583b39bSJohn Wren Kennedy
274*d583b39bSJohn Wren Kennedyfunction log_uninitiated
275*d583b39bSJohn Wren Kennedy{
276*d583b39bSJohn Wren Kennedy	_endlog $STF_UNINITIATED "$@"
277*d583b39bSJohn Wren Kennedy}
278*d583b39bSJohn Wren Kennedy
279*d583b39bSJohn Wren Kennedy# Perform cleanup and exit $STF_NORESULT
280*d583b39bSJohn Wren Kennedy#
281*d583b39bSJohn Wren Kennedy# $@ - message text
282*d583b39bSJohn Wren Kennedy
283*d583b39bSJohn Wren Kennedyfunction log_noresult
284*d583b39bSJohn Wren Kennedy{
285*d583b39bSJohn Wren Kennedy	_endlog $STF_NORESULT "$@"
286*d583b39bSJohn Wren Kennedy}
287*d583b39bSJohn Wren Kennedy
288*d583b39bSJohn Wren Kennedy# Perform cleanup and exit $STF_WARNING
289*d583b39bSJohn Wren Kennedy#
290*d583b39bSJohn Wren Kennedy# $@ - message text
291*d583b39bSJohn Wren Kennedy
292*d583b39bSJohn Wren Kennedyfunction log_warning
293*d583b39bSJohn Wren Kennedy{
294*d583b39bSJohn Wren Kennedy	_endlog $STF_WARNING "$@"
295*d583b39bSJohn Wren Kennedy}
296*d583b39bSJohn Wren Kennedy
297*d583b39bSJohn Wren Kennedy# Perform cleanup and exit $STF_TIMED_OUT
298*d583b39bSJohn Wren Kennedy#
299*d583b39bSJohn Wren Kennedy# $@ - message text
300*d583b39bSJohn Wren Kennedy
301*d583b39bSJohn Wren Kennedyfunction log_timed_out
302*d583b39bSJohn Wren Kennedy{
303*d583b39bSJohn Wren Kennedy	_endlog $STF_TIMED_OUT "$@"
304*d583b39bSJohn Wren Kennedy}
305*d583b39bSJohn Wren Kennedy
306*d583b39bSJohn Wren Kennedy# Perform cleanup and exit $STF_OTHER
307*d583b39bSJohn Wren Kennedy#
308*d583b39bSJohn Wren Kennedy# $@ - message text
309*d583b39bSJohn Wren Kennedy
310*d583b39bSJohn Wren Kennedyfunction log_other
311*d583b39bSJohn Wren Kennedy{
312*d583b39bSJohn Wren Kennedy	_endlog $STF_OTHER "$@"
313*d583b39bSJohn Wren Kennedy}
314*d583b39bSJohn Wren Kennedy
315*d583b39bSJohn Wren Kennedy#
316*d583b39bSJohn Wren Kennedy# Internal functions
317*d583b39bSJohn Wren Kennedy#
318*d583b39bSJohn Wren Kennedy
319*d583b39bSJohn Wren Kennedy# Perform cleanup and exit
320*d583b39bSJohn Wren Kennedy#
321*d583b39bSJohn Wren Kennedy# $1 - stf exit code
322*d583b39bSJohn Wren Kennedy# $2-$n - message text
323*d583b39bSJohn Wren Kennedy
324*d583b39bSJohn Wren Kennedyfunction _endlog
325*d583b39bSJohn Wren Kennedy{
326*d583b39bSJohn Wren Kennedy	typeset logfile="/tmp/log.$$"
327*d583b39bSJohn Wren Kennedy	_recursive_output $logfile
328*d583b39bSJohn Wren Kennedy
329*d583b39bSJohn Wren Kennedy	if [[ -n $_CLEANUP ]] ; then
330*d583b39bSJohn Wren Kennedy		typeset cleanup=$_CLEANUP
331*d583b39bSJohn Wren Kennedy		log_onexit ""
332*d583b39bSJohn Wren Kennedy		log_note "Performing local cleanup via log_onexit ($cleanup)"
333*d583b39bSJohn Wren Kennedy		$cleanup
334*d583b39bSJohn Wren Kennedy	fi
335*d583b39bSJohn Wren Kennedy	typeset exitcode=$1
336*d583b39bSJohn Wren Kennedy	shift
337*d583b39bSJohn Wren Kennedy	(( ${#@} > 0 )) && _printline "$@"
338*d583b39bSJohn Wren Kennedy	exit $exitcode
339*d583b39bSJohn Wren Kennedy}
340*d583b39bSJohn Wren Kennedy
341*d583b39bSJohn Wren Kennedy# Output a formatted line
342*d583b39bSJohn Wren Kennedy#
343*d583b39bSJohn Wren Kennedy# $@ - message text
344*d583b39bSJohn Wren Kennedy
345*d583b39bSJohn Wren Kennedyfunction _printline
346*d583b39bSJohn Wren Kennedy{
347*d583b39bSJohn Wren Kennedy	print "$@"
348*d583b39bSJohn Wren Kennedy}
349*d583b39bSJohn Wren Kennedy
350*d583b39bSJohn Wren Kennedy# Output an error message
351*d583b39bSJohn Wren Kennedy#
352*d583b39bSJohn Wren Kennedy# $@ - message text
353*d583b39bSJohn Wren Kennedy
354*d583b39bSJohn Wren Kennedyfunction _printerror
355*d583b39bSJohn Wren Kennedy{
356*d583b39bSJohn Wren Kennedy	_printline ERROR: "$@"
357*d583b39bSJohn Wren Kennedy}
358*d583b39bSJohn Wren Kennedy
359*d583b39bSJohn Wren Kennedy# Output a success message
360*d583b39bSJohn Wren Kennedy#
361*d583b39bSJohn Wren Kennedy# $@ - message text
362*d583b39bSJohn Wren Kennedy
363*d583b39bSJohn Wren Kennedyfunction _printsuccess
364*d583b39bSJohn Wren Kennedy{
365*d583b39bSJohn Wren Kennedy	_printline SUCCESS: "$@"
366*d583b39bSJohn Wren Kennedy}
367*d583b39bSJohn Wren Kennedy
368*d583b39bSJohn Wren Kennedy# Output logfiles recursively
369*d583b39bSJohn Wren Kennedy#
370*d583b39bSJohn Wren Kennedy# $1 - start file
371*d583b39bSJohn Wren Kennedy# $2 - indicate whether output the start file itself, default as yes.
372*d583b39bSJohn Wren Kennedy
373*d583b39bSJohn Wren Kennedyfunction _recursive_output #logfile
374*d583b39bSJohn Wren Kennedy{
375*d583b39bSJohn Wren Kennedy	typeset logfile=$1
376*d583b39bSJohn Wren Kennedy
377*d583b39bSJohn Wren Kennedy	while [[ -e $logfile ]]; do
378*d583b39bSJohn Wren Kennedy		if [[ -z $2 || $logfile != $1 ]]; then
379*d583b39bSJohn Wren Kennedy			/usr/bin/cat $logfile
380*d583b39bSJohn Wren Kennedy		fi
381*d583b39bSJohn Wren Kennedy		/usr/bin/rm -f $logfile
382*d583b39bSJohn Wren Kennedy		logfile="$logfile.$$"
383*d583b39bSJohn Wren Kennedy        done
384*d583b39bSJohn Wren Kennedy}
385