From af24f061e9342370aad6e045e71d46048521e488 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Tue, 13 Apr 2021 12:00:14 +0200 Subject: [PATCH] WIP syslog in seatd --- seatd/seatd.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/seatd/seatd.c b/seatd/seatd.c index 053d44b..b6c9781 100644 --- a/seatd/seatd.c +++ b/seatd/seatd.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -17,6 +18,17 @@ #define LISTEN_BACKLOG 16 +static const int verbosity_syslog_level[] = { + [LIBSEAT_LOG_LEVEL_SILENT] = LOG_DAEMON | LOG_DEBUG, + [LIBSEAT_LOG_LEVEL_ERROR] = LOG_DAEMON | LOG_ERR, + [LIBSEAT_LOG_LEVEL_INFO] = LOG_DAEMON | LOG_INFO, + [LIBSEAT_LOG_LEVEL_DEBUG] = LOG_DAEMON | LOG_DEBUG, +}; + +static void log_syslog(enum libseat_log_level level, const char *fmt, va_list args) { + syslog(verbosity_syslog_level[level], fmt, args); +} + static int open_socket(const char *path, int uid, int gid) { union { struct sockaddr_un unix; @@ -78,6 +90,7 @@ int main(int argc, char *argv[]) { " -u User to own the seatd socket\n" " -g Group to own the seatd socket\n" " -s Where to create the seatd socket\n" + " -z Log to syslog\n" " -v Show the version number\n" "\n"; @@ -85,7 +98,7 @@ int main(int argc, char *argv[]) { int uid = -1, gid = -1; int readiness = -1; const char *socket_path = getenv("SEATD_SOCK"); - while ((c = getopt(argc, argv, "vhn:s:g:u:")) != -1) { + while ((c = getopt(argc, argv, "vhzn:s:g:u:")) != -1) { switch (c) { case 'n': readiness = atoi(optarg); @@ -117,6 +130,9 @@ int main(int argc, char *argv[]) { } break; } + case 'z': + libseat_set_log_handler(log_syslog); + break; case 'v': printf("seatd version %s\n", SEATD_VERSION); return 0; -- 2.45.2