You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

249 lines
11 KiB

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