]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virprocess: Return retval of the child on success, not 0
authorKristina Hanicova <khanicov@redhat.com>
Wed, 14 Jul 2021 14:46:53 +0000 (16:46 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 15 Jul 2021 10:00:21 +0000 (12:00 +0200)
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/util/virprocess.c

index 01d5d01d025b5bf7e5f7e58ee8be9ce950cdb2db..67dd599b3e60778192a2f11afc95ce6643000459 100644 (file)
@@ -1244,7 +1244,7 @@ static int virProcessNamespaceHelper(pid_t pid G_GNUC_UNUSED,
 /* Run cb(opaque) in the mount namespace of pid.  Return -1 with error
  * message raised if we fail to run the child, if the child dies from
  * a signal, or if the child has status EXIT_CANCELED; otherwise return
- * the exit status of the child. The callback will be run in a child
+ * value is the retval of the callback. The callback will be run in a child
  * process so must be careful to only use async signal safe functions.
  */
 int
@@ -1298,7 +1298,9 @@ virProcessRunInForkHelper(int errfd,
                           virProcessForkCallback cb,
                           void *opaque)
 {
-    if (cb(ppid, opaque) < 0) {
+    int ret = 0;
+
+    if ((ret = cb(ppid, opaque)) < 0) {
         virErrorPtr err = virGetLastError();
 
         if (err) {
@@ -1323,7 +1325,7 @@ virProcessRunInForkHelper(int errfd,
         return -1;
     }
 
-    return 0;
+    return ret;
 }
 
 
@@ -1344,7 +1346,7 @@ virProcessRunInForkHelper(int errfd,
  * On return, the returned value is either -1 with error message
  * reported if something went bad in the parent, if child has
  * died from a signal or if the child returned EXIT_CANCELED.
- * Otherwise the returned value is the exit status of the child.
+ * Otherwise the returned value is the retval of the callback.
  */
 int
 virProcessRunInFork(virProcessForkCallback cb,
@@ -1377,7 +1379,7 @@ virProcessRunInFork(virProcessForkCallback cb,
         ret = virProcessWait(child, &status, false);
         if (ret == 0) {
             ret = status == EXIT_CANCELED ? -1 : status;
-            if (ret) {
+            if (ret < 0) {
                 if (nread == sizeof(*bin)) {
                     bin = g_new0(errorDataBin, 1);
                     memcpy(bin->bindata, buf, sizeof(*bin));