xref: /onnv-gate/usr/src/cmd/cmd-inet/etc/init.d/ncalogd (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!/sbin/sh
2*0Sstevel@tonic-gate#
3*0Sstevel@tonic-gate# CDDL HEADER START
4*0Sstevel@tonic-gate#
5*0Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*0Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
7*0Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
8*0Sstevel@tonic-gate# with the License.
9*0Sstevel@tonic-gate#
10*0Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*0Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
12*0Sstevel@tonic-gate# See the License for the specific language governing permissions
13*0Sstevel@tonic-gate# and limitations under the License.
14*0Sstevel@tonic-gate#
15*0Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
16*0Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*0Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
18*0Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
19*0Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
20*0Sstevel@tonic-gate#
21*0Sstevel@tonic-gate# CDDL HEADER END
22*0Sstevel@tonic-gate#
23*0Sstevel@tonic-gate#
24*0Sstevel@tonic-gate# Copyright (c) 1998-2001 by Sun Microsystems, Inc.
25*0Sstevel@tonic-gate# All rights reserved.
26*0Sstevel@tonic-gate#
27*0Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate# Default location for script
30*0Sstevel@tonic-gatencalogd=/etc/init.d/ncalogd
31*0Sstevel@tonic-gatesuccess=1
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gate# Default config values used by script
34*0Sstevel@tonic-gatencalogdconf=/etc/nca/ncalogd.conf
35*0Sstevel@tonic-gatencakmodconf=/etc/nca/ncakmod.conf
36*0Sstevel@tonic-gate
37*0Sstevel@tonic-gateisValidFile() {
38*0Sstevel@tonic-gate	# Check if file exists
39*0Sstevel@tonic-gate	if [ ! -f $1 ]
40*0Sstevel@tonic-gate	then
41*0Sstevel@tonic-gate		# Create subdirectories
42*0Sstevel@tonic-gate		logd_dir=`/usr/bin/dirname $1`
43*0Sstevel@tonic-gate		if [ ! -d "$logd_dir" ]; then
44*0Sstevel@tonic-gate			/usr/bin/mkdir -m 0755 -p $logd_dir > /dev/null 2>&1
45*0Sstevel@tonic-gate			if [ $? != 0 ]; then
46*0Sstevel@tonic-gate				echo "Error: $ncalogd: unable to" \
47*0Sstevel@tonic-gate				    "create directory $logd_dir"
48*0Sstevel@tonic-gate				return 1
49*0Sstevel@tonic-gate			fi
50*0Sstevel@tonic-gate		fi
51*0Sstevel@tonic-gate		# Create the log file
52*0Sstevel@tonic-gate		touch $1
53*0Sstevel@tonic-gate		if [ $? != 0 ]; then
54*0Sstevel@tonic-gate			echo "Error: ${ncalogd}: unable to create file $1"
55*0Sstevel@tonic-gate			return 1
56*0Sstevel@tonic-gate		fi
57*0Sstevel@tonic-gate	fi
58*0Sstevel@tonic-gate
59*0Sstevel@tonic-gate	# test if valid local file
60*0Sstevel@tonic-gate	df -l $1 > /dev/null 2>&1
61*0Sstevel@tonic-gate	if [ $? != 0 ]; then
62*0Sstevel@tonic-gate		echo "Error: $ncalogd: $1 is not a local file system"
63*0Sstevel@tonic-gate		return 1
64*0Sstevel@tonic-gate	fi
65*0Sstevel@tonic-gate	return 0
66*0Sstevel@tonic-gate}
67*0Sstevel@tonic-gate
68*0Sstevel@tonic-gateisValidDev() {
69*0Sstevel@tonic-gate	# Check if device is valid
70*0Sstevel@tonic-gate	fsck -m $1 > /dev/null 2>&1
71*0Sstevel@tonic-gate	case $? in
72*0Sstevel@tonic-gate	36 | 39 )
73*0Sstevel@tonic-gate		return 0
74*0Sstevel@tonic-gate		;;
75*0Sstevel@tonic-gate	0 | 32 | 33 | 40 )
76*0Sstevel@tonic-gate		echo "Error: $ncalogd: refusing to overwrite filesystem on $1"
77*0Sstevel@tonic-gate		return 1
78*0Sstevel@tonic-gate		;;
79*0Sstevel@tonic-gate	* )
80*0Sstevel@tonic-gate		echo "Error: $ncalogd: $1 is an invalid device"
81*0Sstevel@tonic-gate		return 1
82*0Sstevel@tonic-gate		;;
83*0Sstevel@tonic-gate	esac
84*0Sstevel@tonic-gate}
85*0Sstevel@tonic-gate
86*0Sstevel@tonic-gatecase "$1" in
87*0Sstevel@tonic-gate'start')
88*0Sstevel@tonic-gate	if [ ! -f $ncalogdconf ]; then
89*0Sstevel@tonic-gate		# If configuration file is missing, just exit
90*0Sstevel@tonic-gate		exit 0
91*0Sstevel@tonic-gate	fi
92*0Sstevel@tonic-gate
93*0Sstevel@tonic-gate	. $ncalogdconf
94*0Sstevel@tonic-gate
95*0Sstevel@tonic-gate	# Default is "disabled" so we want to exit
96*0Sstevel@tonic-gate	[ "x$status" != "xenabled" ] && exit 0
97*0Sstevel@tonic-gate
98*0Sstevel@tonic-gate	. $ncakmodconf
99*0Sstevel@tonic-gate
100*0Sstevel@tonic-gate	# Default is "disabled" so we want to exit
101*0Sstevel@tonic-gate	[ "x$status" != "xenabled" ] && exit 0
102*0Sstevel@tonic-gate
103*0Sstevel@tonic-gate	for i in $logd_path_name; do
104*0Sstevel@tonic-gate		# make sure that specified logfile is not a directory
105*0Sstevel@tonic-gate		if [ -d $i ]; then
106*0Sstevel@tonic-gate			echo "Error: $ncalogd: $i is a directory"
107*0Sstevel@tonic-gate			continue
108*0Sstevel@tonic-gate		elif [ -b $i -o -c $i ]; then
109*0Sstevel@tonic-gate		# Check if file is a device
110*0Sstevel@tonic-gate			isValidDev $i || continue
111*0Sstevel@tonic-gate		else
112*0Sstevel@tonic-gate			isValidFile $i || continue
113*0Sstevel@tonic-gate		fi
114*0Sstevel@tonic-gate
115*0Sstevel@tonic-gate		# Finally, set the specified file as a NCA log file
116*0Sstevel@tonic-gate		/usr/sbin/ndd -set /dev/nca nca_log_file $i
117*0Sstevel@tonic-gate		success=0
118*0Sstevel@tonic-gate	done
119*0Sstevel@tonic-gate
120*0Sstevel@tonic-gate	if [ $success = 0 ]; then
121*0Sstevel@tonic-gate		[ "x$logd_file_size" != "x" ] && \
122*0Sstevel@tonic-gate		    /usr/sbin/ndd -set /dev/nca nca_log_size $logd_file_size
123*0Sstevel@tonic-gate		/usr/sbin/ndd -set /dev/nca nca_logging_on 1
124*0Sstevel@tonic-gate	fi
125*0Sstevel@tonic-gate	;;
126*0Sstevel@tonic-gate
127*0Sstevel@tonic-gate'stop')
128*0Sstevel@tonic-gate	. $ncakmodconf
129*0Sstevel@tonic-gate
130*0Sstevel@tonic-gate	if [ "x$status" = "xenabled" ]; then
131*0Sstevel@tonic-gate		/usr/sbin/ndd -set /dev/nca nca_logging_on 0
132*0Sstevel@tonic-gate	fi
133*0Sstevel@tonic-gate	;;
134*0Sstevel@tonic-gate
135*0Sstevel@tonic-gate*)
136*0Sstevel@tonic-gate	echo "Usage: $0 { start | stop }"
137*0Sstevel@tonic-gate	exit 1
138*0Sstevel@tonic-gate	;;
139*0Sstevel@tonic-gateesac
140*0Sstevel@tonic-gateexit 0
141