You need to sign in or sign up before continuing.
提交 9ced219a 编写于 作者: J John Ferlan

virfile: Use virProcessWait in virDirCreate

Rather than inlining the code, use the common API.
上级 b01c68d9
...@@ -2448,8 +2448,7 @@ virDirCreate(const char *path, ...@@ -2448,8 +2448,7 @@ virDirCreate(const char *path,
{ {
struct stat st; struct stat st;
pid_t pid; pid_t pid;
int waitret; int status = 0, ret = 0;
int status, ret = 0;
gid_t *groups; gid_t *groups;
int ngroups; int ngroups;
...@@ -2495,36 +2494,30 @@ virDirCreate(const char *path, ...@@ -2495,36 +2494,30 @@ virDirCreate(const char *path,
/* wait for child to complete, and retrieve its exit code */ /* wait for child to complete, and retrieve its exit code */
VIR_FREE(groups); VIR_FREE(groups);
while ((waitret = waitpid(pid, &status, 0)) == -1 && errno == EINTR); if (virProcessWait(pid, &status, 0) < 0) {
if (waitret == -1) { /* virProcessWait() reports errno on waitpid failure, so we'll just
ret = -errno; * set our return status to EINTR; otherwise, set status to EACCES
virReportSystemError(errno, * since the original failure for the fork+setuid path would have
_("failed to wait for child creating '%s'"), * been EACCES or EPERM by definition.
path); */
goto parenterror; if (virLastErrorIsSystemErrno(0))
status = EINTR;
else if (!status)
status = EACCES;
} }
/* /*
* If waitpid succeeded, but if the child exited abnormally or * If the child exited with EACCES, then fall back to non-fork method
* reported non-zero status, report failure, except for EACCES where * as in the original logic introduced and explained by commit 98f6f381.
* 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 (status == EACCES) {
if (WEXITSTATUS(status) == EACCES) virResetLastError();
return virDirCreateNoFork(path, mode, uid, gid, flags); 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: if (status)
ret = -status;
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册