Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
bool daemon_process = true;
int log_level = LOG_INFO;
bool daemon_process = true;
int log_level = LOG_INFO;
+bool log_syslog = false;
static FILE *pidfile = NULL;
static FILE *pidfile = NULL;
#define __log(Level, Fmt, ...) \
if (log_level >= Level) { \
#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__)
}
#define debug(Fmt, ...) __log(LOG_DEBUG, Fmt, ##__VA_ARGS__)
extern sig_atomic_t sigint;
extern sig_atomic_t sighup;
extern int log_level;
extern sig_atomic_t sigint;
extern sig_atomic_t sighup;
extern int log_level;
void common_sighandler(int sig);
void common_sighandler(int sig);
int common_setup(const char* pidfile, bool unsafe, const char* runas_user,
const char* runas_group, bool daemonize);
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) \
{ \
#define DECLARE_MAIN \
static int main_initialize(void) \
{ \
openlog(DAEMON_NAME, LOG_PID, LOG_MAIL); \
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..."); \
#include "file.h"
#include <dirent.h>
#include "file.h"
#include <dirent.h>
-#define DAEMON_NAME "tst-filters"
-
-DECLARE_MAIN
-
static char *read_query(const char *basepath, const char *filename,
char *buff, char **end, query_t *q)
{
static char *read_query(const char *basepath, const char *filename,
char *buff, char **end, query_t *q)
{
char path[FILENAME_MAX];
char *p;
char path[FILENAME_MAX];
char *p;
p = strrchr(argv[0], '/');
if (p == NULL) {
p = argv[0];
p = strrchr(argv[0], '/');
if (p == NULL) {
p = argv[0];