1 | /***************************************
2 | $Revision: 1.5 $
3 |
4 | Error reporting (er) erroutines.h - header file for error reporting.
5 |
6 | Status: NOT REVUED, TESTED,
7 |
8 | Design and implementation by: Marek Bukowy
9 |
10 | ******************/ /******************
11 | Copyright (c) 1999 RIPE NCC
12 |
13 | All Rights Reserved
14 |
15 | Permission to use, copy, modify, and distribute this software and its
16 | documentation for any purpose and without fee is hereby granted,
17 | provided that the above copyright notice appear in all copies and that
18 | both that copyright notice and this permission notice appear in
19 | supporting documentation, and that the name of the author not be
20 | used in advertising or publicity pertaining to distribution of the
21 | software without specific, written prior permission.
22 |
23 | THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
24 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
25 | AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
26 | DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
27 | AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
28 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29 | ***************************************/
30 |
31 | #ifndef ER_H
32 | #define ER_H
33 |
34 | #include <stdio.h>
35 | #include <unistd.h>
36 | #include <stdlib.h>
37 | #include <assert.h>
38 | #include <time.h>
39 | #include <stdarg.h>
40 | #include <strings.h>
41 |
42 | #include <bitmask.h>
43 | #include <er_aspects.h>
44 | #include <stubs.h>
45 |
46 | #ifdef ER_IMPL
47 | #define EXTDEF
48 | #define EXTINI(a,b) a = b;
49 | #else
50 | #define EXTDEF extern
51 | #define EXTINI(a,b) extern a;
52 | #endif
53 |
54 | typedef unsigned int er_mask_t;
55 |
56 | typedef int er_ret_t;
57 |
58 | #define MNELEN 16
59 | typedef struct {
60 | er_ret_t code;
61 | char mnem[MNELEN];
62 | char text[80];
63 | } er_list_t;
64 |
65 |
66 | typedef struct {
67 | er_ret_t code;
68 | char name[4];
69 | char desc[80];
70 | er_list_t *errs;
71 | } er_main_t;
72 |
73 | #define ER_SEV_C 0x40000000 /*+ circular buffer dump +*/
74 | #define ER_SEV_F 0x20000000 /*+ fatal error +*/
75 | #define ER_SEV_E 0x10000000 /*+ error +*/
76 | #define ER_SEV_W 0x08000000 /*+ warning +*/
77 | #define ER_SEV_I 0x04000000 /*+ information +*/
78 | #define ER_SEV_D 0x02000000 /*+ debug message +*/
79 | #define ER_SEV_L 0x01000000 /*+ library error +*/
80 |
81 | #define ER_SEV_TXT 20
82 |
83 | #define ER_MSGLEN 256
84 | #define ER_ERRLEN 192
85 |
86 | typedef struct {
87 | int sev;
88 | char chr[2];
89 | char txt[ER_SEV_TXT];
90 | } er_level_t;
91 |
92 | #ifndef ER_IMPL /* for client modules */
93 | extern er_level_t er_level_a[];
94 | #else /* full definition */
95 | er_level_t er_level_a[] = {
96 | { ER_SEV_C, "?" , "BUG! bad sev: circ" },
97 | { ER_SEV_F, "F" , "fatal error" },
98 | { ER_SEV_E, "E" , "error" },
99 | { ER_SEV_W, "W" , "warning" },
100 | { ER_SEV_I, "I" , "information" },
101 | { ER_SEV_D, "D" , "debug msg" },
102 | { ER_SEV_L, "L" , "library err" },
103 | { 0, "-" , "BUG! no such sev 0" }
104 | };
105 | #endif /* ER_IMPL */
106 |
107 | #define DEFFAC(a,b) { FAC_##a, #a, b, a##_mod_err }
108 |
109 | /* the macro expects two arguments:
110 | capital letters symbol of the facility
111 | short (<80 chars) description
112 | which then are expanded, eg. DEFFAC(TT, "test facility") expands to:
113 | { FAC_TT , "TT", "test facility" , NULL} ,
114 | Therefore, the FAC_TT must be defined in the enum below.
115 | The er_fac_code_t enum must begin with FAC_NONE=0
116 | and must end with FAC_LAST.
117 | The er_main_err array must end with FAC_NONE.
118 |
119 | The user code must contain INITFAC(a) call early in the code that
120 | sets the pointer to the respective ??_mod_err array. There is nothing
121 | wrong in calling it twice, so don't hesitate if you must do it.
122 |
123 | After a facility number changes (eg. because another one was added or
124 | deleted before yours) ALL your code must be recompiled before linking.
125 | */
126 |
127 | #define ER_LASTTXT {-1} /* macro for use in error text arrays */
128 |
129 | #define ERDUP(a) a, #a
130 |
131 | #include "er_facilities.h"
132 |
133 | /*************************************************************************/
134 |
135 | /* mode values (bitmap: describes what kind of severity and mnemonic we
136 | want back. */
137 |
138 | /* bits 0-1 (values 0-3) - severity: */
139 |
140 | #define ER_M_SEVNONE 0 /* no severity indication */
141 | #define ER_M_SEVCHAR 1 /* one-letter severity indication */
142 | #define ER_M_SEVLONG 2 /* long severity indication */
143 |
144 | /* bit 2 (values 0 or 4) - mnemonic */
145 | #define ER_M_MNEMNONE 0
146 | #define ER_M_MNEMONIC 4
147 |
148 | /* bit 3 (values 0 or 8) - error text */
149 | #define ER_M_TEXTNONE 0
150 | #define ER_M_TEXTLONG 8
151 |
152 | /* bits 4-5 (values 0, 16, 32, 48) - user id's */
153 | #define ER_M_UIDNONE 0
154 | #define ER_M_UIDUID 16
155 | #define ER_M_UIDEUID 32
156 | #define ER_M_UIDBOTH 48
157 |
158 | /* bit 6 (values 0 or 64) - process id's */
159 | #define ER_M_PIDNONE 0
160 | #define ER_M_PIDFULL 64
161 |
162 | /* bit 7 (values 0 or 128) - facility symbol */
163 | #define ER_M_FACSYMB 128
164 |
165 |
166 | /* bit 8 (values 0 or 256) - program name (argv[0]) */
167 | #define ER_M_PROGNAME 256
168 |
169 | /* bit 9 (values 0 or 512) - current date and time */
170 | #define ER_M_DATETIME 512
171 |
172 | #define ER_M_THR_ID 2048
173 |
174 | #define ER_M_DEFAULT (ER_M_DATETIME | ER_M_FACSYMB | ER_M_SEVCHAR \
175 | | ER_M_MNEMONIC | ER_M_TEXTLONG | ER_M_PIDFULL \
176 | | ER_M_THR_ID | ER_M_PROGNAME )
177 |
178 |
179 |
180 | void ER_init(int argc, char **argv);
181 |
182 | #define ER_dbg_eq(mod, asp, typ, expr) \
183 | ER_dbg_va (mod, asp, #expr " = " typ, expr)
184 |
185 | void ER_perror(int facwhere, int errcode, ...);
186 | void ER_dbg_va( int facwhere, er_mask_t asp, char *txt, ...);
187 | int ER_anybody_wants( int facwhere, int errcode, er_mask_t asp );
188 |
189 | /* This is just provisional ! */
190 | typedef struct {
191 | FILE *fdes;
192 | /* file descriptor. This is REALLY provisional! */
193 | er_mask_t asp; /* mask of aspects */
194 | int sev; /* minimal severity */
195 | int mode; /* bitmask of output mode - bits of information that
196 | should be printed */
197 | } er_path_t;
198 |
199 | void ER_setpath(er_path_t *newset);
200 |
201 | #ifdef ER_IMPL
202 |
203 | /* global vars !!!!! must be set for reporting purposes.
204 | Must be initialised in main() by ER_init().
205 | */
206 | char er_progname[32];
207 | char er_pid[16];
208 |
209 | /* those are private variables */
210 |
211 | er_path_t er_provisional_struct;
212 | pthread_mutex_t er_pathlist_mutex;
213 | int er_pathlist_mutex_initialised = 0;
214 | #endif
215 |
216 | #undef EXTDEF
217 | #endif /* ER_H */
218 |
219 |
220 | #if 0
221 |
222 | typedef struct {
223 | mask_t fac_mask;
224 | mask_t asp_mask;
225 | int sev_min;
226 | int sev_max;
227 | unsigned err; // a specific error code - or 0 to mean all errors
228 | } er_filter_t;
229 |
230 |
231 | enum {
232 | ER_PATH_UNBUF=1, /* unbuffered file/socket access via a file descriptor */
233 | ER_PATH_BUFPTR, /* buffered file access via a FILE structure */
234 | ER_PATH_BUFNAM, /* buffered file access via a file name
235 | (file reopened for every message) */
236 | ER_PATH_EMAIL, /* e-mail constructed, send at the end or after one message
237 | depending on options */
238 | ER_PATH_SYSLOG /* syslog msg sent at every message */
239 | } er_path_mt;
240 |
241 |
242 | typedef struct {
243 | char active;
244 | pthread_mutex_t mutex;
245 | er_path_mt type;
246 | er_option_mt options;
247 | union {
248 | struct {
249 | int fd; /* int filedescr for FILEUNBUF */
250 | } unbuf;
251 | struct {
252 | FILE *fp; /* FILE* fp for FILEBUFPTR */
253 | } bufptr;
254 | struct {
255 | char filename[80]; /* filename for FILEBUFNAM */
256 | } bufnam;
257 | struct {
258 | char address[80]; /* address(es) for EMAIL */
259 | } email;
260 | struct {
261 | int facility; /* openlog(3) parameters for SYSLOG */
262 | int logopt;
263 | char ident[32];
264 | } syslog;
265 | } desc;
266 | } er_path_t;
267 |
268 |
269 |
270 | #endif