mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-31 05:51:53 -06:00
monitor: add Error-propagating monitor_handle_fd_param2()
and rebase monitor_handle_fd_param() to it. (Note that this will slightly change the behavior when the qemu_parse_fd() branch is selected and it fails: we now report (and in case of QMP, set) the error immediately, rather than allowing the caller to set its own error message (if any)). Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
This commit is contained in:
parent
e9c5c1f40c
commit
5906366ef0
2 changed files with 24 additions and 6 deletions
|
@ -75,6 +75,7 @@ int monitor_read_block_device_key(Monitor *mon, const char *device,
|
||||||
|
|
||||||
int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp);
|
int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp);
|
||||||
int monitor_handle_fd_param(Monitor *mon, const char *fdname);
|
int monitor_handle_fd_param(Monitor *mon, const char *fdname);
|
||||||
|
int monitor_handle_fd_param2(Monitor *mon, const char *fdname, Error **errp);
|
||||||
|
|
||||||
void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
|
void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
|
||||||
GCC_FMT_ATTR(2, 0);
|
GCC_FMT_ATTR(2, 0);
|
||||||
|
|
29
monitor.c
29
monitor.c
|
@ -2611,16 +2611,33 @@ int monitor_handle_fd_param(Monitor *mon, const char *fdname)
|
||||||
int fd;
|
int fd;
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
|
|
||||||
if (!qemu_isdigit(fdname[0]) && mon) {
|
fd = monitor_handle_fd_param2(mon, fdname, &local_err);
|
||||||
|
if (local_err) {
|
||||||
|
qerror_report_err(local_err);
|
||||||
|
error_free(local_err);
|
||||||
|
}
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
int monitor_handle_fd_param2(Monitor *mon, const char *fdname, Error **errp)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
Error *local_err = NULL;
|
||||||
|
|
||||||
|
if (!qemu_isdigit(fdname[0]) && mon) {
|
||||||
fd = monitor_get_fd(mon, fdname, &local_err);
|
fd = monitor_get_fd(mon, fdname, &local_err);
|
||||||
if (fd == -1) {
|
|
||||||
qerror_report_err(local_err);
|
|
||||||
error_free(local_err);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
fd = qemu_parse_fd(fdname);
|
fd = qemu_parse_fd(fdname);
|
||||||
|
if (fd == -1) {
|
||||||
|
error_setg(&local_err, "Invalid file descriptor number '%s'",
|
||||||
|
fdname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (local_err) {
|
||||||
|
error_propagate(errp, local_err);
|
||||||
|
assert(fd == -1);
|
||||||
|
} else {
|
||||||
|
assert(fd != -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue