]> xenbits.xensource.com Git - libvirt.git/commitdiff
virlog: Take a special care of syslog when setting new set of log outputs
authorErik Skultety <eskultet@redhat.com>
Wed, 30 Mar 2016 10:38:39 +0000 (12:38 +0200)
committerErik Skultety <eskultet@redhat.com>
Mon, 10 Oct 2016 06:27:24 +0000 (08:27 +0200)
Now that we're in the critical section, syslog connection can be re-opened
by issuing openlog, which is something that cannot be done beforehand, since
syslog keeps its file descriptor private and changing the tag earlier might
introduce a log inconsistency if something went wrong with preparing a new set
of logging outputs in order to replace the existing one.

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

index 92ef794084b8ad9aeff638a9200775eba1e097de..9c98588f89daeb245c8f21a3598f4eb89fd5fb3d 100644 (file)
@@ -1794,16 +1794,37 @@ virLogFindOutput(virLogOutputPtr *outputs, size_t noutputs,
 int
 virLogDefineOutputs(virLogOutputPtr *outputs, size_t noutputs)
 {
+    int ret = -1;
+    int id;
+    char *tmp = NULL;
+
     if (virLogInitialize() < 0)
         return -1;
 
     virLogLock();
     virLogResetOutputs();
+
+    /* syslog needs to be special-cased, since it keeps the fd in private */
+    if ((id = virLogFindOutput(outputs, noutputs, VIR_LOG_TO_SYSLOG,
+                               current_ident)) != -1) {
+        /* nothing can go wrong now (except for malloc) and since we're also
+         * holding the lock so it's safe to call openlog and change the message
+         * tag
+         */
+        if (VIR_STRDUP_QUIET(tmp, outputs[id]->name) < 0)
+            goto cleanup;
+        VIR_FREE(current_ident);
+        current_ident = tmp;
+        openlog(current_ident, 0, 0);
+    }
+
     virLogOutputs = outputs;
     virLogNbOutputs = noutputs;
-    virLogUnlock();
 
-    return 0;
+    ret = 0;
+ cleanup:
+    virLogUnlock();
+    return ret;
 }