diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c16983..dcc89c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,7 @@ add_library(webfused-static STATIC src/webfused/auth/file_authenticator.c src/webfused/log/logger.c src/webfused/log/stderr_logger.c + src/webfused/log/syslog_logger.c ) add_executable(webfused diff --git a/src/webfused/daemon.c b/src/webfused/daemon.c index c0b6de5..457b1fe 100644 --- a/src/webfused/daemon.c +++ b/src/webfused/daemon.c @@ -13,8 +13,9 @@ #include #include "webfused/config/config.h" #include "webfused/config/factory.h" -#include "webfused/log/stderr_logger.h" #include "webfused/log/log.h" +#include "webfused/log/logger.h" +#include "webfused/log/stderr_logger.h" #define WFD_SERVICE_TIMEOUT (1 * 1000) #define WFD_DEFAULT_CONFIG_FILE ("/etc/webfuse.conf") @@ -141,6 +142,7 @@ int wfd_daemon_run(int argc, char * argv[]) show_help(); } + wfd_logger_close(); free(args.config_file); return result; } diff --git a/src/webfused/log/syslog_logger.c b/src/webfused/log/syslog_logger.c new file mode 100644 index 0000000..02bca99 --- /dev/null +++ b/src/webfused/log/syslog_logger.c @@ -0,0 +1,56 @@ +#include "webfused/log/syslog_logger.h" +#include "webfused/log/logger.h" +#include "webfused/log/log.h" + +#include +#include + +static int +wfd_syslog_logger_to_priority( + int level) +{ + switch (level) + { + case WFD_LOGLEVEL_FATAL: return LOG_CRIT; + case WFD_LOGLEVEL_ERROR: return LOG_ERR; + case WFD_LOGLEVEL_WARN: return LOG_WARNING; + case WFD_LOGLEVEL_INFO: return LOG_INFO; + case WFD_LOGLEVEL_DEBUG: return LOG_DEBUG; + default: return LOG_NOTICE; + } +} + +static void +wfd_syslog_logger_log( + void * user_data, + int level, + char const * format, + va_list args) +{ + (void) user_data; + + int prio = wfd_syslog_logger_to_priority(level); + vsyslog(prio, format, args); +} + +static void +wfd_syslog_logger_close( + void * user_data) +{ + closelog(); +} + +void +wfd_syslog_logger_init( + int level, + char const * ident, + int options, + int facility) +{ + wfd_logger_init(level, + &wfd_syslog_logger_log, + &wfd_syslog_logger_close, + NULL); + + openlog(ident, options, facility); +} \ No newline at end of file diff --git a/src/webfused/log/syslog_logger.h b/src/webfused/log/syslog_logger.h new file mode 100644 index 0000000..1466d1d --- /dev/null +++ b/src/webfused/log/syslog_logger.h @@ -0,0 +1,20 @@ +#ifndef WFD_LOG_SYSLOG_LOGGER_H +#define WFD_LOG_SYSLOG_LOGGER_H + +#ifdef __cplusplus +extern "C" + { +#endif + +extern void +wfd_syslog_logger_init( + int level, + char const * ident, + int options, + int facility); + +#ifdef __cplusplus + } +#endif + +#endif