From patchwork Wed Oct 10 14:02:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 190646 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4C2942C0086 for ; Thu, 11 Oct 2012 01:05:01 +1100 (EST) Received: from localhost ([::1]:39246 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TLwuB-0003iW-Do for incoming@patchwork.ozlabs.org; Wed, 10 Oct 2012 10:04:59 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48550) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TLwt7-0002PA-0e for qemu-devel@nongnu.org; Wed, 10 Oct 2012 10:04:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TLwsw-0002DC-GI for qemu-devel@nongnu.org; Wed, 10 Oct 2012 10:03:52 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:43012) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TLwsw-00027x-9P for qemu-devel@nongnu.org; Wed, 10 Oct 2012 10:03:42 -0400 Received: by mail-pa0-f45.google.com with SMTP id fb10so618733pad.4 for ; Wed, 10 Oct 2012 07:03:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=53myBydct9oIubj9pdsVv1OzdpHG+5jsqQ725Lo7F1o=; b=OL9hamCbwfEnT1/1juKVcoUwNOAl2J1wnZ9vOrw0Fig48CnEp7KqaXNHMJL3b/7vfq zF3SzWgUurJImVkVTEUhkIeHMEiZrPdsj2Ft4abfVpdgwgBeZZrox3zu5+5UsvC9qQ1m 1MVuEW6QDnJzS0x/rmTOi+CeGy/BKeIBFymd73h8OVg5hwPCRwX0wcqvIfPEztAErabd REGwT4ljwvbj4MMvU2TZCYZ3/8uhwaVat8Psr7G/RHjy4p6QqiskFAmSsbnQ/jcd+Dc2 JRXXgZEyNSUc7IPKD0BivtP8D2yoboOEwfNQCvLQ91i+U3KqPQ5P6qkTq0StNQBDbdRv WGDg== Received: by 10.66.90.65 with SMTP id bu1mr695592pab.31.1349877821912; Wed, 10 Oct 2012 07:03:41 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-169-1.ip50.fastwebnet.it. [93.34.169.1]) by mx.google.com with ESMTPS id n7sm905723pav.26.2012.10.10.07.03.40 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 10 Oct 2012 07:03:41 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 10 Oct 2012 16:02:52 +0200 Message-Id: <1349877786-23514-12-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.12.1 In-Reply-To: <1349877786-23514-1-git-send-email-pbonzini@redhat.com> References: <1349877786-23514-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.220.45 Cc: lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH 11/25] nbd: ask and print error information from qemu-sockets X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Before: $ qemu-system-x86_64 nbd:localhost:12345 inet_connect_opts: connect(ipv4,yakj.usersys.redhat.com,127.0.0.1,12345): Connection refused qemu-system-x86_64: could not open disk image nbd:localhost:12345: Connection refused After: $ x86_64-softmmu/qemu-system-x86_64 nbd:localhost:12345 qemu-system-x86_64: Failed to connect to socket: Connection refused qemu-system-x86_64: could not open disk image nbd:localhost:12345: Connection refused Signed-off-by: Paolo Bonzini --- nbd.c | 39 +++++++++++++++++++++++++++++++-------- 1 file modificato, 31 inserzioni(+), 8 rimozioni(-) diff --git a/nbd.c b/nbd.c index f61a288..cec5a94 100644 --- a/nbd.c +++ b/nbd.c @@ -208,7 +208,14 @@ int tcp_socket_outgoing(const char *address, uint16_t port) int tcp_socket_outgoing_spec(const char *address_and_port) { - return inet_connect(address_and_port, NULL); + Error *local_err = NULL; + int fd = inet_connect(address_and_port, &local_err); + + if (local_err != NULL) { + qerror_report_err(local_err); + error_free(local_err); + } + return fd; } int tcp_socket_incoming(const char *address, uint16_t port) @@ -220,22 +227,38 @@ int tcp_socket_incoming(const char *address, uint16_t port) int tcp_socket_incoming_spec(const char *address_and_port) { - char *ostr = NULL; - int olen = 0; - return inet_listen(address_and_port, ostr, olen, SOCK_STREAM, 0, NULL); + Error *local_err = NULL; + int fd = inet_listen(address_and_port, NULL, 0, SOCK_STREAM, 0, &local_err); + + if (local_err != NULL) { + qerror_report_err(local_err); + error_free(local_err); + } + return fd; } int unix_socket_incoming(const char *path) { - char *ostr = NULL; - int olen = 0; + Error *local_err = NULL; + int fd = unix_listen(path, NULL, 0, &local_err); - return unix_listen(path, ostr, olen, NULL); + if (local_err != NULL) { + qerror_report_err(local_err); + error_free(local_err); + } + return fd; } int unix_socket_outgoing(const char *path) { - return unix_connect(path, NULL); + Error *local_err = NULL; + int fd = unix_connect(path, &local_err); + + if (local_err != NULL) { + qerror_report_err(local_err); + error_free(local_err); + } + return fd; } /* Basic flow for negotiation