misc: add minicom default config
[ana-net.git] / app / die.h
blobe7e7b8e7065b9369d21a764084191eeed340853b
1 /*
2 * Lightweight Autonomic Network Architecture
3 * Copyright 2011 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,
4 * Swiss federal institute of technology (ETH Zurich)
5 * Subject to the GPL.
6 */
8 #ifndef DIE_H
9 #define DIE_H
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <stdarg.h>
14 #include <string.h>
15 #include <errno.h>
16 #include <syslog.h>
18 #include "compiler.h"
20 static inline void error_and_die(int status, char *msg, ...)
22 va_list vl;
23 va_start(vl, msg);
24 vfprintf(stderr, msg, vl);
25 va_end(vl);
26 exit(status);
29 static inline void die(void)
31 exit(EXIT_FAILURE);
34 static inline void panic(char *msg, ...)
36 va_list vl;
37 va_start(vl, msg);
38 vfprintf(stderr, msg, vl);
39 va_end(vl);
40 die();
43 #define syslog_panic(msg...) \
44 do { \
45 syslog(LOG_ERR, ##msg); \
46 die(); \
47 } while (0)
49 static inline void whine(char *msg, ...)
51 va_list vl;
52 va_start(vl, msg);
53 vfprintf(stderr, msg, vl);
54 va_end(vl);
57 #define syslog_whine(msg...) \
58 do { \
59 syslog(LOG_WARNING, ##msg); \
60 } while (0)
62 static inline void info(char *msg, ...)
64 va_list vl;
65 va_start(vl, msg);
66 vfprintf(stdout, msg, vl);
67 va_end(vl);
70 #define syslog_info(msg...) \
71 do { \
72 syslog(LOG_INFO, ##msg); \
73 } while (0)
75 static inline void BUG(char *msg, ...)
77 va_list vl;
78 whine("BUG: ");
79 va_start(vl, msg);
80 vfprintf(stderr, msg, vl);
81 va_end(vl);
82 die();
85 static inline void BUG_ON(int cond, char *msg, ...)
87 va_list vl;
88 if (unlikely(cond)) {
89 whine("BUG: ");
90 va_start(vl, msg);
91 vfprintf(stderr, msg, vl);
92 va_end(vl);
93 die();
97 #ifdef _DEBUG_
98 static inline void debug(char *msg, ...)
100 va_list vl;
101 va_start(vl, msg);
102 vfprintf(stderr, msg, vl);
103 va_end(vl);
104 fflush(stderr);
106 #else
107 static inline void debug(char *msg, ...)
109 /* NOP */
111 #endif /* _DEBUG_ */
112 #endif /* DIE_H */