mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-02 01:45:17 +00:00
virfile: Use virProcessWait in virFileUnlink
Rather than inlining the code, use the common API.
This commit is contained in:
parent
89b9b6d35a
commit
b01c68d9bc
@ -2311,8 +2311,7 @@ virFileRemove(const char *path,
|
|||||||
gid_t gid)
|
gid_t gid)
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
|
||||||
@ -2352,32 +2351,21 @@ virFileRemove(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 unlinking '%s'"),
|
* been EACCES or EPERM by definition.
|
||||||
path);
|
*/
|
||||||
goto parenterror;
|
if (virLastErrorIsSystemErrno(0))
|
||||||
|
status = EINTR;
|
||||||
|
else if (!status)
|
||||||
|
status = EACCES;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if (status)
|
||||||
* If waitpid succeeded, but if the child exited abnormally or
|
ret = -status;
|
||||||
* reported non-zero status, report failure
|
|
||||||
*/
|
|
||||||
if (!WIFEXITED(status) || (WEXITSTATUS(status)) != 0) {
|
|
||||||
char *msg = virProcessTranslateStatus(status);
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("child failed to unlink '%s': %s"),
|
|
||||||
path, msg);
|
|
||||||
VIR_FREE(msg);
|
|
||||||
if (WIFEXITED(status))
|
|
||||||
ret = -WEXITSTATUS(status);
|
|
||||||
else
|
|
||||||
ret = -EACCES;
|
|
||||||
}
|
|
||||||
|
|
||||||
parenterror:
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user