]> xenbits.xensource.com Git - libvirt.git/commitdiff
virlog: Store the journald fd within the output object
authorErik Skultety <eskultet@redhat.com>
Wed, 17 Aug 2016 15:20:35 +0000 (17:20 +0200)
committerErik Skultety <eskultet@redhat.com>
Mon, 10 Oct 2016 06:27:24 +0000 (08:27 +0200)
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 <eskultet@redhat.com>
src/util/virlog.c

index b746fbdef9fec1f47d2ab0d1f09165f59b222046..85a21f08d799cd8b51a348746ebe9d9b03f1da5a 100644 (file)
@@ -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 */