diff options
author | Peter Xu <peterx@redhat.com> | 2017-08-02 17:41:20 +0800 |
---|---|---|
committer | Dr. David Alan Gilbert <dgilbert@redhat.com> | 2017-08-02 11:27:44 +0100 |
commit | 8bd9c4e6c565c566a6cba3470cb2d4ea63994143 (patch) | |
tree | 9d55afd7f69959e924a4d4aea37bd1dd35b86308 /io | |
parent | 2dfaf12ebbdbb85ac0a583caba02f329a7c1ac09 (diff) |
io: fix qio_channel_socket_accept err handling
When accept failed, we should setup errp with the reason. More
importantly, the caller may assume errp be non-NULL when error happens,
and not setting the errp may crash QEMU.
At the same time, move the trace_qio_channel_socket_accept_fail() after
the if check on EINTR. Two reasons:
1. when EINTR happened, it's not really a fault (we should just try
again), so we should not log with an "accept failure".
2. trace_*() functions may overwrite errno, then the old errno will be
missing. We need to either check errno before trace_*() calls, or
reserve the errno.
Signed-off-by: Peter Xu <peterx@redhat.com>
Message-Id: <1501666880-10159-3-git-send-email-peterx@redhat.com>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Diffstat (limited to 'io')
-rw-r--r-- | io/channel-socket.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/io/channel-socket.c b/io/channel-socket.c index 53386b7ba3..591d27e8c3 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -340,10 +340,11 @@ qio_channel_socket_accept(QIOChannelSocket *ioc, cioc->fd = qemu_accept(ioc->fd, (struct sockaddr *)&cioc->remoteAddr, &cioc->remoteAddrLen); if (cioc->fd < 0) { - trace_qio_channel_socket_accept_fail(ioc); if (errno == EINTR) { goto retry; } + error_setg_errno(errp, errno, "Unable to accept connection"); + trace_qio_channel_socket_accept_fail(ioc); goto error; } |