trivial fix of qemu-sockets.c
cover trivial fix of qemu-sockets.c
Those two patches fix trivial issues which were found in the second review.
Amos Kong (2):
socket: remove redundant check
remove unused include of error.h
qemu-sockets.c | 4 +--- qemu_socket.h | 1 - 2 files changed, 1 insertions(+), 4 deletions(-)
PATCH 1/2 socket: remove redundant check
It's aleady in the end of loop, error should be set.
--- qemu-sockets.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
qemu-sockets.c +1 -3
@@ -178,9 +178,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)fprintf (stderr,"%s: bind(%s,%s,%d): %s\n" , __FUNCTION__,inet_strfamily (e->ai_family), uaddr,inet_getport (e),strerror (errno)); -if (!e->ai_next) { -error_set (errp,QERR_SOCKET_BIND_FAILED ); - } +error_set (errp,QERR_SOCKET_BIND_FAILED ); } }closesocket (slisten);
Signature · 1 line
1.7.1
PATCH 2/2 remove unused include of error.h
In reply to Amos Kong--- qemu_socket.h | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
qemu_socket.h +0 -1
@@ -27,7 +27,6 @@ int inet_aton(const char *cp, struct in_addr *ia);#endif /* !_WIN32 */ #include "qemu-option.h" -#include "error.h" #include "qerror.h" /* misc helpers */
Signature · 1 line
1.7.1
cover trivial fix of qemu-sockets.c
In reply to Amos KongThose patches fix trivial issues which were found
in the second review.
Amos Kong (3):
socket: remove redundant check
remove unused include of error.h
socket: clean up redundant assignment
qemu-sockets.c | 5 +---- qemu_socket.h | 1 - 2 files changed, 1 insertions(+), 5 deletions(-)
PATCH RESEND 1/3 socket: remove redundant check
It's aleady in the end of loop, error should be set.
--- qemu-sockets.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
qemu-sockets.c +1 -3
@@ -181,9 +181,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)fprintf (stderr,"%s: bind(%s,%s,%d): %s\n" , __FUNCTION__,inet_strfamily (e->ai_family), uaddr,inet_getport (e),strerror (errno)); -if (!e->ai_next) { -error_set (errp,QERR_SOCKET_BIND_FAILED ); - } +error_set (errp,QERR_SOCKET_BIND_FAILED ); } }closesocket (slisten);
Signature · 1 line
1.7.1
Re: [Qemu-devel] [Qemu-trivial] [RESEND PATCH 1/3] socket: remove redundant check
Quoted 12 lines · Amos Kong
It's aleady in the end of loop, error should be set.
Signed-off-by Amos Kong <[email protected]>--- qemu-sockets.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)qemu-sockets.c +0
-0
qemu-sockets.c int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp) · line 187
Quoted 10 lines
qemu-sockets.c +1
-3@@ -181,9 +181,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)fprintf (stderr,"%s: bind(%s,%s,%d): %s\n" , __FUNCTION__,inet_strfamily (e->ai_family), uaddr,inet_getport (e),strerror (errno)); -if (!e->ai_next) { -error_set (errp,QERR_SOCKET_BIND_FAILED ); - } +error_set (errp,QERR_SOCKET_BIND_FAILED ); } }closesocket (slisten);
This isn't obvious. It looks like the intent of the if (!e->ai_next) is to suppress the error so that the next iteration of the *outer* loop can succeed.
Why is it okay to set QERR_SOCKET_BIND_FAILED? We may have more addrinfos left to try in the outer loop. They may succeed so we don't want an error in that case.
Stefan
Re: [Qemu-devel] [Qemu-trivial] [RESEND PATCH 1/3] socket: remove redundant check
Quoted 3 lines · Stefan Hajnoczi
This isn't obvious. It looks like the intent of the if (!e->ai_next) is to suppress the error so that the next iteration of the *outer* loop can succeed.
Yeah, we only call it an error on the last time round. This loop is a bit confusingly structured, since we're effectively handling the failure in several places at once: we always fprintf() something, then we set the error on the last time round the loop, then at the end of the loop we fprintf again. We also duplicate the loop termination condition.
It might be better to have an Error *local_err in this function. Then we could unconditionally call error_set() for any failures, passing &local_err. Then at the end of the loop we can call error_propagate(errp, local_err) to pass an error up if we didn't succeed at all. Unfortunately you'd have to do
if (error_is_set(&local_err)) {
error_free(&local_err);
}
error_set(&local_err, QERR_whatever);for the error setting, since error_set() will assert if you try to set an error twice.
[Another demonstration of the fprintf errors being much more useful than the error_set mechanisms at the moment, incidentally. We can get away with the fprintfs because the only caller of this function which passes in a non-NULL errp is the migration code called from vl.c, which is just going to fprintf and exit on error anyway.]
-- PMM
Re: [Qemu-devel] [Qemu-trivial] [RESEND PATCH 1/3] socket: remove redundant check
Quoted 11 lines · Peter Maydell
Quoted 3 lines · Stefan Hajnoczi
This isn't obvious. It looks like the intent of the if (!e->ai_next) is to suppress the error so that the next iteration of the *outer* loop can succeed.
Yeah, we only call it an error on the last time round. This loop is a bit confusingly structured, since we're effectively handling the failure in several places at once: we always
fprintf()something, then we set the error on the last time round the loop, then at the end of the loop we fprintf again. We also duplicate the loop termination condition.
I cleaned it up some back in February, but my admittedly incremental improvement was rejected because it didn't also convert to error_set(). *shrug*
http://lists.nongnu.org/archive/html/qemu-devel/2012-02/msg00772.html
[...]
Re: [Qemu-devel] [Qemu-trivial] [RESEND PATCH 1/3] socket: remove redundant check
In reply to Stefan HajnocziQuoted 28 lines · Stefan Hajnoczi
Quoted 12 lines · Amos Kong
It's aleady in the end of loop, error should be set.
Signed-off-by Amos Kong <[email protected]>--- qemu-sockets.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)qemu-sockets.c +0
-0qemu-sockets.c int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp) · line 187
Quoted 10 lines
qemu-sockets.c +1
-3@@ -181,9 +181,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)fprintf (stderr,"%s: bind(%s,%s,%d): %s\n" , __FUNCTION__,inet_strfamily (e->ai_family), uaddr,inet_getport (e),strerror (errno)); -if (!e->ai_next) { -error_set (errp,QERR_SOCKET_BIND_FAILED ); - } +error_set (errp,QERR_SOCKET_BIND_FAILED ); } }closesocket (slisten);This isn't obvious. It looks like the intent of the if (!e->ai_next) is to suppress the error so that the next iteration of the *outer* loop can succeed.
Quoted 3 lines
Why is it okay to set
QERR_SOCKET_BIND_FAILED? We may have more addrinfos left to try in the outer loop. They may succeed so we don't want an error in that case.
You are correct, and the patch is wrong.
See also related
http://lists.nongnu.org/archive/html/qemu-devel/2012-02/msg00772.html
Re: [Qemu-devel] [Qemu-trivial] [RESEND PATCH 1/3] socket: remove redundant check
----- Original Message -----
Quoted 35 lines
Quoted 33 lines · Stefan Hajnoczi
Quoted 22 lines · Amos Kong
It's aleady in the end of loop, error should be set.
Signed-off-by Amos Kong <[email protected]>--- qemu-sockets.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)qemu-sockets.c +1
-3@@ -181,9 +181,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)fprintf (stderr,"%s: bind(%s,%s,%d): %s\n" , __FUNCTION__,inet_strfamily (e->ai_family), uaddr,inet_getport (e),strerror (errno)); -if (!e->ai_next) { -error_set (errp,QERR_SOCKET_BIND_FAILED ); - } +error_set (errp,QERR_SOCKET_BIND_FAILED );Quoted 3 lines
} } closesocket(slisten);This isn't obvious. It looks like the intent of the if (!e->ai_next) is
to suppress the error so that the next iteration of the *outer* loop can
succeed.
Quoted 6 lines
Quoted 4 lines
Why is it okay to set
QERR_SOCKET_BIND_FAILED? We may have more addrinfos left to try in the outer loop. They may succeed so we don't
want an error in that case.You are correct, and the patch is wrong.
Yeah, will drop this patch from this thread.
Thanks.
Quoted 4 lines
See also related
http://lists.nongnu.org/archive/html/qemu-devel/2012-02/msg00772.html
PATCH RESEND 2/3 remove unused include of error.h
In reply to Amos Kong--- qemu_socket.h | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
qemu_socket.h +0 -1
@@ -27,7 +27,6 @@ int inet_aton(const char *cp, struct in_addr *ia);#endif /* !_WIN32 */ #include "qemu-option.h" -#include "error.h" #include "qerror.h" /* misc helpers */
Signature · 1 line
1.7.1
PATCH RESEND 3/3 socket: clean up redundant assignment
In reply to Amos Kong--- qemu-sockets.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
qemu-sockets.c +0 -1
@@ -282,7 +282,6 @@ int inet_connect_opts(QemuOpts *opts, Error **errp)inet_strfamily (e->ai_family), e->ai_canonname, uaddr, uport, strerror(errno));closesocket (sock); - sock =-1 ;continue ; }freeaddrinfo (res);
Signature · 1 line
1.7.1