diff mbox series

[1/3] monitor: Add monitor_recv_fd function to work with sent fds

Message ID 20190412122028.7067-2-yury-kotov@yandex-team.ru (mailing list archive)
State New, archived
Headers show
Series Add 'inline-fd:' protocol for migration | expand

Commit Message

Yury Kotov April 12, 2019, 12:20 p.m. UTC
Signed-off-by: Yury Kotov <yury-kotov@yandex-team.ru>
---
 include/monitor/monitor.h |  1 +
 monitor.c                 | 15 +++++++++++----
 2 files changed, 12 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index c1b40a9cac..9b9e593fb3 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -25,6 +25,7 @@  void monitor_cleanup(void);
 int monitor_suspend(Monitor *mon);
 void monitor_resume(Monitor *mon);
 
+int monitor_recv_fd(Monitor *mon, Error **errp);
 int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp);
 int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp);
 
diff --git a/monitor.c b/monitor.c
index 4807bbe811..3ebbc08e5c 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2206,9 +2206,8 @@  void qmp_getfd(const char *fdname, Error **errp)
     mon_fd_t *monfd;
     int fd, tmp_fd;
 
-    fd = qemu_chr_fe_get_msgfd(&cur_mon->chr);
+    fd = monitor_recv_fd(cur_mon, errp);
     if (fd == -1) {
-        error_setg(errp, QERR_FD_NOT_SUPPLIED);
         return;
     }
 
@@ -2266,6 +2265,15 @@  void qmp_closefd(const char *fdname, Error **errp)
     error_setg(errp, QERR_FD_NOT_FOUND, fdname);
 }
 
+int monitor_recv_fd(Monitor *mon, Error **errp)
+{
+    int fd = qemu_chr_fe_get_msgfd(&cur_mon->chr);
+    if (fd == -1) {
+        error_setg(errp, QERR_FD_NOT_SUPPLIED);
+    }
+    return fd;
+}
+
 int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp)
 {
     mon_fd_t *monfd;
@@ -2335,9 +2343,8 @@  AddfdInfo *qmp_add_fd(bool has_fdset_id, int64_t fdset_id, bool has_opaque,
     Monitor *mon = cur_mon;
     AddfdInfo *fdinfo;
 
-    fd = qemu_chr_fe_get_msgfd(&mon->chr);
+    fd = monitor_recv_fd(mon, errp);
     if (fd == -1) {
-        error_setg(errp, QERR_FD_NOT_SUPPLIED);
         goto error;
     }