X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=common%2Fcommon.h;h=22299b7150e1bd22ae48ea800238ad86e8112862;hb=e327d3786ba0371eaaff8e6ba0fe3fc39f095ae2;hp=896eaccb1f70c979a745d88384e51669ec79bcd2;hpb=92dc834e982d4b71ce6a3fcc2c973e555afd3fcf;p=apps%2Fpfixtools.git diff --git a/common/common.h b/common/common.h index 896eacc..22299b7 100644 --- a/common/common.h +++ b/common/common.h @@ -57,7 +57,6 @@ #include "mem.h" - #define __tostr(x) #x #define STR(x) __tostr(x) @@ -73,13 +72,23 @@ typedef void (*exitcall_t)(void); #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, Fmt, ##__VA_ARGS__); \ } else { \ - fprintf(stderr, "[%d] " Fmt "\n", \ - Level, ##__VA_ARGS__); \ + fprintf(stderr, "[%s] " Fmt "\n", \ + __level_name(Level), ##__VA_ARGS__); \ } \ } @@ -102,6 +111,7 @@ extern bool log_syslog; void common_sighandler(int sig); +int setnonblock(int sock); int tcp_bind(const struct sockaddr *addr, socklen_t len); int tcp_listen(const struct sockaddr *addr, socklen_t len); int tcp_listen_nonblock(const struct sockaddr *addr, socklen_t len); @@ -124,7 +134,6 @@ static inline void common_startup(void) signal(SIGTERM, &common_sighandler); signal(SIGHUP, &common_sighandler); signal(SIGSEGV, &common_sighandler); - info("starting"); }