mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-28 11:21:44 +03:00
qemu_fd: Add validation before transferring file descriptors
Add validation to the transfer step to make the adding step more simple for easier cleanup paths. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
bcfd23b762
commit
80f75fb758
@ -65,6 +65,30 @@ qemuFDPassFree(qemuFDPass *fdpass)
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
qemuFDPassValidate(qemuFDPass *fdpass)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!fdpass->useFDSet &&
|
||||
fdpass->nfds > 1) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("direct FD passing supports only 1 file descriptor"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < fdpass->nfds; i++) {
|
||||
if (fdpass->fds[i].fd < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("invalid file descriptor"));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* qemuFDPassNew:
|
||||
* @prefix: prefix used for naming the passed FDs
|
||||
@ -186,6 +210,9 @@ qemuFDPassTransferCommand(qemuFDPass *fdpass,
|
||||
if (!fdpass)
|
||||
return 0;
|
||||
|
||||
if (qemuFDPassValidate(fdpass) < 0)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < fdpass->nfds; i++) {
|
||||
virCommandPassFD(cmd, fdpass->fds[i].fd, VIR_COMMAND_PASS_FD_CLOSE_PARENT);
|
||||
|
||||
@ -229,6 +256,9 @@ qemuFDPassTransferMonitor(qemuFDPass *fdpass,
|
||||
if (!fdpass)
|
||||
return 0;
|
||||
|
||||
if (qemuFDPassValidate(fdpass) < 0)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < fdpass->nfds; i++) {
|
||||
if (fdpass->useFDSet) {
|
||||
qemuMonitorAddFdInfo fdsetinfo;
|
||||
@ -274,6 +304,9 @@ qemuFDPassTransferMonitorFake(qemuFDPass *fdpass)
|
||||
if (!fdpass)
|
||||
return 0;
|
||||
|
||||
if (qemuFDPassValidate(fdpass) < 0)
|
||||
return -1;
|
||||
|
||||
if (fdpass->useFDSet) {
|
||||
fdpass->path = g_strdup_printf("/dev/fdset/monitor-fake");
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user