1 #! /usr/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 # A script to clean up any stray instances of service_app before starting
29 # the svccfg apply tests.
30
31 # Load the STF library
32 . ${STF_TOOLS}/include/stf.kshlib
33 # for find_nontransient_pids
34 . ${STF_SUITE}/include/gltest.kshlib
35
36 # This is our test service app name
37 typeset SERVICE_APP=${STF_SUITE}/tests/bin/${STF_EXECUTE_MODE}/service_app
38 typeset -i result=$STF_PASS
39
40 # Verify that no instance of ${SERVICE_APP} is currently running
41 SVC_APP=${SERVICE_APP##*/}
42 typeset pids=$(find_nontransient_pids ${SVC_APP})
43 typeset -i num_apps=$?
44 if [[ $num_apps -eq 0 ]]; then
45 echo "--INFO: Success
46 No instance of ${SVC_APP} was found running on the system"
47
48 echo "--RSLT: ${STF_RESULT_NAMES[$STF_PASS]}"
49 exit $STF_PASS
50 fi
51
52 # If we are here, at least one stray instance was found.
53 #
54 echo "--INFO: Attempting to kill all ${SVC_APP} processes"
55 pkill -9 -z $(zonename) ${SVC_APP} >/dev/null 2>&1
56
57 # If we still couldn't kill all service_app processes, it will
58 # interfere with the rest of the tests in this directory. Therefore,
59 # we exit with UNRESOLVED, so that the tests are not even executed.
60 num_apps=$(pgrep -z $(zonename) $SVC_APP 2>/dev/null | wc -l)
61 [[ $num_apps -ne 0 ]] && {
62 echo "--DIAG: Fatal error: pkill failed
63 EXPECTED: All instances of ${SVC_APP} were killed
64 RETURNED: $num_apps instances are still running"
65
66 result=$STF_UNRESOLVED
67 }
68
69 echo "--RSLT: ${STF_RESULT_NAMES[$result]}"
70 exit $result