#include "mem.h"
-
#define __tostr(x) #x
#define STR(x) __tostr(x)
#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__); \
} \
}
signal(SIGTERM, &common_sighandler);
signal(SIGHUP, &common_sighandler);
signal(SIGSEGV, &common_sighandler);
- info("starting");
}
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);
}
}
}
+ info("exit requested");
return EXIT_SUCCESS;
}
#include "config.h"
#define DAEMON_NAME "postlicyd"
+#define DAEMON_VERSION "0.2"
#define DEFAULT_PORT 10000
#define RUNAS_USER "nobody"
#define RUNAS_GROUP "nogroup"
}
}
+ 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;