From patchwork Thu Nov 9 08:03:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuval Shaia X-Patchwork-Id: 10050391 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 05FEC60381 for ; Thu, 9 Nov 2017 08:03:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDC932AB97 for ; Thu, 9 Nov 2017 08:03:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E28432AB9B; Thu, 9 Nov 2017 08:03:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C996D2AB97 for ; Thu, 9 Nov 2017 08:03:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753192AbdKIID3 (ORCPT ); Thu, 9 Nov 2017 03:03:29 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:50728 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753096AbdKIID2 (ORCPT ); Thu, 9 Nov 2017 03:03:28 -0500 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id vA983OlU031255 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 9 Nov 2017 08:03:25 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id vA983Oo6016111 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 9 Nov 2017 08:03:24 GMT Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id vA983NPD001414; Thu, 9 Nov 2017 08:03:23 GMT Received: from localhost.localdomain (/77.138.186.148) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 09 Nov 2017 00:03:23 -0800 From: Yuval Shaia To: sean.hefty@intel.com, hal@dev.mellanox.co.il, jgg@ziepe.ca, linux-rdma@vger.kernel.org Cc: Yuval Shaia Subject: [PATCH] librdmacm: Print correct error message from rdma_getaddrinfo Date: Thu, 9 Nov 2017 10:03:07 +0200 Message-Id: <20171109080307.4825-1-yuval.shaia@oracle.com> X-Mailer: git-send-email 2.13.6 X-Source-IP: aserv0021.oracle.com [141.146.126.233] Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A return value of -1 from rdma_getaddrinfo can indicates either EAI_BADFLAGS returned from getaddrinfo or a generic error returned by rdma_getaddrinfo itself. Fix this conflict by printing errno in case it is set, otherwise gai_strerror. Signed-off-by: Yuval Shaia --- librdmacm/examples/cmatose.c | 6 ++++-- librdmacm/examples/cmtime.c | 6 ++++-- librdmacm/examples/rdma_client.c | 3 ++- librdmacm/examples/rdma_server.c | 3 ++- librdmacm/examples/rdma_xclient.c | 3 ++- librdmacm/examples/riostream.c | 6 ++++-- librdmacm/examples/rstream.c | 9 ++++++--- librdmacm/examples/udaddy.c | 6 ++++-- 8 files changed, 28 insertions(+), 14 deletions(-) diff --git a/librdmacm/examples/cmatose.c b/librdmacm/examples/cmatose.c index b1c9dd13..6f6a99d8 100644 --- a/librdmacm/examples/cmatose.c +++ b/librdmacm/examples/cmatose.c @@ -507,7 +507,8 @@ static int run_server(void) ret = get_rdma_addr(src_addr, dst_addr, port, &hints, &test.rai); if (ret) { - printf("cmatose: getrdmaaddr error: %s\n", gai_strerror(ret)); + printf("cmatose: getrdmaaddr error: %s\n", errno ? + strerror(errno) : gai_strerror(ret)); goto out; } @@ -580,7 +581,8 @@ static int run_client(void) ret = get_rdma_addr(src_addr, dst_addr, port, &hints, &test.rai); if (ret) { - printf("cmatose: getaddrinfo error: %s\n", gai_strerror(ret)); + printf("cmatose: getaddrinfo error: %s\n", errno ? + strerror(errno) : gai_strerror(ret)); return ret; } diff --git a/librdmacm/examples/cmtime.c b/librdmacm/examples/cmtime.c index aa96b901..a7d109dd 100644 --- a/librdmacm/examples/cmtime.c +++ b/librdmacm/examples/cmtime.c @@ -462,7 +462,8 @@ static int run_server(void) ret = get_rdma_addr(src_addr, dst_addr, port, &hints, &rai); if (ret) { - printf("getrdmaaddr error: %s\n", gai_strerror(ret)); + printf("getrdmaaddr error: %s\n", errno ? strerror(errno) : + gai_strerror(ret)); goto out; } @@ -491,7 +492,8 @@ static int run_client(void) ret = get_rdma_addr(src_addr, dst_addr, port, &hints, &rai); if (ret) { - printf("getaddrinfo error: %s\n", gai_strerror(ret)); + printf("getaddrinfo error: %s\n", errno ? strerror(errno) : + gai_strerror(ret)); return ret; } diff --git a/librdmacm/examples/rdma_client.c b/librdmacm/examples/rdma_client.c index c27047c5..de43eb0a 100644 --- a/librdmacm/examples/rdma_client.c +++ b/librdmacm/examples/rdma_client.c @@ -56,7 +56,8 @@ static int run(void) hints.ai_port_space = RDMA_PS_TCP; ret = rdma_getaddrinfo(server, port, &hints, &res); if (ret) { - printf("rdma_getaddrinfo: %s\n", gai_strerror(ret)); + printf("rdma_getaddrinfo: %s\n", errno ? strerror(errno) : + gai_strerror(ret)); goto out; } diff --git a/librdmacm/examples/rdma_server.c b/librdmacm/examples/rdma_server.c index bcf649fe..bedd9a73 100644 --- a/librdmacm/examples/rdma_server.c +++ b/librdmacm/examples/rdma_server.c @@ -57,7 +57,8 @@ static int run(void) hints.ai_port_space = RDMA_PS_TCP; ret = rdma_getaddrinfo(NULL, port, &hints, &res); if (ret) { - printf("rdma_getaddrinfo: %s\n", gai_strerror(ret)); + printf("rdma_getaddrinfo: %s\n", errno ? strerror(errno) : + gai_strerror(ret)); return ret; } diff --git a/librdmacm/examples/rdma_xclient.c b/librdmacm/examples/rdma_xclient.c index 63dfb6df..687e1deb 100644 --- a/librdmacm/examples/rdma_xclient.c +++ b/librdmacm/examples/rdma_xclient.c @@ -82,7 +82,8 @@ static int test(void) ret = rdma_getaddrinfo(server, port, &hints, &res); if (ret) { - printf("rdma_getaddrinfo: %s\n", gai_strerror(ret)); + printf("rdma_getaddrinfo: %s\n", errno ? strerror(errno) : + gai_strerror(ret)); return ret; } diff --git a/librdmacm/examples/riostream.c b/librdmacm/examples/riostream.c index bdf4fd34..883f8a82 100644 --- a/librdmacm/examples/riostream.c +++ b/librdmacm/examples/riostream.c @@ -363,7 +363,8 @@ static int server_listen(void) ret = getaddrinfo(src_addr, port, &ai_hints, &ai); } if (ret) { - printf("getaddrinfo: %s\n", gai_strerror(ret)); + printf("getaddrinfo: %s\n", errno ? strerror(errno) : + gai_strerror(ret)); return ret; } @@ -444,7 +445,8 @@ static int client_connect(void) ret = use_rgai ? rdma_getaddrinfo(dst_addr, port, &rai_hints, &rai) : getaddrinfo(dst_addr, port, &ai_hints, &ai); if (ret) { - printf("getaddrinfo: %s\n", gai_strerror(ret)); + printf("getaddrinfo: %s\n", errno ? strerror(errno) : + gai_strerror(ret)); return ret; } diff --git a/librdmacm/examples/rstream.c b/librdmacm/examples/rstream.c index 7523269c..11fe6f25 100644 --- a/librdmacm/examples/rstream.c +++ b/librdmacm/examples/rstream.c @@ -327,7 +327,8 @@ static int server_listen(void) ret = getaddrinfo(src_addr, port, &ai_hints, &ai); } if (ret) { - printf("getaddrinfo: %s\n", gai_strerror(ret)); + printf("getaddrinfo: %s\n", errno ? strerror(errno) : + gai_strerror(ret)); return ret; } @@ -412,7 +413,8 @@ static int client_connect(void) getaddrinfo(dst_addr, port, &ai_hints, &ai); if (ret) { - printf("getaddrinfo: %s\n", gai_strerror(ret)); + printf("getaddrinfo: %s\n", errno ? strerror(errno) : + gai_strerror(ret)); return ret; } @@ -425,7 +427,8 @@ static int client_connect(void) ret = getaddrinfo(src_addr, port, &ai_hints, &ai_src); } if (ret) { - printf("getaddrinfo src_addr: %s\n", gai_strerror(ret)); + printf("getaddrinfo src_addr: %s\n", errno ? + strerror(errno) : gai_strerror(ret)); return ret; } } diff --git a/librdmacm/examples/udaddy.c b/librdmacm/examples/udaddy.c index b1ac90c3..914be0a2 100644 --- a/librdmacm/examples/udaddy.c +++ b/librdmacm/examples/udaddy.c @@ -514,7 +514,8 @@ static int run_server(void) ret = get_rdma_addr(src_addr, dst_addr, port, &hints, &test.rai); if (ret) { - printf("udaddy: getrdmaaddr error: %s\n", gai_strerror(ret)); + printf("udaddy: getrdmaaddr error: %s\n", errno ? + strerror(errno) : gai_strerror(ret)); goto out; } @@ -563,7 +564,8 @@ static int run_client(void) ret = get_rdma_addr(src_addr, dst_addr, port, &hints, &test.rai); if (ret) { - printf("udaddy: getaddrinfo error: %s\n", gai_strerror(ret)); + printf("udaddy: getaddrinfo error: %s\n", errno ? + strerror(errno) : gai_strerror(ret)); return ret; }