+void common_register_exit(exitcall_t exitcall);
+void common_init(void);
+
+#define module_init(fn) \
+ __attribute__((constructor,used)) \
+ static void __init_wrapper__ ## fn (void) { \
+ common_init(); \
+ if (fn() != 0) { \
+ exit(-1); \
+ } \
+ }
+#define module_exit(fn) \
+ __attribute__((constructor,used)) \
+ static void __exit_wrapper ## fn(void) { \
+ common_init(); \
+ common_register_exit(fn); \
+ }
+
+#define likely(expr) __builtin_expect((expr) != 0, 1)
+#define unlikely(expr) __builtin_expect((expr) != 0, 0)
+
+#define __level_name(L) \
+ ( (L) == LOG_DEBUG ? "debug " \
+ : (L) == LOG_NOTICE ? "notice" \
+ : (L) == LOG_INFO ? "info " \
+ : (L) == LOG_WARNING ? "warn " \
+ : (L) == LOG_ERR ? "error " \
+ : (L) == LOG_CRIT ? "crit " \
+ : (L) == LOG_ALERT ? "alert " \
+ : "??? " )
+
+#define __log(Level, Fmt, ...) \
+ if (log_level >= Level) { \
+ if (log_syslog) { \
+ syslog(Level, "%s" Fmt, log_state, ##__VA_ARGS__); \
+ } else { \
+ fprintf(stderr, "[%s] %s" Fmt "\n", \
+ __level_name(Level), log_state, ##__VA_ARGS__);\
+ } \
+ }
+
+#define debug(Fmt, ...) __log(LOG_DEBUG, Fmt, ##__VA_ARGS__)
+#define notice(Fmt, ...) __log(LOG_NOTICE, Fmt, ##__VA_ARGS__)
+#define info(Fmt, ...) __log(LOG_INFO, Fmt, ##__VA_ARGS__)
+#define warn(Fmt, ...) __log(LOG_WARNING, Fmt, ##__VA_ARGS__)
+#define err(Fmt, ...) __log(LOG_ERR, Fmt, ##__VA_ARGS__)
+#define crit(Fmt, ...) __log(LOG_CRIT, Fmt, ##__VA_ARGS__)
+#define alert(Fmt, ...) __log(LOG_ALERT, Fmt, ##__VA_ARGS__)
+#define emerg(Fmt, ...) __log(LOG_ALERT, Fmt, ##__VA_ARGS__)
+
+#define UNIXERR(fun) err("%s:%d:%s %s: %m", \
+ __FILE__, __LINE__, __func__, fun)
+
+extern int log_level;
+extern bool log_syslog;
+extern const char *log_state;