]> xenbits.xensource.com Git - libvirt.git/commitdiff
virlog: Introduce virLogFindOutput
authorErik Skultety <eskultet@redhat.com>
Wed, 30 Mar 2016 10:22:15 +0000 (12:22 +0200)
committerErik Skultety <eskultet@redhat.com>
Mon, 10 Oct 2016 06:27:24 +0000 (08:27 +0200)
Outputs are a bit trickier than filters, since the user(config)-specified
set of outputs can contain duplicates. That would lead to logging the same
message twice. For compatibility reasons, we cannot just error out and forbid
the daemon to start if we find duplicate outputs which do not make sense.
Instead, we could silently take into account only the last occurrence of the
duplicate output and remove all the previous ones, so that the logger will not
try to use them when it is looping over all of its registered outputs.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
src/libvirt_private.syms
src/util/virlog.c
src/util/virlog.h

index da44c2f31e151d74eae5889d5a3466668994ae7c..ae22a51723d5c49a02a020dfbb174979ab011972 100644 (file)
@@ -1874,6 +1874,7 @@ virLogDefineOutput;
 virLogFilterFree;
 virLogFilterListFree;
 virLogFilterNew;
+virLogFindOutput;
 virLogGetDefaultPriority;
 virLogGetFilters;
 virLogGetNbFilters;
index 2957b8c1b62a2fb7c4e9aa2e9eaa44f8436c694d..df8b5bc22ae5ee6b8b7d8730979c2b590892224c 100644 (file)
@@ -1649,3 +1649,35 @@ virLogFilterNew(const char *match,
 
     return ret;
 }
+
+
+/**
+ * virLogFindOutput:
+ * @outputs: a list of outputs where to look for the output of type @dest
+ * @noutputs: number of elements in @outputs
+ * @dest: destination type of an output
+ * @opaque: opaque data to the method (only filename at the moment)
+ *
+ * Looks for an output of destination type @dest in the source list @outputs.
+ * If such an output exists, index of the object in the list is returned.
+ * In case of the destination being of type FILE also a comparison of the
+ * output's filename with @opaque is performed first.
+ *
+ * Returns the index of the object in the list or -1 if no object matching the
+ * specified @dest type and/or @opaque data one was found.
+ */
+int
+virLogFindOutput(virLogOutputPtr *outputs, size_t noutputs,
+                 virLogDestination dest, const void *opaque)
+{
+    size_t i;
+    const char *name = opaque;
+
+    for (i = 0; i < noutputs; i++) {
+        if (dest == outputs[i]->dest &&
+            (STREQ_NULLABLE(outputs[i]->name, name)))
+                return i;
+    }
+
+    return -1;
+}
index a33553328a2c9ddb640519d6ce5dda0cae11d1b2..4e557f8d3842081e934b7ab0d4084d5b7259db65 100644 (file)
@@ -235,5 +235,7 @@ virLogOutputPtr virLogOutputNew(virLogOutputFunc f,
 virLogFilterPtr virLogFilterNew(const char *match,
                                 virLogPriority priority,
                                 unsigned int flags) ATTRIBUTE_NONNULL(1);
+int virLogFindOutput(virLogOutputPtr *outputs, size_t noutputs,
+                     virLogDestination dest, const void *opaque);
 
 #endif