Signed-off-by: Guoyi Tu <t...@chinatelecom.cn>
---
include/qemu/osdep.h | 1 +
monitor/misc.c | 21 +--------------------
util/osdep.c | 25 +++++++++++++++++++++++++
util/qemu-sockets.c | 17 +++++------------
4 files changed, 32 insertions(+), 32 deletions(-)
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index b1c161c035..b920f128a7 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -491,6 +491,7 @@ int qemu_open_old(const char *name, int flags, ...);
int qemu_open(const char *name, int flags, Error **errp);
int qemu_create(const char *name, int flags, mode_t mode, Error **errp);
int qemu_close(int fd);
+int qemu_get_fd(Monitor *mon, const char *fdname, Error **errp);
int qemu_unlink(const char *name);
#ifndef _WIN32
int qemu_dup_flags(int fd, int flags);
diff --git a/monitor/misc.c b/monitor/misc.c
index 3d2312ba8d..0d3372cf2b 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -1395,26 +1395,7 @@ void monitor_fdset_dup_fd_remove(int dup_fd)
int monitor_fd_param(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);
- } else {
- 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 qemu_get_fd(mon, fdname, errp);
}
/* Please update hmp-commands.hx when adding or changing commands */
diff --git a/util/osdep.c b/util/osdep.c
index 60fcbbaebe..c57551ca78 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -23,6 +23,7 @@
*/
#include "qemu/osdep.h"
#include "qapi/error.h"
+#include "qemu/ctype.h"
#include "qemu/cutils.h"
#include "qemu/sockets.h"
#include "qemu/error-report.h"
@@ -413,6 +414,30 @@ int qemu_close(int fd)
return close(fd);
}
+int qemu_get_fd(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);
+ } else {
+ 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;
+}
+