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 2008 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "@(#)log.c 1.7 08/05/05 SMI" 28 29 #include <unistd.h> 30 #include <stdarg.h> 31 #include <stdio.h> 32 #include <string.h> 33 #include <errno.h> 34 #include <syslog.h> 35 #include <pthread.h> 36 #include "hbs_head.h" 37 38 extern int debug; 39 40 /* 41 * Note: openlog() shouldn't be called, since it'll interfere with the 42 * sc_syslog facility, such as resetting the id string. User of these 43 * functions should ensure sc_syslog_msg_initialize() be used to 44 * initialize syslog. 45 */ 46 47 48 /* 49 * General syslog routine for debug messages. System call error reporting 50 * should using log_syserr instead. 51 */ 52 void 53 log_debug(char *fmt, ...) 54 { 55 static char syslog_output[LINELEN]; 56 va_list ap; 57 58 /*lint -e40 Undeclared identifier (__builtin_va_alist) */ 59 va_start(ap, fmt); 60 /*lint +e40 */ 61 (void) vsnprintf(syslog_output, 62 sizeof (syslog_output), fmt, ap); 63 va_end(ap); 64 65 DEBUGP((stderr, "%s\n", syslog_output)); 66 if (debug) { 67 syslog(LOG_DEBUG, "%s[%d]: %s", 68 msg_gchb, pthread_self(), syslog_output); 69 } 70 } 71 72 void 73 log_syserr(char *fmt, ...) 74 { 75 static char buf[LINELEN]; 76 va_list ap; 77 int err = errno; /*lint !e746 */ 78 79 /*lint -e40 Undeclared identifier (__builtin_va_alist) */ 80 va_start(ap, fmt); 81 /*lint +e40 */ 82 (void) vsnprintf(buf, LINELEN, fmt, ap); 83 va_end(ap); 84 85 if (err != 0) { 86 (void) strcat(buf, ": "); 87 (void) strcat(buf, strerror(err)); 88 } 89 90 DEBUGP((stderr, "%s\n", buf)); 91 (void) sc_syslog_msg_log(msg_gchb, SC_SYSLOG_ERROR, MESSAGE, 92 "GCHB system error: %s", buf); 93 } 94 95 void 96 log_conferr(char *fmt, ...) 97 { 98 static char buf[LINELEN]; 99 va_list ap; 100 101 /*lint -e40 Undeclared identifier (__builtin_va_alist) */ 102 va_start(ap, fmt); 103 /*lint +e40 */ 104 (void) vsnprintf(buf, LINELEN, fmt, ap); 105 va_end(ap); 106 107 DEBUGP((stderr, "%s\n", buf)); 108 log_debug("GCHB config error: %s", buf); 109 } 110 111 void 112 log_sysinfo(char *fmt, ...) 113 { 114 static char buf[LINELEN]; 115 va_list ap; 116 117 /*lint -e40 Undeclared identifier (__builtin_va_alist) */ 118 va_start(ap, fmt); 119 /*lint +e40 */ 120 (void) vsnprintf(buf, LINELEN, fmt, ap); 121 va_end(ap); 122 123 DEBUGP((stderr, "%s\n", buf)); 124 (void) sc_syslog_msg_log(msg_gchb, SC_SYSLOG_NOTICE, MESSAGE, 125 "GCHB info: %s", buf); 126 } 127