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 #
29 # start __stf_assertion__
30 #
31 # ASSERTION: context_044
32 # DESCRIPTION:
33 # Attempting to start a service with an inaccessible working_directory
34 # will result in an error. svc.startd will re-attempt to start
35 # the service until the error threshold is reached and, at that
36 # point, the service will be placed into maintenance state.
37 #
38 # end __stf_assertion__
39 #
40
41 . ${STF_TOOLS}/include/stf.kshlib
42 . ${STF_SUITE}/include/gltest.kshlib
43 . ${STF_SUITE}/include/svc.startd_config.kshlib
44 . ${STF_SUITE}/tests/svc.startd/include/svc.startd_common.kshlib
45
46 typeset service_setup=0
47 function cleanup {
48 common_cleanup
49 [[ -d $TESTDIR ]] && rm -rf $TESTDIR
50 }
51
52 trap cleanup 0 1 2 15
53
54 readonly ME=$(whence -p ${0})
55 readonly MYLOC=$(dirname ${ME})
56
57 DATA=$MYLOC
58
59 readonly registration_template=$DATA/service_044.xml
60
61 extract_assertion_info $ME
62
63 # make sure that the svc.startd is running
64 verify_daemon
65 if [ $? -ne 0 ]; then
66 print -- "--DIAG: $assertion: svc.startd is not executing. Cannot "
67 print -- " continue"
68 exit $STF_UNRESOLVED
69 fi
70
71 # Make sure the environment is clean - the test service isn't running
72 print -- "--INFO: Cleanup any old $test_FMRI state"
73 service_cleanup $test_service
74 if [ $? -ne 0 ]; then
75 print -- "--DIAG: $assertion: cleanup of a previous instance failed"
76 exit $STF_UNRESOLVED
77 fi
78
79 print -- "--INFO: create world read/writeable log file for the service"
80 rm -f $service_log
81 touch $service_log
82 if [ $? -ne 0 ]; then
83 print -- "--DIAG: $assertion: could not create log file"
84 exit $STF_UNRESOLVED
85 fi
86 chmod a+rw $service_log
87 if [ $? -ne 0 ]; then
88 print -- "--DIAG: $assertion: could not make log file world writeable"
89 exit $STF_UNRESOLVED
90 fi
91
92 echo "--INFO: enforce a+rx for all directories down to $RUNDIR"
93 typeset permdir=$RUNDIR
94 while :; do
95 [ $permdir = "/" ] && break
96 chmod a+rx $permdir
97 if [ $? -ne 0 ]; then
98 echo "--DIAG: $assertion: could not chmod $permdir a+rx"
99 exit $STF_UNRESOLVED
100 fi
101 permdir=$(dirname $permdir)
102 done
103
104
105 TESTDIR="$RUNDIR/test_dir"
106 if [ ! -d "$TESTDIR" ]; then
107 mkdir -p "$TESTDIR"
108 if [ $? -ne 0 ]; then
109 echo "--DIAG: $assertion: could not create $TESTDIR"
110 exit $STF_UNRESOLVED
111 fi
112 fi
113
114 chmod a-rwx "$TESTDIR"
115 if [ $? -ne 0 ]; then
116 echo "--DIAG: $assertion: could not set $TESTDIR to inacecssible"
117 exit $STF_UNRESOLVED
118 fi
119
120 print -- "--INFO: generating manifest for importation into repository"
121 manifest_generate $registration_template \
122 TEST_SERVICE=$test_service \
123 TEST_INSTANCE=$test_instance \
124 SERVICE_APP=$service_app \
125 LOGFILE=$service_log \
126 USERNAME=$ctx_user \
127 STARTINGDIR="$TESTDIR" \
128 STATEFILE=$service_state > $registration_file
129 manifest_zone_clean $registration_file
130
131 print -- "--INFO: Importing service into repository"
132 manifest_purgemd5 $registration_file
133 svccfg -v import $registration_file >$svccfg_errfile 2>&1
134
135 if [ $? -ne 0 ]; then
136 print -- "--DIAG: $assertion: Unable to import the service $test_FMRI"
137 print -- " error messages from svccfg: \"$(cat $svccfg_errfile)\""
138 exit $STF_UNRESOLVED
139 fi
140 service_setup=1
141
142 print -- "--INFO: Wait for $test_FMRI to goto maintenance"
143 service_wait_state $test_FMRI maintenance
144 if [ $? -ne 0 ]; then
145 print -- "--DIAG: $assertion: Service $test_FMRI did not go"
146 print -- " to maintenance. It was in '$(svcs -H -o STATE $test_FMRI)'"
147 exit $STF_FAIL
148 fi
149
150 print -- "--INFO: Cleaning up service"
151 cleanup
152
153 exit $STF_PASS