From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <reshmapa@ecsmtp.ir.intel.com>
Received: from mga14.intel.com (mga14.intel.com [192.55.52.115])
 by dpdk.org (Postfix) with ESMTP id 8F0F32BA2
 for <dev@dpdk.org>; Wed, 13 Jul 2016 18:29:25 +0200 (CEST)
Received: from fmsmga004.fm.intel.com ([10.253.24.48])
 by fmsmga103.fm.intel.com with ESMTP; 13 Jul 2016 09:29:24 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.28,358,1464678000"; d="scan'208";a="138553570"
Received: from irvmail001.ir.intel.com ([163.33.26.43])
 by fmsmga004.fm.intel.com with ESMTP; 13 Jul 2016 09:29:24 -0700
Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com
 [10.237.217.46])
 by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id
 u6DGTNrs010335; Wed, 13 Jul 2016 17:29:23 +0100
Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1])
 by sivswdev02.ir.intel.com with ESMTP id u6DGTNd4016151;
 Wed, 13 Jul 2016 17:29:23 +0100
Received: (from reshmapa@localhost)
 by sivswdev02.ir.intel.com with  id u6DGTNx8016147;
 Wed, 13 Jul 2016 17:29:23 +0100
From: Reshma Pattan <reshma.pattan@intel.com>
To: dev@dpdk.org
Cc: Reshma Pattan <reshma.pattan@intel.com>
Date: Wed, 13 Jul 2016 17:29:08 +0100
Message-Id: <1468427350-16102-2-git-send-email-reshma.pattan@intel.com>
X-Mailer: git-send-email 1.7.4.1
In-Reply-To: <1468427350-16102-1-git-send-email-reshma.pattan@intel.com>
References: <1468427350-16102-1-git-send-email-reshma.pattan@intel.com>
Subject: [dpdk-dev] [PATCH 1/3] pdump: fix error handlings
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Wed, 13 Jul 2016 16:29:26 -0000

The changes include
1)If mkdir fails for user passed socket paths log error and return.

2)At some places return value was set to errno and that non-negative number
was returned, but the intention was to return negative value.
So now rte_errno was set to errno and returning the actual negative value
that the APIs has returned.

Fixes: 278f945402c5 ("pdump: add new library for packet capture")

Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
---
 lib/librte_pdump/rte_pdump.c | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/lib/librte_pdump/rte_pdump.c b/lib/librte_pdump/rte_pdump.c
index 22ed476..9b921ce 100644
--- a/lib/librte_pdump/rte_pdump.c
+++ b/lib/librte_pdump/rte_pdump.c
@@ -449,6 +449,7 @@ pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type)
 	char dpdk_dir[PATH_MAX] = {0};
 	char dir[PATH_MAX] = {0};
 	char *dir_home = NULL;
+	int ret = 0;
 
 	if (type == RTE_PDUMP_SOCKET_SERVER && server_socket_dir[0] != 0)
 		snprintf(dir, sizeof(dir), "%s", server_socket_dir);
@@ -475,7 +476,16 @@ pdump_get_socket_path(char *buffer, int bufsz, enum rte_pdump_socktype type)
 					dpdk_dir, SOCKET_DIR);
 	}
 
-	mkdir(dir, 700);
+	ret =  mkdir(dir, 700);
+	/* if user passed socket path is invalid, return immediately */
+	if (ret < 0 && errno != EEXIST) {
+		RTE_LOG(ERR, PDUMP,
+			"Failed to create dir:%s:%s\n", dir,
+			strerror(errno));
+		rte_errno = errno;
+		return -1;
+	}
+
 	if (type == RTE_PDUMP_SOCKET_SERVER)
 		snprintf(buffer, bufsz, SERVER_SOCKET, dir);
 	else
@@ -667,8 +677,8 @@ pdump_create_client_socket(struct pdump_request *p)
 			"client socket(): %s:pid(%d):tid(%u), %s:%d\n",
 			strerror(errno), pid, rte_sys_gettid(),
 			__func__, __LINE__);
-		ret = errno;
-		return ret;
+		rte_errno = errno;
+		return -1;
 	}
 
 	ret = pdump_get_socket_path(addr.sun_path, sizeof(addr.sun_path),
@@ -677,6 +687,7 @@ pdump_create_client_socket(struct pdump_request *p)
 		RTE_LOG(ERR, PDUMP,
 			"Failed to get client socket path: %s:%d\n",
 			__func__, __LINE__);
+		rte_errno = errno;
 		goto exit;
 	}
 	addr.sun_family = AF_UNIX;
@@ -688,7 +699,7 @@ pdump_create_client_socket(struct pdump_request *p)
 			RTE_LOG(ERR, PDUMP,
 				"client bind(): %s, %s:%d\n",
 				strerror(errno), __func__, __LINE__);
-			ret = errno;
+			rte_errno = errno;
 			break;
 		}
 
@@ -701,6 +712,7 @@ pdump_create_client_socket(struct pdump_request *p)
 			RTE_LOG(ERR, PDUMP,
 				"Failed to get server socket path: %s:%d\n",
 				__func__, __LINE__);
+			rte_errno = errno;
 			break;
 		}
 		serv_addr.sun_family = AF_UNIX;
@@ -711,7 +723,8 @@ pdump_create_client_socket(struct pdump_request *p)
 			RTE_LOG(ERR, PDUMP,
 				"failed to send to server:%s, %s:%d\n",
 				strerror(errno), __func__, __LINE__);
-			ret =  errno;
+			rte_errno = errno;
+			ret = -1;
 			break;
 		}
 
@@ -722,7 +735,8 @@ pdump_create_client_socket(struct pdump_request *p)
 			RTE_LOG(ERR, PDUMP,
 				"failed to recv from server:%s, %s:%d\n",
 				strerror(errno), __func__, __LINE__);
-			ret = errno;
+			rte_errno = errno;
+			ret = -1;
 			break;
 		}
 		ret = server_resp.err_value;
-- 
2.5.0