AUTHORS: Add Hisao Tanabe for his contribution
[netsniff-ng-new.git] / die.h
blob0ca9e86c56f0fcdee51ed8161919dfd49fc60d70
1 #ifndef DIE_H
2 #define DIE_H
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <stdarg.h>
7 #include <stdbool.h>
8 #include <string.h>
9 #include <errno.h>
10 #include <unistd.h>
11 #include <syslog.h>
13 #include "built_in.h"
15 extern void panic_handler_add(void (*on_panic)(void *arg), void *arg);
16 extern void call_panic_handlers(void);
18 static inline void panic(const char *format, ...) __check_format_printf(1, 2);
19 static inline void syslog_panic(const char *format,
20 ...) __check_format_printf(1, 2);
21 static inline void syslog_maybe(bool cond, int priority,
22 const char *format, ...) __check_format_printf(3, 4);
24 static inline void __noreturn __die_hard(void)
26 call_panic_handlers();
27 exit(EXIT_FAILURE);
30 static inline void __noreturn __die_harder(void)
32 call_panic_handlers();
33 _exit(EXIT_FAILURE);
36 static inline void __noreturn die(void)
38 __die_hard();
41 static inline void __noreturn _die(void)
43 __die_harder();
46 static inline void __noreturn panic(const char *format, ...)
48 va_list vl;
50 va_start(vl, format);
51 vfprintf(stderr, format, vl);
52 va_end(vl);
54 die();
57 static inline void __noreturn syslog_panic(const char *format, ...)
59 va_list vl;
61 va_start(vl, format);
62 vsyslog(LOG_ERR, format, vl);
63 va_end(vl);
65 die();
68 static inline void syslog_maybe(bool cond, int priority,
69 const char *format, ...)
71 if (cond) {
72 va_list vl;
74 va_start(vl, format);
75 vsyslog(priority, format, vl);
76 va_end(vl);
80 #endif /* DIE_H */