mirror of
https://github.com/qemu/qemu.git
synced 2024-11-23 19:03:38 +08:00
monitor: Report errors from monitor_fdset_dup_fd_add
I'm keeping the EACCES because callers expect to be able to look at errno. Reviewed-by: Peter Xu <peterx@redhat.com> Signed-off-by: Fabiano Rosas <farosas@suse.de>
This commit is contained in:
parent
881172f3f9
commit
960f29b347
@ -51,7 +51,7 @@ int monitor_read_password(MonitorHMP *mon, ReadLineFunc *readline_func,
|
||||
|
||||
AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
|
||||
const char *opaque, Error **errp);
|
||||
int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags);
|
||||
int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags, Error **errp);
|
||||
void monitor_fdset_dup_fd_remove(int dup_fd);
|
||||
|
||||
void monitor_register_hmp(const char *name, bool info,
|
||||
|
@ -409,9 +409,10 @@ AddfdInfo *monitor_fdset_add_fd(int fd, bool has_fdset_id, int64_t fdset_id,
|
||||
return fdinfo;
|
||||
}
|
||||
|
||||
int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags)
|
||||
int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags, Error **errp)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
error_setg(errp, "Platform does not support fd passing (fdset)");
|
||||
return -ENOENT;
|
||||
#else
|
||||
MonFdset *mon_fdset;
|
||||
@ -431,6 +432,8 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags)
|
||||
QLIST_FOREACH(mon_fdset_fd, &mon_fdset->fds, next) {
|
||||
mon_fd_flags = fcntl(mon_fdset_fd->fd, F_GETFL);
|
||||
if (mon_fd_flags == -1) {
|
||||
error_setg(errp, "Failed to read file status flags for fd=%d",
|
||||
mon_fdset_fd->fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -442,11 +445,15 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags)
|
||||
|
||||
if (fd == -1) {
|
||||
errno = EACCES;
|
||||
error_setg(errp,
|
||||
"Failed to find file descriptor with matching flags=0x%x",
|
||||
flags);
|
||||
return -1;
|
||||
}
|
||||
|
||||
dup_fd = qemu_dup_flags(fd, flags);
|
||||
if (dup_fd == -1) {
|
||||
error_setg(errp, "Failed to dup() given file descriptor fd=%d", fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -456,6 +463,7 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags)
|
||||
return dup_fd;
|
||||
}
|
||||
|
||||
error_setg(errp, "Failed to find fdset /dev/fdset/%" PRId64, fdset_id);
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
#endif
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "monitor/monitor.h"
|
||||
#include "../monitor/monitor-internal.h"
|
||||
|
||||
int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags)
|
||||
int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags, Error **errp)
|
||||
{
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
|
10
util/osdep.c
10
util/osdep.c
@ -310,7 +310,6 @@ qemu_open_internal(const char *name, int flags, mode_t mode, Error **errp)
|
||||
/* Attempt dup of fd from fd set */
|
||||
if (strstart(name, "/dev/fdset/", &fdset_id_str)) {
|
||||
int64_t fdset_id;
|
||||
int dupfd;
|
||||
|
||||
fdset_id = qemu_parse_fdset(fdset_id_str);
|
||||
if (fdset_id == -1) {
|
||||
@ -319,14 +318,7 @@ qemu_open_internal(const char *name, int flags, mode_t mode, Error **errp)
|
||||
return -1;
|
||||
}
|
||||
|
||||
dupfd = monitor_fdset_dup_fd_add(fdset_id, flags);
|
||||
if (dupfd == -1) {
|
||||
error_setg_errno(errp, errno, "Could not dup FD for %s flags %x",
|
||||
name, flags);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return dupfd;
|
||||
return monitor_fdset_dup_fd_add(fdset_id, flags, errp);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user