#include "common.h"
-bool daemon_process = true;
-int log_level = LOG_INFO;
-bool log_syslog = false;
+bool daemon_process = true;
+int log_level = LOG_INFO;
+bool log_syslog = false;
+const char *log_state = "";
static FILE *pidfile = NULL;
static void common_shutdown(void)
{
+ log_state = "stopping ";
if (daemon_process && log_syslog) {
- info("stopping...");
+ info("");
}
pidfile_close();
for (int i = array_len(__exit) - 1 ; i >= 0 ; --i) {
if (__ran) {
return;
}
+ log_state = "starting ";
if (atexit(common_shutdown)) {
fputs("Cannot hook my atexit function, quitting !\n", stderr);
abort();
: (L) == LOG_ALERT ? "alert " \
: "??? " )
-#define __log(Level, Fmt, ...) \
- if (log_level >= Level) { \
- if (log_syslog) { \
- syslog(Level, Fmt, ##__VA_ARGS__); \
- } else { \
- fprintf(stderr, "[%s] " Fmt "\n", \
- __level_name(Level), ##__VA_ARGS__); \
- } \
+#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__)
extern int log_level;
extern bool log_syslog;
+extern const char *log_state;
void common_sighandler(int sig);
*context->result = RBL_FOUND;
}
if (context->call != NULL) {
- debug("calling callback");
context->call(context->result, context->data);
- } else {
- debug("no callback defined");
}
ub_resolve_free(result);
rbl_context_release(context);
{
client_t *server = (client_t*)w;
- debug("Entering client_cb for %p, %d (%d | %d)", w, events, EV_WRITE, EV_READ);
-
if (events & EV_WRITE && server->obuf.len) {
if (buffer_write(&server->obuf, server->io.fd) < 0) {
client_release(server);
static void refresh_cb(EV_P_ struct ev_signal *w, int event)
{
+ log_state = "refreshing ";
if (!gl_config_refresh(gl_config)) {
ev_unloop(EV_A_ EVUNLOOP_ALL);
+ info("failed");
+ } else {
+ info("done");
}
+ log_state = "";
}
static void exit_cb(EV_P_ struct ev_signal *w, int event)
ev_signal_init(&ev_sigterm, exit_cb, SIGTERM);
ev_signal_start(gl_loop, &ev_sigterm);
+ log_state = "";
info("entering processing loop");
ev_loop(gl_loop, 0);
info("exit requested");
return EXIT_FAILURE;
}
- info("starting %s v%s...", DAEMON_NAME, DAEMON_VERSION);
+ info("%s v%s...", DAEMON_NAME, DAEMON_VERSION);
config.domain = argv[optind];
config.srs = srs_read_secrets(argv[optind + 1]);
return EXIT_FAILURE;
}
- info("starting %s v%s...", DAEMON_NAME, DAEMON_VERSION);
+ info("%s v%s...", DAEMON_NAME, DAEMON_VERSION);
if (pidfile_open(pidfile) < 0) {
crit("unable to write pidfile %s", pidfile);