Commit 7768e04c34c60d99de57ddcc37fcbbe736185430
Committed by
Anthony Liguori
1 parent
f07918fd
Add monitor_get_fd() command for fetching named fds
Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing
2 changed files
with
26 additions
and
0 deletions
monitor.c
@@ -1774,6 +1774,30 @@ static void do_closefd(Monitor *mon, const char *fdname) | @@ -1774,6 +1774,30 @@ static void do_closefd(Monitor *mon, const char *fdname) | ||
1774 | fdname); | 1774 | fdname); |
1775 | } | 1775 | } |
1776 | 1776 | ||
1777 | +int monitor_get_fd(Monitor *mon, const char *fdname) | ||
1778 | +{ | ||
1779 | + mon_fd_t *monfd; | ||
1780 | + | ||
1781 | + LIST_FOREACH(monfd, &mon->fds, next) { | ||
1782 | + int fd; | ||
1783 | + | ||
1784 | + if (strcmp(monfd->name, fdname) != 0) { | ||
1785 | + continue; | ||
1786 | + } | ||
1787 | + | ||
1788 | + fd = monfd->fd; | ||
1789 | + | ||
1790 | + /* caller takes ownership of fd */ | ||
1791 | + LIST_REMOVE(monfd, next); | ||
1792 | + qemu_free(monfd->name); | ||
1793 | + qemu_free(monfd); | ||
1794 | + | ||
1795 | + return fd; | ||
1796 | + } | ||
1797 | + | ||
1798 | + return -1; | ||
1799 | +} | ||
1800 | + | ||
1777 | static const mon_cmd_t mon_cmds[] = { | 1801 | static const mon_cmd_t mon_cmds[] = { |
1778 | #include "qemu-monitor.h" | 1802 | #include "qemu-monitor.h" |
1779 | { NULL, NULL, }, | 1803 | { NULL, NULL, }, |
monitor.h
@@ -20,6 +20,8 @@ void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, | @@ -20,6 +20,8 @@ void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, | ||
20 | BlockDriverCompletionFunc *completion_cb, | 20 | BlockDriverCompletionFunc *completion_cb, |
21 | void *opaque); | 21 | void *opaque); |
22 | 22 | ||
23 | +int monitor_get_fd(Monitor *mon, const char *fdname); | ||
24 | + | ||
23 | void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap); | 25 | void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap); |
24 | void monitor_printf(Monitor *mon, const char *fmt, ...) | 26 | void monitor_printf(Monitor *mon, const char *fmt, ...) |
25 | __attribute__ ((__format__ (__printf__, 2, 3))); | 27 | __attribute__ ((__format__ (__printf__, 2, 3))); |