From d25cf39d7cb4d2df2d7e2fa307c1c8f14bb018cc Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Mon, 6 Oct 2008 22:24:54 +0200 Subject: [PATCH] Improve logging again. Signed-off-by: Florent Bruneau --- common/common.c | 2 +- common/common.h | 16 ++++++++++++---- common/server.c | 4 ++++ postlicyd/main-postlicyd.c | 7 +++++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/common/common.c b/common/common.c index e9e4f2e..aa9e5ea 100644 --- a/common/common.c +++ b/common/common.c @@ -297,7 +297,7 @@ extern exitcall_t __madexit[]; static void common_shutdown(void) { - if (daemon_process) { + if (daemon_process && log_syslog) { info("stopping..."); } pidfile_close(); diff --git a/common/common.h b/common/common.h index 896eacc..0b0cd85 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__); \ } \ } @@ -124,7 +133,6 @@ static inline void common_startup(void) signal(SIGTERM, &common_sighandler); signal(SIGHUP, &common_sighandler); signal(SIGSEGV, &common_sighandler); - info("starting"); } diff --git a/common/server.c b/common/server.c index ea1df31..78af625 100644 --- a/common/server.c +++ b/common/server.c @@ -136,16 +136,19 @@ static int start_client(server_t *server, start_client_t starter, int server_loop(start_client_t starter, delete_client_t deleter, run_client_t runner, refresh_t refresh, void* config) { + info("entering processing loop"); while (!sigint) { struct epoll_event evts[1024]; int n; if (sighup && refresh) { sighup = false; + info("refreshing..."); if (!refresh(config)) { crit("error while refreshing configuration"); return EXIT_FAILURE; } + info("refresh done, processing loop restarts"); } n = epoll_select(evts, countof(evts), -1); @@ -183,5 +186,6 @@ int server_loop(start_client_t starter, delete_client_t deleter, } } } + info("exit requested"); return EXIT_SUCCESS; } diff --git a/postlicyd/main-postlicyd.c b/postlicyd/main-postlicyd.c index 9bdc391..751ff5a 100644 --- a/postlicyd/main-postlicyd.c +++ b/postlicyd/main-postlicyd.c @@ -45,6 +45,7 @@ #include "config.h" #define DAEMON_NAME "postlicyd" +#define DAEMON_VERSION "0.2" #define DEFAULT_PORT 10000 #define RUNAS_USER "nobody" #define RUNAS_GROUP "nogroup" @@ -199,11 +200,17 @@ int main(int argc, char *argv[]) } } + if (!daemonize) { + log_syslog = false; + } + if (argc - optind != 1) { usage(); return EXIT_FAILURE; } + info("starting %s v%s...", DAEMON_NAME, DAEMON_VERSION); + if (pidfile_open(pidfile) < 0) { crit("unable to write pidfile %s", pidfile); return EXIT_FAILURE; -- 2.20.1