Patch to remove segfault on the exiting of a service.
[openais.git] / exec / logsys.h
blob3bcfcf0d353b8f9902f173b6da1e6d676bbe0b59
1 /*
2 * Copyright (c) 2002-2004 MontaVista Software, Inc.
3 * Copyright (c) 2006-2007 Red Hat, Inc.
5 * Author: Steven Dake (sdake@redhat.com)
6 * Author: Lon Hohberger (lhh@redhat.com)
8 * All rights reserved.
10 * This software licensed under BSD license, the text of which follows:
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions are met:
15 * - Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * - Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * - Neither the name of the MontaVista Software, Inc. nor the names of its
21 * contributors may be used to endorse or promote products derived from this
22 * software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
34 * THE POSSIBILITY OF SUCH DAMAGE.
36 #ifndef LOGSYS_H_DEFINED
37 #define LOGSYS_H_DEFINED
39 #include <stdarg.h>
40 #include <syslog.h>
43 * MODE_OUTPUT_SYSLOG_* modes are mutually exclusive
45 #define LOG_MODE_OUTPUT_FILE (1<<0)
46 #define LOG_MODE_OUTPUT_STDERR (1<<1)
47 #define LOG_MODE_OUTPUT_SYSLOG_THREADED (1<<2)
48 #define LOG_MODE_OUTPUT_SYSLOG_LOSSY (1<<3)
49 #define LOG_MODE_OUTPUT_SYSLOG_BLOCKING (1<<4)
50 #define LOG_MODE_DISPLAY_PRIORITY (1<<5)
51 #define LOG_MODE_DISPLAY_FILELINE (1<<6)
52 #define LOG_MODE_DISPLAY_TIMESTAMP (1<<7)
53 #define LOG_MODE_DISPLAY_DEBUG (1<<8)
54 #define LOG_MODE_BUFFER_BEFORE_CONFIG (1<<9)
55 #define LOG_MODE_FLUSH_AFTER_CONFIG (1<<10)
58 * Log priorities, compliant with syslog and SA Forum Log spec.
60 #define LOG_LEVEL_EMERG LOG_EMERG
61 #define LOG_LEVEL_ALERT LOG_ALERT
62 #define LOG_LEVEL_CRIT LOG_CRIT
63 #define LOG_LEVEL_ERROR LOG_ERR
64 #define LOG_LEVEL_WARNING LOG_WARNING
65 #define LOG_LEVEL_SECURITY LOG_WARNING // openais specific
66 #define LOG_LEVEL_NOTICE LOG_NOTICE
67 #define LOG_LEVEL_INFO LOG_INFO
68 #define LOG_LEVEL_DEBUG LOG_DEBUG
71 ** Log tags, used by _logsys_trace macros, uses 32 bits => 32 different tags
72 */
73 #define LOGSYS_TAG_LOG (1<<0)
74 #define LOGSYS_TAG_ENTER (1<<1)
75 #define LOGSYS_TAG_LEAVE (1<<2)
76 #define LOGSYS_TAG_TRACE1 (1<<3)
77 #define LOGSYS_TAG_TRACE2 (1<<4)
78 #define LOGSYS_TAG_TRACE3 (1<<5)
79 #define LOGSYS_TAG_TRACE4 (1<<6)
80 #define LOGSYS_TAG_TRACE5 (1<<7)
81 #define LOGSYS_TAG_TRACE6 (1<<8)
82 #define LOGSYS_TAG_TRACE7 (1<<9)
83 #define LOGSYS_TAG_TRACE8 (1<<10)
86 * External API
89 struct logsys_logger {
90 char subsys[6];
91 unsigned int priority;
92 unsigned int tags;
93 unsigned int mode;
96 extern struct logsys_logger logsys_loggers[];
98 extern inline int logsys_mkpri (int priority, int id);
100 extern void logsys_config_mode_set (
101 unsigned int mode);
103 extern int logsys_config_file_set (
104 char **error_string,
105 char *file);
107 extern void logsys_config_facility_set (
108 char *name,
109 unsigned int facility);
111 extern unsigned int logsys_config_subsys_set (
112 const char *subsys,
113 unsigned int tags,
114 unsigned int priority);
116 extern int logsys_config_subsys_get (
117 const char *subsys,
118 unsigned int *tags,
119 unsigned int *priority);
121 extern int logsys_facility_id_get (
122 const char *name);
124 extern char *logsys_facility_name_get (
125 unsigned int facility);
127 extern int logsys_priority_id_get (
128 const char *name);
130 extern char *logsys_priority_name_get (
131 unsigned int priority);
133 extern void logsys_flush (void);
135 extern void logsys_atsegv (void);
138 * Internal APIs that must be globally exported
140 extern unsigned int _logsys_subsys_create (const char *ident,
141 unsigned int priority);
143 extern void _logsys_nosubsys_set (void);
145 extern int _logsys_wthread_create (void);
147 extern void logsys_log_printf (char *file, int line, int priority,
148 char *format, ...) __attribute__((format(printf, 4, 5)));
150 extern void _logsys_log_printf2 (char *file, int line, int priority,
151 int id, char *format, ...) __attribute__((format(printf, 5, 6)));
153 extern void _logsys_trace (char *file, int line, int tag, int id,
154 char *format, ...) __attribute__((format(printf, 5, 6)));
157 * External definitions
159 #define LOGSYS_DECLARE_SYSTEM(name,mode,file,facility) \
160 __attribute__ ((constructor)) static void logsys_system_init (void) \
162 char *error_string; \
164 logsys_config_mode_set (mode); \
165 logsys_config_file_set (&error_string, (file)); \
166 logsys_config_facility_set (name, (facility)); \
167 if (((mode) & LOG_MODE_BUFFER_BEFORE_CONFIG) == 0) { \
168 _logsys_wthread_create (); \
172 #define LOGSYS_DECLARE_NOSUBSYS(priority) \
173 static unsigned int logsys_subsys_id __attribute__((unused)); \
174 __attribute__ ((constructor)) static void logsys_nosubsys_init (void) \
176 _logsys_nosubsys_set(); \
177 logsys_subsys_id = \
178 _logsys_subsys_create ("MAIN", (priority)); \
181 #define LOGSYS_DECLARE_SUBSYS(subsys,priority) \
182 static unsigned int logsys_subsys_id __attribute__((unused)); \
183 __attribute__ ((constructor)) static void logsys_subsys_init (void) \
185 logsys_subsys_id = \
186 _logsys_subsys_create ((subsys), (priority)); \
189 #define log_printf(lvl, format, args...) do { \
190 if ((lvl) <= logsys_loggers[logsys_subsys_id].priority) { \
191 _logsys_log_printf2 (__FILE__, __LINE__, lvl, \
192 logsys_subsys_id, (format), ##args); \
194 } while(0)
196 #define dprintf(format, args...) do { \
197 if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
198 _logsys_log_printf2 (__FILE__, __LINE__, LOG_DEBUG, \
199 logsys_subsys_id, (format), ##args); \
201 } while(0)
203 #define ENTER_VOID() do { \
204 if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
205 _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_ENTER, \
206 logsys_subsys_id, ">%s\n", __FUNCTION__); \
208 } while(0)
210 #define ENTER(format, args...) do { \
211 if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
212 _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_ENTER, \
213 logsys_subsys_id, ">%s: " format, __FUNCTION__, \
214 ##args); \
216 } while(0)
218 #define LEAVE_VOID() do { \
219 if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
220 _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_LEAVE, \
221 logsys_subsys_id, "<%s\n", __FUNCTION__); \
223 } while(0)
225 #define LEAVE(format, args...) do { \
226 if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
227 _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_LEAVE, \
228 logsys_subsys_id, "<%s: " format, \
229 __FUNCTION__, ##args); \
231 } while(0)
233 #define TRACE1(format, args...) do { \
234 if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
235 _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE1, \
236 logsys_subsys_id, (format), ##args); \
238 } while(0)
240 #define TRACE2(format, args...) do { \
241 if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
242 _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE2, \
243 logsys_subsys_id, (format), ##args); \
245 } while(0)
247 #define TRACE3(format, args...) do { \
248 if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
249 _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE3, \
250 logsys_subsys_id, (format), ##args); \
252 } while(0)
254 #define TRACE4(format, args...) do { \
255 if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
256 _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE4, \
257 logsys_subsys_id, (format), ##args); \
259 } while(0)
261 #define TRACE5(format, args...) do { \
262 if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
263 _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE5, \
264 logsys_subsys_id, (format), ##args); \
266 } while(0)
268 #define TRACE6(format, args...) do { \
269 if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
270 _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE6, \
271 logsys_subsys_id, (format), ##args); \
273 } while(0)
275 #define TRACE7(format, args...) do { \
276 if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
277 _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE7, \
278 logsys_subsys_id, (format), ##args); \
280 } while(0)
282 #define TRACE8(format, args...) do { \
283 if (LOG_LEVEL_DEBUG <= logsys_loggers[logsys_subsys_id].priority) { \
284 _logsys_trace (__FILE__, __LINE__, LOGSYS_TAG_TRACE8, \
285 logsys_subsys_id, (format), ##args); \
287 } while(0)
289 extern void _logsys_config_priority_set (unsigned int id, unsigned int priority);
291 #define logsys_config_priority_set(priority) do { \
292 _logsys_config_priority_set (logsys_subsys_id, priority); \
293 } while(0)
295 #endif /* LOGSYS_H_DEFINED */