diff --git a/utils.c b/utils.c index c7022ce9..2094106c 100644 --- a/utils.c +++ b/utils.c @@ -1,25 +1,25 @@ #include "config.h" #include #include #include "utils.h" int utils_debug = 0; -int utils_syslog = 0; +int utils_syslog = 1; int knet_fdset_cloexec(int fd) { int fdflags; fdflags = fcntl(fd, F_GETFD, 0); if (fdflags < 0) return -1; fdflags |= FD_CLOEXEC; if (fcntl(fd, F_SETFD, fdflags) < 0) return -1; return 0; } diff --git a/utils.h b/utils.h index 0c71eaa7..20963cb4 100644 --- a/utils.h +++ b/utils.h @@ -1,47 +1,49 @@ #ifndef __UTILS_H__ #define __UTILS_H__ #include #include #include #include extern int utils_debug; extern int utils_syslog; #ifndef TEST #define STATIC static #else #define STATIC #endif #define log_debug(fmt, args...) \ -if (utils_debug) { \ - printf("DEBUG(%s:%i|%s): " fmt "\n", \ - __FILE__, __LINE__, __FUNCTION__, ##args); \ -} +do { \ + if (utils_debug) { \ + printf("DEBUG(%s:%i|%s): " fmt "\n", __FILE__, __LINE__, __FUNCTION__, ##args); \ + if (utils_syslog) syslog(LOG_DEBUG, "DEBUG(%s:%i|%s): " fmt, __FILE__, __LINE__, __FUNCTION__, ##args); \ + } \ +} while (0); #define log_info(fmt, args...) \ do { \ fprintf(stderr, "Notice: " fmt "\n", ##args); \ if (utils_syslog) syslog(LOG_INFO, fmt, ##args); \ } while (0); #define log_error(fmt, args...) \ do { \ fprintf(stderr, "Error: " fmt " (%s)\n", ##args, strerror(errno)); \ if (utils_syslog) syslog(LOG_ERR, fmt, ##args); \ } while (0); #define timespec_diff(start, end, diff) \ do { \ if (end.tv_sec > start.tv_sec) \ *(diff) = ((end.tv_sec - start.tv_sec) * 1000000000llu) \ + end.tv_nsec - start.tv_nsec; \ else \ *(diff) = end.tv_nsec - start.tv_nsec; \ } while (0); int knet_fdset_cloexec(int fd); #endif