From 8a8f49a501fd109bcb722afff7eb2c7852a04107 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 17 Jun 2018 16:27:10 +0200 Subject: [PATCH] usyslogd: do logfile lookup by facility number Signed-off-by: David Oberhollenzer --- syslogd/logfile.c | 3 ++- syslogd/logfile.h | 3 ++- syslogd/main.c | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/syslogd/logfile.c b/syslogd/logfile.c index a59f7e7..5687750 100644 --- a/syslogd/logfile.c +++ b/syslogd/logfile.c @@ -25,7 +25,7 @@ #include "logfile.h" -logfile_t *logfile_create(const char *name) +logfile_t *logfile_create(const char *name, int facility) { logfile_t *file; @@ -36,6 +36,7 @@ logfile_t *logfile_create(const char *name) } strcpy(file->name, name); + file->facility = facility; file->fd = open(file->name, O_WRONLY | O_CREAT, 0640); if (file->fd < 0) diff --git a/syslogd/logfile.h b/syslogd/logfile.h index 58da272..cf4a7d6 100644 --- a/syslogd/logfile.h +++ b/syslogd/logfile.h @@ -20,12 +20,13 @@ typedef struct logfile_t { struct logfile_t *next; + int facility; int fd; char name[]; } logfile_t; -logfile_t *logfile_create(const char *name); +logfile_t *logfile_create(const char *name, int facility); void logfile_destroy(logfile_t *file); diff --git a/syslogd/main.c b/syslogd/main.c index b1b70b0..79d6325 100644 --- a/syslogd/main.c +++ b/syslogd/main.c @@ -134,12 +134,12 @@ static int print_to_log(const syslog_msg_t *msg) return -1; for (log = logfiles; log != NULL; log = log->next) { - if (!strcmp(log->name, fac_name)) + if (log->facility == msg->facility) break; } if (log == NULL) { - log = logfile_create(fac_name); + log = logfile_create(fac_name, msg->facility); if (log == NULL) return -1; log->next = logfiles;