From a2405a889e9e76e757ce097d6262431338acad7c Mon Sep 17 00:00:00 2001 From: Erik Skultety Date: Wed, 17 Aug 2016 17:20:35 +0200 Subject: [PATCH] virlog: Store the journald fd within the output object There is really no reason why we could not keep journald's fd within the journald output object the same way as we do for regular file-based outputs. By doing this we later won't have to special case the journald-based output (due to the fd being globally shared) when replacing the existing set of outputs with a new one. Additionally, by making this change, we don't need the virLogCloseJournald routine anymore, plain virLogCloseFd will suffice. Signed-off-by: Erik Skultety --- src/util/virlog.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/util/virlog.c b/src/util/virlog.c index b746fbdef9..85a21f08d7 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -962,8 +962,6 @@ journalAddInt(struct journalState *state, const char *field, int value) state->iov += 4; } -static int journalfd = -1; - static void virLogOutputToJournald(virLogSourcePtr source, virLogPriority priority, @@ -975,10 +973,11 @@ virLogOutputToJournald(virLogSourcePtr source, unsigned int flags, const char *rawstr, const char *str ATTRIBUTE_UNUSED, - void *data ATTRIBUTE_UNUSED) + void *data) { virCheckFlags(VIR_LOG_STACK_TRACE,); int buffd = -1; + int journalfd = (intptr_t) data; struct msghdr mh; struct sockaddr_un sa; union { @@ -1084,24 +1083,23 @@ virLogOutputToJournald(virLogSourcePtr source, } -static void virLogCloseJournald(void *data ATTRIBUTE_UNUSED) -{ - VIR_LOG_CLOSE(journalfd); -} - - static int virLogAddOutputToJournald(int priority) { + int journalfd; + if ((journalfd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) return -1; if (virSetInherit(journalfd, false) < 0) { VIR_LOG_CLOSE(journalfd); return -1; } - if (virLogDefineOutput(virLogOutputToJournald, virLogCloseJournald, NULL, - priority, VIR_LOG_TO_JOURNALD, NULL, 0) < 0) { + if (virLogDefineOutput(virLogOutputToJournald, virLogCloseFd, + (void *)(intptr_t) journalfd, priority, + VIR_LOG_TO_JOURNALD, NULL, 0) < 0) { + VIR_LOG_CLOSE(journalfd); return -1; } + return 0; } # endif /* USE_JOURNALD */ -- GitLab