xref: /titanic_52/usr/src/cmd/smserverd/smediad_err.c (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 
30 #include	<stdio.h>
31 #include	<stdlib.h>
32 #include	<stdarg.h>
33 #include	<unistd.h>
34 #include	<time.h>
35 #include	<syslog.h>
36 #include	<errno.h>
37 #include	<string.h>
38 #include	<sys/types.h>
39 #include	<sys/stat.h>
40 #include	<thread.h>
41 #include	<pthread.h>
42 #include	<synch.h>
43 #include	<sys/smedia.h>
44 #include	"smserver.h"
45 
46 #define	DEBUGMSG	"Level[%d]: %s"
47 
48 void
49 fatal(const char *fmt, ...)
50 {
51 	va_list		ap;
52 
53 	(void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
54 
55 	va_start(ap, fmt);
56 	(void) vsyslog(LOG_DAEMON|LOG_CRIT, fmt, ap);
57 	va_end(ap);
58 
59 	(void) pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
60 
61 	exit(-1);
62 }
63 
64 void
65 quit(const char *fmt, ...)
66 {
67 	va_list		ap;
68 
69 	(void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
70 
71 	va_start(ap, fmt);
72 	(void) vsyslog(LOG_DAEMON|LOG_ERR, fmt, ap);
73 	va_end(ap);
74 
75 	(void) pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
76 
77 	exit(0);
78 }
79 
80 
81 void
82 noise(const char *fmt, ...)
83 {
84 	va_list		ap;
85 
86 	(void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
87 
88 	va_start(ap, fmt);
89 	(void) vsyslog(LOG_DAEMON|LOG_WARNING, fmt, ap);
90 	va_end(ap);
91 
92 	(void) pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
93 }
94 
95 void
96 warning(const char *fmt, ...)
97 {
98 	va_list		ap;
99 
100 
101 	(void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
102 
103 	va_start(ap, fmt);
104 	(void) vsyslog(LOG_DAEMON|LOG_WARNING, fmt, ap);
105 	va_end(ap);
106 
107 	(void) pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
108 }
109 
110 
111 void
112 info(const char *fmt, ...)
113 {
114 	extern int	verbose;
115 	va_list		ap;
116 
117 
118 	if (verbose == 0) {
119 		return;
120 	}
121 
122 	(void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
123 
124 	va_start(ap, fmt);
125 	(void) vsyslog(LOG_DAEMON|LOG_INFO, fmt, ap);
126 	va_end(ap);
127 
128 	(void) pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
129 }
130 
131 /*PRINTFLIKE2*/
132 void
133 debug(uint_t level, const char *fmt, ...)
134 {
135 	extern int	debug_level;
136 	va_list		ap;
137 	char		dbgmsg[BUFSIZ];
138 
139 
140 
141 	if (level > debug_level) {
142 		return;
143 	}
144 
145 	(void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
146 
147 	(void) snprintf(dbgmsg, sizeof (dbgmsg), DEBUGMSG, level, fmt);
148 	va_start(ap, fmt);
149 	(void) vsyslog(LOG_DAEMON|LOG_DEBUG, dbgmsg, ap);
150 	va_end(ap);
151 
152 	(void) pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
153 }
154