X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=common%2Fcommon.h;fp=common%2Fcommon.h;h=30ce1d8ca9a4a78665eaa9111861efcfa2399960;hb=bcdb5e34f3c251407304e01eea26607e77dd8609;hp=03d2fbb6cf20cba49da0fe8d77c78d129bc383c7;hpb=a66e19cd437595328f202cbde8d492d5f7e2205a;p=apps%2Fpfixtools.git diff --git a/common/common.h b/common/common.h index 03d2fbb..30ce1d8 100644 --- a/common/common.h +++ b/common/common.h @@ -72,7 +72,12 @@ typedef void (*exitcall_t)(void); #define __log(Level, Fmt, ...) \ if (log_level >= Level) { \ - syslog(Level, Fmt, ##__VA_ARGS__); \ + if (log_syslog) { \ + syslog(Level, Fmt, ##__VA_ARGS__); \ + } else { \ + fprintf(stderr, "[%d] " Fmt "\n", \ + Level, ##__VA_ARGS__); \ + } \ } #define debug(Fmt, ...) __log(LOG_DEBUG, Fmt, ##__VA_ARGS__) @@ -90,6 +95,7 @@ typedef void (*exitcall_t)(void); extern sig_atomic_t sigint; extern sig_atomic_t sighup; extern int log_level; +extern bool log_syslog; void common_sighandler(int sig); @@ -108,16 +114,23 @@ int pidfile_refresh(void); int common_setup(const char* pidfile, bool unsafe, const char* runas_user, const char* runas_group, bool daemonize); +static inline void common_startup(void) +{ + signal(SIGPIPE, SIG_IGN); + signal(SIGINT, &common_sighandler); + signal(SIGTERM, &common_sighandler); + signal(SIGHUP, &common_sighandler); + signal(SIGSEGV, &common_sighandler); + info("starting"); +} + + #define DECLARE_MAIN \ static int main_initialize(void) \ { \ + log_syslog = true; \ openlog(DAEMON_NAME, LOG_PID, LOG_MAIL); \ - signal(SIGPIPE, SIG_IGN); \ - signal(SIGINT, &common_sighandler); \ - signal(SIGTERM, &common_sighandler); \ - signal(SIGHUP, &common_sighandler); \ - signal(SIGSEGV, &common_sighandler); \ - info("starting..."); \ + common_startup(); \ return 0; \ } \ \