xref: /illumos-gate/usr/src/lib/sun_sas/common/log.c (revision 9e86db79)
1*9e86db79SHyon Kim /*
2*9e86db79SHyon Kim  * CDDL HEADER START
3*9e86db79SHyon Kim  *
4*9e86db79SHyon Kim  * The contents of this file are subject to the terms of the
5*9e86db79SHyon Kim  * Common Development and Distribution License (the "License").
6*9e86db79SHyon Kim  * You may not use this file except in compliance with the License.
7*9e86db79SHyon Kim  *
8*9e86db79SHyon Kim  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*9e86db79SHyon Kim  * or http://www.opensolaris.org/os/licensing.
10*9e86db79SHyon Kim  * See the License for the specific language governing permissions
11*9e86db79SHyon Kim  * and limitations under the License.
12*9e86db79SHyon Kim  *
13*9e86db79SHyon Kim  * When distributing Covered Code, include this CDDL HEADER in each
14*9e86db79SHyon Kim  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*9e86db79SHyon Kim  * If applicable, add the following below this CDDL HEADER, with the
16*9e86db79SHyon Kim  * fields enclosed by brackets "[]" replaced with your own identifying
17*9e86db79SHyon Kim  * information: Portions Copyright [yyyy] [name of copyright owner]
18*9e86db79SHyon Kim  *
19*9e86db79SHyon Kim  * CDDL HEADER END
20*9e86db79SHyon Kim  */
21*9e86db79SHyon Kim 
22*9e86db79SHyon Kim /*
23*9e86db79SHyon Kim  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24*9e86db79SHyon Kim  * Use is subject to license terms.
25*9e86db79SHyon Kim  */
26*9e86db79SHyon Kim 
27*9e86db79SHyon Kim #include <stdio.h>
28*9e86db79SHyon Kim #include <sys/types.h>
29*9e86db79SHyon Kim #include <sys/varargs.h>
30*9e86db79SHyon Kim #include <errno.h>
31*9e86db79SHyon Kim #include <string.h>
32*9e86db79SHyon Kim 
33*9e86db79SHyon Kim #include <sun_sas.h>
34*9e86db79SHyon Kim 
35*9e86db79SHyon Kim #define	MAX_LOG_LEN 2048
36*9e86db79SHyon Kim 
37*9e86db79SHyon Kim void
log(int level,const char * routine,char * msg,...)38*9e86db79SHyon Kim log(
39*9e86db79SHyon Kim 	int level,
40*9e86db79SHyon Kim 	const char *routine,
41*9e86db79SHyon Kim 	char *msg,
42*9e86db79SHyon Kim 	...
43*9e86db79SHyon Kim )
44*9e86db79SHyon Kim {
45*9e86db79SHyon Kim 	char header[MAX_LOG_LEN+1];
46*9e86db79SHyon Kim 	char message[MAX_LOG_LEN+1];
47*9e86db79SHyon Kim 	int oldErrno = 0;
48*9e86db79SHyon Kim 	va_list ap;
49*9e86db79SHyon Kim 
50*9e86db79SHyon Kim 	oldErrno = errno;
51*9e86db79SHyon Kim 
52*9e86db79SHyon Kim 	(void) memset(&header,  0, MAX_LOG_LEN+1);
53*9e86db79SHyon Kim 	(void) memset(&message, 0, MAX_LOG_LEN+1);
54*9e86db79SHyon Kim 
55*9e86db79SHyon Kim 	va_start(ap, msg);
56*9e86db79SHyon Kim 	(void) snprintf(header, MAX_LOG_LEN, "%s: %s: %s",
57*9e86db79SHyon Kim 	    "SM-HBA Sun SAS VSL", routine, msg);
58*9e86db79SHyon Kim 
59*9e86db79SHyon Kim 	/* LINTED E_SEC_PRINTF_VAR_FMT */
60*9e86db79SHyon Kim 	(void) vsnprintf(message, MAX_LOG_LEN, header, ap);
61*9e86db79SHyon Kim 
62*9e86db79SHyon Kim 	/* LINTED E_SEC_PRINTF_VAR_FMT */
63*9e86db79SHyon Kim 	syslog(level, message);
64*9e86db79SHyon Kim 
65*9e86db79SHyon Kim 	va_end(ap);
66*9e86db79SHyon Kim 
67*9e86db79SHyon Kim 	errno = oldErrno;
68*9e86db79SHyon Kim }