Previous patch of this series proposed a fix to virDirCreate, so that parent
process reports an error if child process failed its task.
However our logic still permits the child to exit with negative errno followed
by a check of the status on the parent side using WEXITSTATUS which, being
POSIX compliant, takes the lower 8 bits of the exit code and returns is to
the caller. However, by taking 8 bits from a negative exit code
(two's complement) the status value we read and append to stream is
'2^8 - abs(original exit code)' which doesn't quite reflect the real cause
when
compared to the meaning of errno values.
---
src/util/virfile.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/src/util/virfile.c b/src/util/virfile.c
index 5e678fe..91e460f 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -2413,12 +2413,12 @@ virDirCreate(const char *path,
/* set desired uid/gid, then attempt to create the directory */
if (virSetUIDGID(uid, gid, groups, ngroups) < 0) {
- ret = -errno;
+ ret = errno;
goto childerror;
}
if (mkdir(path, mode) < 0) {
- ret = -errno;
- if (ret != -EACCES) {
+ ret = errno;
+ if (ret != EACCES) {
/* in case of EACCES, the parent will retry */
virReportSystemError(errno, _("child failed to create directory
'%s'"),
path);
@@ -2428,13 +2428,13 @@ virDirCreate(const char *path,
/* check if group was set properly by creating after
* setgid. If not, try doing it with chown */
if (stat(path, &st) == -1) {
- ret = -errno;
+ ret = errno;
virReportSystemError(errno,
_("stat of '%s' failed"), path);
goto childerror;
}
if ((st.st_gid != gid) && (chown(path, (uid_t) -1, gid) < 0)) {
- ret = -errno;
+ ret = errno;
virReportSystemError(errno,
_("cannot chown '%s' to group %u"),
path, (unsigned int) gid);
@@ -2447,6 +2447,10 @@ virDirCreate(const char *path,
goto childerror;
}
childerror:
+ if ((ret & 0xff) != ret) {
+ VIR_WARN("unable to pass desired return value %d", ret);
+ ret = 0xff;
+ }
_exit(ret);
}
--
1.9.3