Version 1.8.0.0
[socat.git] / error.h
blob9853f8ad12cf65dad2c0074ce8c159f1383caffb
1 /* source: error.h */
2 /* Copyright Gerhard Rieger and contributors (see file CHANGES) */
3 /* Published under the GNU General Public License V.2, see file COPYING */
5 #ifndef __error_h_included
6 #define __error_h_included 1
8 /* these must be defines because they are used by cpp! */
9 #define E_DEBUG 0 /* all, including trace */
10 #define E_INFO 1 /* all status changes etc. */
11 #define E_NOTICE 2 /* all interesting, e.g. for firewall relay */
12 #define E_WARN 3 /* all unusual */
13 #define E_ERROR 4 /* errors */
14 #define E_FATAL 5 /* emergency abort */
16 #define F_strerror "%m" /* a pseudo format, replaced by strerror(errno) */
18 /* here are the macros for diag invocation; use WITH_MSGLEVEL to specify the
19 lowest priority that is compiled into your program */
20 #ifndef WITH_MSGLEVEL
21 # define WITH_MSGLEVEL E_NOTICE
22 #endif
24 #if WITH_MSGLEVEL <= E_FATAL
25 #define Fatal(m) msg(E_FATAL,"%s",m)
26 #define Fatal1(m,a1) msg(E_FATAL,m,a1)
27 #define Fatal2(m,a1,a2) msg(E_FATAL,m,a1,a2)
28 #define Fatal3(m,a1,a2,a3) msg(E_FATAL,m,a1,a2,a3)
29 #define Fatal4(m,a1,a2,a3,a4) msg(E_FATAL,m,a1,a2,a3,a4)
30 #define Fatal5(m,a1,a2,a3,a4,a5) msg(E_FATAL,m,a1,a2,a3,a4,a5)
31 #define Fatal6(m,a1,a2,a3,a4,a5,a6) msg(E_FATAL,m,a1,a2,a3,a4,a5,a6)
32 #define Fatal7(m,a1,a2,a3,a4,a5,a6,a7) msg(E_FATAL,m,a1,a2,a3,a4,a5,a6,a7)
33 #else /* !(WITH_MSGLEVEL <= E_FATAL) */
34 #define Fatal(m)
35 #define Fatal1(m,a1)
36 #define Fatal2(m,a1,a2)
37 #define Fatal3(m,a1,a2,a3)
38 #define Fatal4(m,a1,a2,a3,a4)
39 #define Fatal5(m,a1,a2,a3,a4,a5)
40 #define Fatal6(m,a1,a2,a3,a4,a5,a6)
41 #define Fatal7(m,a1,a2,a3,a4,a5,a6,a7)
42 #endif /* !(WITH_MSGLEVEL <= E_FATAL) */
44 #if WITH_MSGLEVEL <= E_ERROR
45 #define Error(m) msg(E_ERROR,"%s",m)
46 #define Error1(m,a1) msg(E_ERROR,m,a1)
47 #define Error2(m,a1,a2) msg(E_ERROR,m,a1,a2)
48 #define Error3(m,a1,a2,a3) msg(E_ERROR,m,a1,a2,a3)
49 #define Error4(m,a1,a2,a3,a4) msg(E_ERROR,m,a1,a2,a3,a4)
50 #define Error5(m,a1,a2,a3,a4,a5) msg(E_ERROR,m,a1,a2,a3,a4,a5)
51 #define Error6(m,a1,a2,a3,a4,a5,a6) msg(E_ERROR,m,a1,a2,a3,a4,a5,a6)
52 #define Error7(m,a1,a2,a3,a4,a5,a6,a7) msg(E_ERROR,m,a1,a2,a3,a4,a5,a6,a7)
53 #define Error8(m,a1,a2,a3,a4,a5,a6,a7,a8) msg(E_ERROR,m,a1,a2,a3,a4,a5,a6,a7,a8)
54 #define Error9(m,a1,a2,a3,a4,a5,a6,a7,a8,a9) msg(E_ERROR,m,a1,a2,a3,a4,a5,a6,a7,a8,a9)
55 #define Error10(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) msg(E_ERROR,m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)
56 #define Error11(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11) msg(E_ERROR,m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11)
57 #else /* !(WITH_MSGLEVEL >= E_ERROR) */
58 #define Error(m)
59 #define Error1(m,a1)
60 #define Error2(m,a1,a2)
61 #define Error3(m,a1,a2,a3)
62 #define Error4(m,a1,a2,a3,a4)
63 #define Error5(m,a1,a2,a3,a4,a5)
64 #define Error6(m,a1,a2,a3,a4,a5,a6)
65 #define Error7(m,a1,a2,a3,a4,a5,a6,a7)
66 #define Error8(m,a1,a2,a3,a4,a5,a6,a7,a8)
67 #define Error9(m,a1,a2,a3,a4,a5,a6,a7,a8,a9)
68 #define Error10(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)
69 #define Error11(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11)
70 #endif /* !(WITH_MSGLEVEL <= E_ERROR) */
72 #if WITH_MSGLEVEL <= E_WARN
73 #define Warn(m) msg(E_WARN,"%s",m)
74 #define Warn1(m,a1) msg(E_WARN,m,a1)
75 #define Warn2(m,a1,a2) msg(E_WARN,m,a1,a2)
76 #define Warn3(m,a1,a2,a3) msg(E_WARN,m,a1,a2,a3)
77 #define Warn4(m,a1,a2,a3,a4) msg(E_WARN,m,a1,a2,a3,a4)
78 #define Warn5(m,a1,a2,a3,a4,a5) msg(E_WARN,m,a1,a2,a3,a4,a5)
79 #define Warn6(m,a1,a2,a3,a4,a5,a6) msg(E_WARN,m,a1,a2,a3,a4,a5,a6)
80 #define Warn7(m,a1,a2,a3,a4,a5,a6,a7) msg(E_WARN,m,a1,a2,a3,a4,a5,a6,a7)
81 #else /* !(WITH_MSGLEVEL <= E_WARN) */
82 #define Warn(m)
83 #define Warn1(m,a1)
84 #define Warn2(m,a1,a2)
85 #define Warn3(m,a1,a2,a3)
86 #define Warn4(m,a1,a2,a3,a4)
87 #define Warn5(m,a1,a2,a3,a4,a5)
88 #define Warn6(m,a1,a2,a3,a4,a5,a6)
89 #define Warn7(m,a1,a2,a3,a4,a5,a6,a7)
90 #endif /* !(WITH_MSGLEVEL <= E_WARN) */
92 #if WITH_MSGLEVEL <= E_NOTICE
93 #define Notice(m) msg(E_NOTICE,"%s",m)
94 #define Notice1(m,a1) msg(E_NOTICE,m,a1)
95 #define Notice2(m,a1,a2) msg(E_NOTICE,m,a1,a2)
96 #define Notice3(m,a1,a2,a3) msg(E_NOTICE,m,a1,a2,a3)
97 #define Notice4(m,a1,a2,a3,a4) msg(E_NOTICE,m,a1,a2,a3,a4)
98 #define Notice5(m,a1,a2,a3,a4,a5) msg(E_NOTICE,m,a1,a2,a3,a4,a5)
99 #define Notice6(m,a1,a2,a3,a4,a5,a6) msg(E_NOTICE,m,a1,a2,a3,a4,a5,a6)
100 #define Notice7(m,a1,a2,a3,a4,a5,a6,a7) msg(E_NOTICE,m,a1,a2,a3,a4,a5,a6,a7)
101 #define Notice8(m,a1,a2,a3,a4,a5,a6,a7,a8) msg(E_NOTICE,m,a1,a2,a3,a4,a5,a6,a7,a8)
102 #define Notice9(m,a1,a2,a3,a4,a5,a6,a7,a8,a9) msg(E_NOTICE,m,a1,a2,a3,a4,a5,a6,a7,a8,a9)
103 #else /* !(WITH_MSGLEVEL <= E_NOTICE) */
104 #define Notice(m)
105 #define Notice1(m,a1)
106 #define Notice2(m,a1,a2)
107 #define Notice3(m,a1,a2,a3)
108 #define Notice4(m,a1,a2,a3,a4)
109 #define Notice5(m,a1,a2,a3,a4,a5)
110 #define Notice6(m,a1,a2,a3,a4,a5,a6)
111 #define Notice7(m,a1,a2,a3,a4,a5,a6,a7)
112 #define Notice8(m,a1,a2,a3,a4,a5,a6,a7,a8)
113 #define Notice9(m,a1,a2,a3,a4,a5,a6,a7,a8,a9)
114 #endif /* !(WITH_MSGLEVEL <= E_NOTICE) */
116 #if WITH_MSGLEVEL <= E_INFO
117 #define Info(m) msg(E_INFO,"%s",m)
118 #define Info1(m,a1) msg(E_INFO,m,a1)
119 #define Info2(m,a1,a2) msg(E_INFO,m,a1,a2)
120 #define Info3(m,a1,a2,a3) msg(E_INFO,m,a1,a2,a3)
121 #define Info4(m,a1,a2,a3,a4) msg(E_INFO,m,a1,a2,a3,a4)
122 #define Info5(m,a1,a2,a3,a4,a5) msg(E_INFO,m,a1,a2,a3,a4,a5)
123 #define Info6(m,a1,a2,a3,a4,a5,a6) msg(E_INFO,m,a1,a2,a3,a4,a5,a6)
124 #define Info7(m,a1,a2,a3,a4,a5,a6,a7) msg(E_INFO,m,a1,a2,a3,a4,a5,a6,a7)
125 #define Info8(m,a1,a2,a3,a4,a5,a6,a7,a8) msg(E_INFO,m,a1,a2,a3,a4,a5,a6,a7,a8)
126 #define Info9(m,a1,a2,a3,a4,a5,a6,a7,a8,a9) msg(E_INFO,m,a1,a2,a3,a4,a5,a6,a7,a8,a9)
127 #define Info10(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) msg(E_INFO,m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)
128 #define Info11(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11) msg(E_INFO,m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11)
129 #else /* !(WITH_MSGLEVEL <= E_INFO) */
130 #define Info(m)
131 #define Info1(m,a1)
132 #define Info2(m,a1,a2)
133 #define Info3(m,a1,a2,a3)
134 #define Info4(m,a1,a2,a3,a4)
135 #define Info5(m,a1,a2,a3,a4,a5)
136 #define Info6(m,a1,a2,a3,a4,a5,a6)
137 #define Info7(m,a1,a2,a3,a4,a5,a6,a7)
138 #define Info8(m,a1,a2,a3,a4,a5,a6,a7,a8)
139 #define Info9(m,a1,a2,a3,a4,a5,a6,a7,a8,a9)
140 #define Info10(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)
141 #define Info11(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11)
142 #endif /* !(WITH_MSGLEVEL <= E_INFO) */
144 #if WITH_MSGLEVEL <= E_DEBUG
145 #define Debug(m) msg(E_DEBUG,"%s",m)
146 #define Debug1(m,a1) msg(E_DEBUG,m,a1)
147 #define Debug2(m,a1,a2) msg(E_DEBUG,m,a1,a2)
148 #define Debug3(m,a1,a2,a3) msg(E_DEBUG,m,a1,a2,a3)
149 #define Debug4(m,a1,a2,a3,a4) msg(E_DEBUG,m,a1,a2,a3,a4)
150 #define Debug5(m,a1,a2,a3,a4,a5) msg(E_DEBUG,m,a1,a2,a3,a4,a5)
151 #define Debug6(m,a1,a2,a3,a4,a5,a6) msg(E_DEBUG,m,a1,a2,a3,a4,a5,a6)
152 #define Debug7(m,a1,a2,a3,a4,a5,a6,a7) msg(E_DEBUG,m,a1,a2,a3,a4,a5,a6,a7)
153 #define Debug8(m,a1,a2,a3,a4,a5,a6,a7,a8) msg(E_DEBUG,m,a1,a2,a3,a4,a5,a6,a7,a8)
154 #define Debug9(m,a1,a2,a3,a4,a5,a6,a7,a8,a9) msg(E_DEBUG,m,a1,a2,a3,a4,a5,a6,a7,a8,a9)
155 #define Debug10(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) msg(E_DEBUG,m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)
156 #define Debug11(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11) msg(E_DEBUG,m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11)
157 #define Debug12(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12) msg(E_DEBUG,m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12)
158 #define Debug13(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13) msg(E_DEBUG,m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13)
159 #define Debug14(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14) msg(E_DEBUG,m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14)
160 #define Debug15(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15) msg(E_DEBUG,m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15)
161 #define Debug16(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16) msg(E_DEBUG,m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16)
162 #define Debug17(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17) msg(E_DEBUG,m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17)
163 #define Debug18(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18) msg(E_DEBUG,m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18)
164 #else /* !(WITH_MSGLEVEL <= E_DEBUG) */
165 #define Debug(m)
166 #define Debug1(m,a1)
167 #define Debug2(m,a1,a2)
168 #define Debug3(m,a1,a2,a3)
169 #define Debug4(m,a1,a2,a3,a4)
170 #define Debug5(m,a1,a2,a3,a4,a5)
171 #define Debug6(m,a1,a2,a3,a4,a5,a6)
172 #define Debug7(m,a1,a2,a3,a4,a5,a6,a7)
173 #define Debug8(m,a1,a2,a3,a4,a5,a6,a7,a8)
174 #define Debug9(m,a1,a2,a3,a4,a5,a6,a7,a8,a9)
175 #define Debug10(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)
176 #define Debug11(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11)
177 #define Debug12(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12)
178 #define Debug13(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13)
179 #define Debug14(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14)
180 #define Debug15(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15)
181 #define Debug16(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16)
182 #define Debug17(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17)
183 #define Debug18(m,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18)
184 #endif /* !(WITH_MSGLEVEL <= E_DEBUG) */
186 /* message with software controlled serverity */
187 #if WITH_MSGLEVEL <= E_FATAL
188 #define Msg(l,m) msg(l,"%s",m)
189 #define Msg1(l,m,a1) msg(l,m,a1)
190 #define Msg2(l,m,a1,a2) msg(l,m,a1,a2)
191 #define Msg3(l,m,a1,a2,a3) msg(l,m,a1,a2,a3)
192 #define Msg4(l,m,a1,a2,a3,a4) msg(l,m,a1,a2,a3,a4)
193 #define Msg5(l,m,a1,a2,a3,a4,a5) msg(l,m,a1,a2,a3,a4,a5)
194 #define Msg6(l,m,a1,a2,a3,a4,a5,a6) msg(l,m,a1,a2,a3,a4,a5,a6)
195 #define Msg7(l,m,a1,a2,a3,a4,a5,a6,a7) msg(l,m,a1,a2,a3,a4,a5,a6,a7)
196 #else /* !(WITH_MSGLEVEL >= E_FATAL) */
197 #define Msg(l,m)
198 #define Msg1(l,m,a1)
199 #define Msg2(l,m,a1,a2)
200 #define Msg3(l,m,a1,a2,a3)
201 #define Msg4(l,m,a1,a2,a3,a4)
202 #define Msg5(l,m,a1,a2,a3,a4,a5)
203 #define Msg6(l,m,a1,a2,a3,a4,a5,a6)
204 #define Msg7(l,m,a1,a2,a3,a4,a5,a6,a7)
205 #endif /* !(WITH_MSGLEVEL <= E_FATAL) */
208 enum diag_op {
209 DIAG_OP_MSG, /* a diagnostic message */
210 DIAG_OP_EXIT, /* exit the program */
213 /* datagram for communication between outer msg() call from signal handler to
214 inner msg() call in normal flow */
215 # define TEXTLEN 480
216 struct diag_dgram {
217 enum diag_op op;
218 #if HAVE_CLOCK_GETTIME
219 struct timespec now;
220 #elif HAVE_PROTOTYPE_LIB_gettimeofday
221 struct timeval now;
222 #else
223 time_t now;
224 #endif
225 int level; /* E_FATAL, ... E_DEBUG */
226 int _errno; /* for glibc %m format */
227 int exitcode; /* if exiting take this num */
228 char text[TEXTLEN];
231 extern volatile sig_atomic_t diag_in_handler;
232 extern volatile sig_atomic_t diag_immediate_msg;
233 extern volatile sig_atomic_t diag_immediate_exit;
235 extern void diag_set(char what, const char *arg);
236 extern void diag_set_int(char what, int arg);
237 extern int diag_get_int(char what);
238 extern const char *diag_get_string(char what);
239 extern int diag_reserve_fd(int fd);
240 extern int diag_fork(void);
241 extern int diag_dup(void);
242 extern int diag_dup2(int newfd);
243 extern void msg(int level, const char *format, ...);
244 extern void diag_flush(void);
245 extern void diag_exit(int status);
246 extern int diag_select(int nfds, fd_set *readfds, fd_set *writefds,
247 fd_set *exceptfds, struct timeval *timeout);
249 #endif /* !defined(__error_h_included) */