]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: virfile: Fix 'unknown cause' error if NFS mount point creation fails
authorErik Skultety <eskultet@redhat.com>
Thu, 11 Jun 2015 08:51:23 +0000 (10:51 +0200)
committerErik Skultety <eskultet@redhat.com>
Tue, 16 Jun 2015 14:26:20 +0000 (16:26 +0200)
This happens if user requires creation of a directory with specified
UID/GID permissions. To accomplish this, we use fork approach and
set particular UID/GID permissions in child process. However, child
process doesn't have a valid descriptor to a logfile (this is prohibited
explicitly) and since parent process doesn't handle negative exit codes from
child in any way, 'uknown cause' error is returned to the user.

Commit 92d9114e tweaked the way we handle child errors when using fork
approach to set specific permissions (features originally introduced
by 98f6f381). The same logic should be used to create directories with
specified permissions as well.

https://bugzilla.redhat.com/show_bug.cgi?id=1230137

src/util/virfile.c

index 4b64225b534fa7879c7a452a67cd0b818eae25cd..91e460f9b1985c2c8aad002b926b7bc16be25fad 100644 (file)
@@ -2384,11 +2384,27 @@ virDirCreate(const char *path,
                                  path);
             goto parenterror;
         }
-        if (!WIFEXITED(status) || (ret = -WEXITSTATUS(status)) == -EACCES) {
-            /* fall back to the simpler method, which works better in
-             * some cases */
-            return virDirCreateNoFork(path, mode, uid, gid, flags);
+
+        /*
+         * If waitpid succeeded, but if the child exited abnormally or
+         * reported non-zero status, report failure, except for EACCES where
+         * we try to fall back to non-fork method as in the original logic
+         * introduced and explained by commit 98f6f381.
+         */
+        if (!WIFEXITED(status) || (WEXITSTATUS(status)) != 0) {
+            if (WEXITSTATUS(status) == EACCES)
+                return virDirCreateNoFork(path, mode, uid, gid, flags);
+            char *msg = virProcessTranslateStatus(status);
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("child failed to create '%s': %s"),
+                           path, msg);
+            VIR_FREE(msg);
+            if (WIFEXITED(status))
+                ret = -WEXITSTATUS(status);
+            else
+                ret = -EACCES;
         }
+
  parenterror:
         return ret;
     }