[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when li
From: |
Knut Omang |
Subject: |
Re: [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address |
Date: |
Wed, 21 Oct 2015 19:52:58 +0200 |
On Mon, 2015-10-12 at 12:14 +0100, Daniel P. Berrange wrote:
> If the port in the SocketAddress struct is NULL, it can allow
> the kernel to automatically select a free port. This is useful
> in particular in unit tests to avoid a race trying to find a
> free port to run a test case on.
This patch seems to do a bit more than it claims ;-)
I just noticed that after a rebase a few minutes ago, all options I
have that uses this type of port syntax:
-serial telnet:ip:port
-serial tcp:ip:port
-qmp ip:port
started to ignore the port argument and instead provide a dynamic port.
Rebasing without this patch fixes the issue,
Thanks,
Knut
>
> Signed-off-by: Daniel P. Berrange <address@hidden>
> ---
> util/qemu-sockets.c | 18 +++++++++++++-----
> 1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
> index 9cc5bee..f9d2f6e 100644
> --- a/util/qemu-sockets.c
> +++ b/util/qemu-sockets.c
> @@ -128,12 +128,15 @@ int inet_listen_opts(QemuOpts *opts, int
> port_offset, Error **errp)
> ai.ai_family = PF_UNSPEC;
> ai.ai_socktype = SOCK_STREAM;
>
> - if ((qemu_opt_get(opts, "host") == NULL) ||
> - (qemu_opt_get(opts, "port") == NULL)) {
> - error_setg(errp, "host and/or port not specified");
> + if ((qemu_opt_get(opts, "host") == NULL)) {
> + error_setg(errp, "host not specified");
> return -1;
> }
> - pstrcpy(port, sizeof(port), qemu_opt_get(opts, "port"));
> + if (qemu_opt_get(opts, "port") != NULL) {
> + pstrcpy(port, sizeof(port), qemu_opt_get(opts, "port"));
> + } else {
> + port[0] = '\0';
> + }
> addr = qemu_opt_get(opts, "host");
>
> to = qemu_opt_get_number(opts, "to", 0);
> @@ -145,6 +148,10 @@ int inet_listen_opts(QemuOpts *opts, int
> port_offset, Error **errp)
> /* lookup */
> if (port_offset) {
> unsigned long long baseport;
> + if (strlen(port) == 0) {
> + error_setg(errp, "port not specified");
> + return -1;
> + }
> if (parse_uint_full(port, &baseport, 10) < 0) {
> error_setg(errp, "can't convert to a number: %s", port);
> return -1;
> @@ -156,7 +163,8 @@ int inet_listen_opts(QemuOpts *opts, int
> port_offset, Error **errp)
> }
> snprintf(port, sizeof(port), "%d", (int)baseport +
> port_offset);
> }
> - rc = getaddrinfo(strlen(addr) ? addr : NULL, port, &ai, &res);
> + rc = getaddrinfo(strlen(addr) ? addr : NULL,
> + strlen(port) ? port : NULL, &ai, &res);
> if (rc != 0) {
> error_setg(errp, "address resolution failed for %s:%s: %s",
> addr, port,
> gai_strerror(rc));
- [Qemu-devel] [PATCH v2 00/16] Introduce I/O channels framework, Daniel P. Berrange, 2015/10/15
- [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address, Daniel P. Berrange, 2015/10/12
- Re: [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address, Eric Blake, 2015/10/19
- Re: [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address,
Knut Omang <=
- Re: [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address, Daniel P. Berrange, 2015/10/22
- Re: [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address, Peter Maydell, 2015/10/22
- Re: [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address, Markus Armbruster, 2015/10/22
- Re: [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address, Daniel P. Berrange, 2015/10/22
- Re: [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address, Eric Blake, 2015/10/22
- Re: [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address, Shannon Zhao, 2015/10/31
- Re: [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address, Peter Maydell, 2015/10/31
[Qemu-devel] [PATCH v2 04/16] ui: convert VNC startup code to use SocketAddress, Daniel P. Berrange, 2015/10/12