util: Avoid duplicating virFileOpenAsNoFork in virFileOpenAs

In 2f4d2496a88055a8343b3efca618522da8715d92 I didn't notice that one
part of virFileOpenAs doesn't actually call to virFileOpenAsNoFork but
rather includes a copy of the code from there.
This commit is contained in:
Jiri Denemark 2011-07-14 11:04:16 +08:00 committed by Daniel Veillard
parent ff98359d51
commit 3e75c5ec85

View File

@ -763,7 +763,6 @@ int
virFileOpenAs(const char *path, int openflags, mode_t mode, virFileOpenAs(const char *path, int openflags, mode_t mode,
uid_t uid, gid_t gid, unsigned int flags) uid_t uid, gid_t gid, unsigned int flags)
{ {
struct stat st;
pid_t pid; pid_t pid;
int waitret, status, ret = 0; int waitret, status, ret = 0;
int fd = -1; int fd = -1;
@ -830,6 +829,7 @@ virFileOpenAs(const char *path, int openflags, mode_t mode,
/* fall back to the simpler method, which works better in /* fall back to the simpler method, which works better in
* some cases */ * some cases */
VIR_FORCE_CLOSE(fd); VIR_FORCE_CLOSE(fd);
flags &= ~VIR_FILE_OPEN_AS_UID;
return virFileOpenAsNoFork(path, openflags, mode, uid, gid, flags); return virFileOpenAsNoFork(path, openflags, mode, uid, gid, flags);
} }
if (!ret) if (!ret)
@ -854,36 +854,11 @@ parenterror:
ret = -errno; ret = -errno;
goto childerror; goto childerror;
} }
if ((fd = open(path, openflags, mode)) < 0) {
ret = -errno; ret = virFileOpenAsNoFork(path, openflags, mode, uid, gid, flags);
if (ret != -EACCES) { if (ret < 0)
/* in case of EACCES, the parent will retry */
virReportSystemError(errno,
_("child failed to create file '%s'"),
path);
}
goto childerror; goto childerror;
} fd = ret;
if (fstat(fd, &st) == -1) {
ret = -errno;
virReportSystemError(errno, _("stat of '%s' failed"), path);
goto childerror;
}
if ((st.st_gid != gid)
&& (fchown(fd, -1, gid) < 0)) {
ret = -errno;
virReportSystemError(errno, _("cannot chown '%s' to (%u, %u)"),
path, (unsigned int) uid, (unsigned int) gid);
goto childerror;
}
if ((flags & VIR_FILE_OPEN_FORCE_PERMS)
&& (fchmod(fd, mode) < 0)) {
ret = -errno;
virReportSystemError(errno,
_("cannot set mode of '%s' to %04o"),
path, mode);
goto childerror;
}
do { do {
ret = sendfd(pair[1], fd); ret = sendfd(pair[1], fd);