IRC being well on the way to deprecate other character devices, it must be exposed to management tools as well. These often prefer to pass a socket FD instead of a host and port to connect to, so this patch adds an appropriate option.
Signed-off-by: Max Reitz <mre...@redhat.com> --- qemu-char.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index a68fef3..4507e5f 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -3937,19 +3937,26 @@ static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend, static void qemu_chr_parse_irc(QemuOpts *opts, ChardevBackend *backend, Error **errp) { - const char *host, *port, *nick, *channel; + const char *host, *port, *nick, *channel, *sockfd; SocketAddress *addr; host = qemu_opt_get(opts, "host"); port = qemu_opt_get(opts, "port") ?: "6667"; + sockfd = qemu_opt_get(opts, "sockfd"); nick = qemu_opt_get(opts, "nick"); channel = qemu_opt_get(opts, "channel"); - if (!host || !nick || !channel) { + if ((!host && !sockfd) || !nick || !channel) { error_setg(errp, "chardev: irc: Missing options"); return; } + if ((host || port) && sockfd) { + error_setg(errp, + "chardev: irc: Both sockfd and host and/or port specified"); + return; + } + if (strlen(nick) > 64 || strlen(channel) > 64) { error_setg(errp, "chardev: irc: Nick or channel too long"); return; @@ -3958,10 +3965,17 @@ static void qemu_chr_parse_irc(QemuOpts *opts, ChardevBackend *backend, backend->irc = g_new0(ChardevIrc, 1); addr = g_new0(SocketAddress, 1); - addr->kind = SOCKET_ADDRESS_KIND_INET; - addr->inet = g_new0(InetSocketAddress, 1); - addr->inet->host = g_strdup(host); - addr->inet->port = g_strdup(port); + if (host) { + addr->kind = SOCKET_ADDRESS_KIND_INET; + addr->inet = g_new0(InetSocketAddress, 1); + addr->inet->host = g_strdup(host); + addr->inet->port = g_strdup(port); + } else { + addr->kind = SOCKET_ADDRESS_KIND_FD; + addr->fd = g_new(String, 1); + addr->fd->str = g_strdup(sockfd); + } + backend->irc->addr = addr; backend->irc->nick = g_strdup(nick); @@ -4332,6 +4346,9 @@ QemuOptsList qemu_chardev_opts = { },{ .name = "channel", .type = QEMU_OPT_STRING, + },{ + .name = "sockfd", + .type = QEMU_OPT_STRING, }, { /* end of list */ } }, -- 2.3.4