#!/bin/ksh

# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
# Copyright 2005-2008 Sun Microsystems, Inc. All rights reserved. 
#
# The contents of this file are subject to the terms of the GNU General Public
# License Version 3("GPL")(the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the License at
# https://common-agent-container.dev.java.net/bootstrap/legal/license.txt or
# www/bootstrap/legal/license.txt.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# When distributing the software, include this License Header Notice in each
# file and include the License file at www/bootstrap/legal/license.txt.
#
# Sun designates this particular file as subject to the "Classpath" exception
# as provided by Sun in the GPL Version 3 section of the License file that
# accompanied this code.
#
# If applicable, add the following below the License Header, with the fields
# enclosed by brackets [] replaced by your own identifying information:
#     "Portions Copyrighted [year] [name of copyright owner]"
#

# 
# This script, used only in solaris 10, is used to synchronize smf 
# and the java cacao container that should print an exit code when the start of 
# the container is finished.
# This exit code can be 0 (success) or one between 0 and 99
# For the moment we use 0, 1
#
# param taken : the  java container launch command ( should have 
# -Dcacao.print.status=true inside for the container to print an exit code)
#
# Loosely inspired from /usr/sadm/lib/smc/bin/smcwbemserver

$1 |&
_pid=$!
code=0
while true; do
	read -p bkg
         # in case of kill -9 of the private container
	 [ $? -ne 0 ] && echo "${_pid}" && return 1
	 if expr "$bkg" : '^[0-9][0-9]*$' > /dev/null 2>&1; then
			code=$bkg
			break
        fi
done

echo "${_pid}"
return ${code}
