]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virt-login-shell: avoid loosing error during cleanup
authorDaniel P. Berrange <berrange@redhat.com>
Tue, 12 Apr 2016 15:48:19 +0000 (16:48 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Fri, 10 Jun 2016 10:03:02 +0000 (11:03 +0100)
The virDomainFree / virConnectClose methods will reset the
last error handle, so we must save the error during cleanup

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
tools/virt-login-shell.c

index 527395a5d0335a1ff992bd996ad3f091b3fed1b8..59ec801501150ea68c32d8b70de028c34950a255 100644 (file)
@@ -220,6 +220,7 @@ main(int argc, char **argv)
     size_t i;
     const char *cmdstr = NULL;
     char *tmp;
+    virErrorPtr saved_err = NULL;
 
     struct option opt[] = {
         {"help", no_argument, NULL, 'h'},
@@ -390,6 +391,8 @@ main(int argc, char **argv)
     /* At this point, the parent is now waiting for the child to exit,
      * but as that may take a long time, we release resources now.  */
  cleanup:
+    saved_err = virSaveLastError();
+
     if (nfdlist > 0)
         for (i = 0; i < nfdlist; i++)
             VIR_FORCE_CLOSE(fdlist[i]);
@@ -410,7 +413,9 @@ main(int argc, char **argv)
     if (virProcessWait(cpid, &status, true) == 0)
         virProcessExitWithStatus(status);
 
-    if (virGetLastError())
+    if (saved_err) {
+        virSetError(saved_err);
         virDispatchError(NULL);
+    }
     return ret;
 }