8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / cmd-inet / etc / init.d / ncalogd
blob7a435579b510561b29cc8dcdadcbe1e757e15d43
1 #!/sbin/sh
3 # CDDL HEADER START
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.
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.
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]
21 # CDDL HEADER END
24 # Copyright (c) 1998-2001 by Sun Microsystems, Inc.
25 # All rights reserved.
27 #ident "%Z%%M% %I% %E% SMI"
29 # Default location for script
30 ncalogd=/etc/init.d/ncalogd
31 success=1
33 # Default config values used by script
34 ncalogdconf=/etc/nca/ncalogd.conf
35 ncakmodconf=/etc/nca/ncakmod.conf
37 isValidFile() {
38 # Check if file exists
39 if [ ! -f $1 ]
40 then
41 # Create subdirectories
42 logd_dir=`/usr/bin/dirname $1`
43 if [ ! -d "$logd_dir" ]; then
44 /usr/bin/mkdir -m 0755 -p $logd_dir > /dev/null 2>&1
45 if [ $? != 0 ]; then
46 echo "Error: $ncalogd: unable to" \
47 "create directory $logd_dir"
48 return 1
51 # Create the log file
52 touch $1
53 if [ $? != 0 ]; then
54 echo "Error: ${ncalogd}: unable to create file $1"
55 return 1
59 # test if valid local file
60 df -l $1 > /dev/null 2>&1
61 if [ $? != 0 ]; then
62 echo "Error: $ncalogd: $1 is not a local file system"
63 return 1
65 return 0
68 isValidDev() {
69 # Check if device is valid
70 fsck -m $1 > /dev/null 2>&1
71 case $? in
72 36 | 39 )
73 return 0
75 0 | 32 | 33 | 40 )
76 echo "Error: $ncalogd: refusing to overwrite filesystem on $1"
77 return 1
79 * )
80 echo "Error: $ncalogd: $1 is an invalid device"
81 return 1
83 esac
86 case "$1" in
87 'start')
88 if [ ! -f $ncalogdconf ]; then
89 # If configuration file is missing, just exit
90 exit 0
93 . $ncalogdconf
95 # Default is "disabled" so we want to exit
96 [ "x$status" != "xenabled" ] && exit 0
98 . $ncakmodconf
100 # Default is "disabled" so we want to exit
101 [ "x$status" != "xenabled" ] && exit 0
103 for i in $logd_path_name; do
104 # make sure that specified logfile is not a directory
105 if [ -d $i ]; then
106 echo "Error: $ncalogd: $i is a directory"
107 continue
108 elif [ -b $i -o -c $i ]; then
109 # Check if file is a device
110 isValidDev $i || continue
111 else
112 isValidFile $i || continue
115 # Finally, set the specified file as a NCA log file
116 /usr/sbin/ndd -set /dev/nca nca_log_file $i
117 success=0
118 done
120 if [ $success = 0 ]; then
121 [ "x$logd_file_size" != "x" ] && \
122 /usr/sbin/ndd -set /dev/nca nca_log_size $logd_file_size
123 /usr/sbin/ndd -set /dev/nca nca_logging_on 1
127 'stop')
128 . $ncakmodconf
130 if [ "x$status" = "xenabled" ]; then
131 /usr/sbin/ndd -set /dev/nca nca_logging_on 0
136 echo "Usage: $0 { start | stop }"
137 exit 1
139 esac
140 exit 0