[PATCH v2 19/20] virlog: Store the journald fd within the output object

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Now that previous patches tried to refactor the code and split parsing and
defining logic of logging primitives, there is 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. Quite the opposite, by doing that we gain the
benefit of creating a journald-based object the same way as we create
file-based ones and therefore when replacing the existing set of outputs
for a new one, journald does not need to be special cased due to its globally
shared fd and the only remaining thing to special case is syslog. Additionally,
making this change, we don't need the virLogCloseJournald routinei anymore,
since as it stores the fd within the object, plain virLogCloseFd will suffice.

Signed-off-by: Erik Skultety <eskultet@xxxxxxxxxx>
---
 src/util/virlog.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/src/util/virlog.c b/src/util/virlog.c
index 34209d0..713cd0c 100644
--- a/src/util/virlog.c
+++ b/src/util/virlog.c
@@ -852,8 +852,6 @@ journalAddInt(struct journalState *state, const char *field, int value)
     state->iov += 4;
 }
 
-static int journalfd = -1;
-
 static void
 virLogOutputToJournald(virLogSourcePtr source,
                        virLogPriority priority,
@@ -865,10 +863,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 {
@@ -974,15 +973,10 @@ virLogOutputToJournald(virLogSourcePtr source,
 }
 
 
-static void virLogCloseJournald(void *data ATTRIBUTE_UNUSED)
-{
-    VIR_LOG_CLOSE(journalfd);
-}
-
-
 static virLogOutputPtr
 virLogNewOutputToJournald(int priority)
 {
+    int journalfd;
     virLogOutputPtr ret = NULL;
 
     if ((journalfd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0)
@@ -993,9 +987,9 @@ virLogNewOutputToJournald(int priority)
         return NULL;
     }
 
-    if (!(ret = virLogOutputNew(virLogOutputToJournald,
-                                virLogCloseJournald, NULL,
-                                priority, VIR_LOG_TO_JOURNALD, NULL))) {
+    if (!(ret = virLogOutputNew(virLogOutputToJournald, virLogCloseFd,
+                                (void *)(intptr_t) journalfd, priority,
+                                VIR_LOG_TO_JOURNALD, NULL))) {
         VIR_LOG_CLOSE(journalfd);
         return NULL;
     }
-- 
2.5.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]