1 # 2 # CDDL HEADER START 3 # 4 # The contents of this file are subject to the terms of the 5 # Common Development and Distribution License (the License). 6 # You may not use this file except in compliance with the License. 7 # 8 # You can obtain a copy of the license at usr/src/CDDL.txt 9 # or http://www.opensolaris.org/os/licensing. 10 # See the License for the specific language governing permissions 11 # and limitations under the License. 12 # 13 # When distributing Covered Code, include this CDDL HEADER in each 14 # file and include the License file at usr/src/CDDL.txt. 15 # If applicable, add the following below this CDDL HEADER, with the 16 # fields enclosed by brackets [] replaced with your own identifying 17 # information: Portions Copyright [yyyy] [name of copyright owner] 18 # 19 # CDDL HEADER END 20 # 21 22 # 23 # Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24 # Use is subject to license terms. 25 # 26 # ident "@(#)functions.ksh 1.4 07/06/06 SMI" 27 # 28 29 PKG=SUNWsczone 30 METHOD=`basename $0` 31 LOGFILE=/var/tmp/${RESOURCE}_logfile 32 33 SCLOGGER=/usr/cluster/lib/sc/scds_syslog 34 35 syslog_tag() 36 { 37 # 38 # Data Service message format 39 # 40 41 ${SET_DEBUG} 42 43 print "SC[${PKG:-??}.${METHOD:-??}]:${RESOURCEGROUP:-??}:${RESOURCE:-??}" 44 } 45 46 scds_syslog() 47 { 48 49 # 50 # Log a message 51 # 52 53 ${SET_DEBUG} 54 55 ${SCLOGGER} "$@" & 56 } 57 58 debug_message() 59 { 60 # 61 # Output a debug message to syslog if required 62 # 63 64 if [ "${DEBUG}" = "${RESOURCE}" -o "${DEBUG}" = "ALL" ] 65 then 66 SET_DEBUG="set -x" 67 68 DEBUG_TEXT=$1 69 70 scds_syslog -p daemon.debug -t $(syslog_tag) -m \ 71 "%s" "${DEBUG_TEXT}" 72 else 73 SET_DEBUG= 74 fi 75 } 76 77 log_message() 78 { 79 # 80 # Output a message to syslog as required 81 # 82 83 debug_message "Function: log_message - Begin" 84 ${SET_DEBUG} 85 86 if [ -s "${LOGFILE}" ] 87 then 88 PRIORITY=$1 89 HEADER=$2 90 91 # 92 # Ensure the while loop only reads a closed file 93 # 94 95 strings ${LOGFILE} > ${LOGFILE}.copy 96 while read MSG_TXT 97 do 98 scds_syslog -p daemon.${PRIORITY} -t $(syslog_tag) -m \ 99 "%s - %s" \ 100 "${HEADER}" "${MSG_TXT}" 101 done < ${LOGFILE}.copy 102 103 cat /dev/null > ${LOGFILE} > /dev/null 104 cat /dev/null > ${LOGFILE}.copy 105 fi 106 107 debug_message "Function: log_message - End" 108 } 109