Revert
6a1f5f568f8. Now that libvirt_iohelper takes fds by
inheritance rather than by open() (commit
1eb66479), there is
no longer a race where the parent can unlink() a file prior to
the iohelper open()ing the same file. From there, it makes
more sense to have the callers both create and unlink, rather
than the caller create and the stream unlink, since the latter
was only needed when iohelper had to do the unlink.
* src/fdstream.h (virFDStreamOpenFile, virFDStreamCreateFile):
Callers are responsible for deletion.
* src/fdstream.c (virFDStreamOpenFileInternal): Don't leak created
file on failure.
(virFDStreamOpenFile, virFDStreamCreateFile): Drop parameter.
* src/lxc/lxc_driver.c (lxcDomainOpenConsole): Update callers.
* src/qemu/qemu_driver.c (qemuDomainScreenshot)
(qemuDomainOpenConsole): Likewise.
* src/storage/storage_driver.c (storageVolumeDownload)
(storageVolumeUpload): Likewise.
* src/uml/uml_driver.c (umlDomainOpenConsole): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainScreenshot): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainOpenConsole): Likewise.
unsigned long long offset,
unsigned long long length,
int oflags,
- int mode,
- bool delete)
+ int mode)
{
int fd = -1;
int fds[2] = { -1, -1 };
virCommandPtr cmd = NULL;
int errfd = -1;
- VIR_DEBUG("st=%p path=%s oflags=%x offset=%llu length=%llu mode=%o delete=%d",
- st, path, oflags, offset, length, mode, delete);
+ VIR_DEBUG("st=%p path=%s oflags=%x offset=%llu length=%llu mode=%o",
+ st, path, oflags, offset, length, mode);
if (oflags & O_CREAT)
fd = open(path, oflags, mode);
if (virFDStreamOpenInternal(st, fd, cmd, errfd, length) < 0)
goto error;
- if (delete)
- unlink(path);
-
return 0;
error:
VIR_FORCE_CLOSE(fds[0]);
VIR_FORCE_CLOSE(fds[1]);
VIR_FORCE_CLOSE(fd);
+ if (oflags & O_CREAT)
+ unlink(path);
return -1;
}
const char *path,
unsigned long long offset,
unsigned long long length,
- int oflags,
- bool delete)
+ int oflags)
{
if (oflags & O_CREAT) {
streamsReportError(VIR_ERR_INTERNAL_ERROR,
}
return virFDStreamOpenFileInternal(st, path,
offset, length,
- oflags, 0, delete);
+ oflags, 0);
}
int virFDStreamCreateFile(virStreamPtr st,
unsigned long long offset,
unsigned long long length,
int oflags,
- mode_t mode,
- bool delete)
+ mode_t mode)
{
return virFDStreamOpenFileInternal(st, path,
offset, length,
- oflags | O_CREAT,
- mode, delete);
+ oflags | O_CREAT, mode);
}
const char *path,
unsigned long long offset,
unsigned long long length,
- int oflags,
- bool delete);
+ int oflags);
int virFDStreamCreateFile(virStreamPtr st,
const char *path,
unsigned long long offset,
unsigned long long length,
int oflags,
- mode_t mode,
- bool delete);
+ mode_t mode);
#endif /* __VIR_FDSTREAM_H_ */
}
if (virFDStreamOpenFile(st, chr->source.data.file.path,
- 0, 0, O_RDWR, false) < 0)
+ 0, 0, O_RDWR) < 0)
goto cleanup;
ret = 0;
char *tmp = NULL;
int tmp_fd = -1;
char *ret = NULL;
+ bool unlink_tmp = false;
virCheckFlags(0, NULL);
virReportSystemError(errno, _("mkstemp(\"%s\") failed"), tmp);
goto endjob;
}
+ unlink_tmp = true;
virSecurityManagerSetSavedStateLabel(qemu_driver->securityManager, vm, tmp);
qemuDomainObjEnterMonitor(driver, vm);
if (qemuMonitorScreendump(priv->mon, tmp) < 0) {
qemuDomainObjExitMonitor(driver, vm);
- unlink(tmp);
goto endjob;
}
qemuDomainObjExitMonitor(driver, vm);
if (VIR_CLOSE(tmp_fd) < 0) {
virReportSystemError(errno, _("unable to close %s"), tmp);
- unlink(tmp);
goto endjob;
}
- if (virFDStreamOpenFile(st, tmp, 0, 0, O_RDONLY, true) < 0) {
+ if (virFDStreamOpenFile(st, tmp, 0, 0, O_RDONLY) < 0) {
qemuReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("unable to open stream"));
- unlink(tmp);
goto endjob;
}
endjob:
VIR_FORCE_CLOSE(tmp_fd);
+ if (unlink_tmp)
+ unlink(tmp);
VIR_FREE(tmp);
if (qemuDomainObjEndJob(driver, vm) == 0)
}
if (virFDStreamOpenFile(st, chr->source.data.file.path,
- 0, 0, O_RDWR, false) < 0)
+ 0, 0, O_RDWR) < 0)
goto cleanup;
ret = 0;
if (virFDStreamOpenFile(stream,
vol->target.path,
offset, length,
- O_RDONLY, false) < 0)
+ O_RDONLY) < 0)
goto out;
ret = 0;
if (virFDStreamOpenFile(stream,
vol->target.path,
offset, length,
- O_WRONLY, false) < 0)
+ O_WRONLY) < 0)
goto out;
ret = 0;
}
if (virFDStreamOpenFile(st, chr->source.data.file.path,
- 0, 0, O_RDWR, false) < 0)
+ 0, 0, O_RDWR) < 0)
goto cleanup;
ret = 0;
if (NS_FAILED(rc) || !width || !height) {
vboxError(VIR_ERR_OPERATION_FAILED, "%s",
_("unable to get screen resolution"));
- unlink(tmp);
goto endjob;
}
if (NS_FAILED(rc)) {
vboxError(VIR_ERR_OPERATION_FAILED, "%s",
_("failed to take screenshot"));
- unlink(tmp);
goto endjob;
}
screenDataSize) < 0) {
virReportSystemError(errno, _("unable to write data "
"to '%s'"), tmp);
- unlink(tmp);
goto endjob;
}
if (VIR_CLOSE(tmp_fd) < 0) {
virReportSystemError(errno, _("unable to close %s"), tmp);
- unlink(tmp);
goto endjob;
}
- if (virFDStreamOpenFile(st, tmp, 0, 0, O_RDONLY, true) < 0) {
+ if (virFDStreamOpenFile(st, tmp, 0, 0, O_RDONLY) < 0) {
vboxError(VIR_ERR_OPERATION_FAILED, "%s",
_("unable to open stream"));
- unlink(tmp);
goto endjob;
}
}
VIR_FORCE_CLOSE(tmp_fd);
+ unlink(tmp);
VIR_FREE(tmp);
VBOX_RELEASE(machine);
vboxIIDUnalloc(&iid);
}
if (virFDStreamOpenFile(st, chr->source.data.file.path,
- 0, 0, O_RDWR, false) < 0)
+ 0, 0, O_RDWR) < 0)
goto cleanup;
ret = 0;