xref: /titanic_41/usr/src/cmd/power/svc-power (revision b86efd96f8acd85ddaa930a2f0c1d664237e4aaf)
1#!/sbin/sh
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, Version 1.0 only
7# (the "License").  You may not use this file except in compliance
8# with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23#
24# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27#ident	"%Z%%M%	%I%	%E% SMI"
28#
29# If the /etc/power.conf file does not have a "statefile" entry
30# to specify the pathname of the cpr statefile, build one and
31# add the line.  We choose the largest of the standard Sun partitions.
32
33init_statefile_entry() {
34	[ ! -f /etc/power.conf -o ! -w /etc/power.conf ] && return
35
36	# Whitespace regular expression below is [<TAB><SPACE>]
37
38	pattern="^[ 	]*statefile[	 ][	 ]*/"
39	[ `/usr/bin/grep -c "$pattern" /etc/power.conf` -ge 1 ] && return
40
41	avail=0			# Free blocks in current filesystem
42	max_avail=0		# Most available free blocks encountered so far
43 	statefile=.CPR		# Default cpr statefile name
44
45	# Remove old statefile (if any) from root
46	[ -f /$statefile ] && /usr/bin/rm -f /$statefile
47
48	/usr/bin/df -k -F ufs |
49	(
50		read line	# Skip past the header line of the df output
51
52		while read device kbytes used avail capacity filesys; do
53			case $filesys in
54			/|/usr|/var|/export/home)
55				if [ $avail -gt $max_avail ]; then
56					max_avail=$avail
57					winner=$filesys
58				fi
59				;;
60			esac
61		done
62
63		if [ $max_avail -gt 0 ]; then
64			echo "statefile		${winner}/${statefile}" \
65			    >>/etc/power.conf
66		fi
67
68		return
69	)
70}
71
72case "$1" in
73'start')
74	[ -z "$_INIT_UTS_ISA" ] && _INIT_UTS_ISA=`/usr/bin/uname -p`
75
76	if [ $_INIT_UTS_ISA = sparc ]; then
77		init_statefile_entry
78	fi
79
80	if [ -x /usr/sbin/pmconfig -a -r /etc/power.conf ]; then
81		/usr/sbin/pmconfig >/dev/console 2>&1
82	fi
83	;;
84
85'stop')
86	if [ -x /usr/sbin/pmconfig ]; then
87		/usr/sbin/pmconfig -r >/dev/null 2>/dev/null
88	fi
89	;;
90
91*)
92	echo "Usage: $0 { start | stop }"
93	exit 1
94	;;
95esac
96exit 0
97