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