[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] [PATCH 07/19] config: fix libccs return codes and errno handling



Spotted by Coverity Scan

Signed-off-by: Fabio M. Di Nitto <fdinitto redhat com>
---
:100644 100644 b0cf55b... 541fed7... M	config/libs/libccsconfdb/extras.c
:100644 100644 3b2ab4b... 6b2e138... M	config/libs/libccsconfdb/fullxpath.c
:100644 100644 d9cddc0... bfc2d29... M	config/libs/libccsconfdb/libccs.c
 config/libs/libccsconfdb/extras.c    |   34 +++++++++++++++++++---------------
 config/libs/libccsconfdb/fullxpath.c |    9 ++++-----
 config/libs/libccsconfdb/libccs.c    |   14 +++++++++++++-
 3 files changed, 36 insertions(+), 21 deletions(-)

diff --git a/config/libs/libccsconfdb/extras.c b/config/libs/libccsconfdb/extras.c
index b0cf55b..541fed7 100644
--- a/config/libs/libccsconfdb/extras.c
+++ b/config/libs/libccsconfdb/extras.c
@@ -38,8 +38,10 @@ int ccs_lookup_nodename(int cd, const char *nodename, char **retval)
 	size_t nodename_len;
 	struct addrinfo hints;
 
-	if (nodename == NULL)
-		return (-1);
+	if (nodename == NULL) {
+		errno = EINVAL;
+		return -1;
+	}
 
 	nodename_len = strlen(nodename);
 	ret = snprintf(path, sizeof(path),
@@ -47,19 +49,19 @@ int ccs_lookup_nodename(int cd, const char *nodename, char **retval)
 		       nodename);
 	if (ret < 0 || (size_t) ret >= sizeof(path)) {
 		errno = E2BIG;
-		return (-E2BIG);
+		return -1;
 	}
 
 	str = NULL;
 	error = ccs_get(cd, path, &str);
 	if (!error) {
 		*retval = str;
-		return (0);
+		return 0;
 	}
 
 	if (nodename_len >= sizeof(host_only)) {
 		errno = E2BIG;
-		return (-E2BIG);
+		return -1;
 	}
 
 	/* Try just the hostname */
@@ -71,14 +73,16 @@ int ccs_lookup_nodename(int cd, const char *nodename, char **retval)
 		ret = snprintf(path, sizeof(path),
 			       "/cluster/clusternodes/clusternode[ name=\"%s\"]/@name",
 			       host_only);
-		if (ret < 0 || (size_t) ret >= sizeof(path))
-			return (-E2BIG);
+		if (ret < 0 || (size_t) ret >= sizeof(path)) {
+			errno = E2BIG;
+			return -1;
+		}
 
 		str = NULL;
 		error = ccs_get(cd, path, &str);
 		if (!error) {
 			*retval = str;
-			return (0);
+			return 0;
 		}
 	}
 
@@ -128,7 +132,7 @@ int ccs_lookup_nodename(int cd, const char *nodename, char **retval)
 				if (strlen(str) >= sizeof(canonical_name)) {
 					free(str);
 					errno = E2BIG;
-					return (-E2BIG);
+					return -1;
 				}
 				strcpy(canonical_name, str);
 			}
@@ -136,7 +140,7 @@ int ccs_lookup_nodename(int cd, const char *nodename, char **retval)
 			if (strlen(str) >= sizeof(cur_node)) {
 				free(str);
 				errno = E2BIG;
-				return (-E2BIG);
+				return -1;
 			}
 
 			strcpy(cur_node, str);
@@ -153,9 +157,9 @@ int ccs_lookup_nodename(int cd, const char *nodename, char **retval)
 				*retval = strdup(canonical_name);
 				if (*retval == NULL) {
 					errno = ENOMEM;
-					return (-ENOMEM);
+					return -1;
 				}
-				return (0);
+				return 0;
 			}
 
 			if (getaddrinfo(str, NULL, &hints, &ai) == 0) {
@@ -178,9 +182,9 @@ int ccs_lookup_nodename(int cd, const char *nodename, char **retval)
 						    strdup(canonical_name);
 						if (*retval == NULL) {
 							errno = ENOMEM;
-							return (-ENOMEM);
+							return -1;
 						}
-						return (0);
+						return 0;
 					}
 				}
 				freeaddrinfo(ai);
@@ -195,7 +199,7 @@ int ccs_lookup_nodename(int cd, const char *nodename, char **retval)
 out_fail:
 	errno = EINVAL;
 	*retval = NULL;
-	return (-1);
+	return -1;
 }
 
 static int facility_id_get(char *name)
diff --git a/config/libs/libccsconfdb/fullxpath.c b/config/libs/libccsconfdb/fullxpath.c
index 3b2ab4b..6b2e138 100644
--- a/config/libs/libccsconfdb/fullxpath.c
+++ b/config/libs/libccsconfdb/fullxpath.c
@@ -148,10 +148,8 @@ static int dump_objdb_buff(confdb_handle_t dump_handle, hdb_handle_t cluster_han
 		res =
 		    dump_objdb_buff(dump_handle, cluster_handle, object_handle, buffer,
 				    bufsize);
-		if (res) {
-			errno = res;
+		if (res)
 			return res;
-		}
 
 		if (object_handle != parent_object_handle) {
 			snprintf(temp, PATH_MAX - 1, "</%s>\n", object_name);
@@ -254,8 +252,7 @@ char *_ccs_get_fullxpath(confdb_handle_t handle, hdb_handle_t connection_handle,
 	unsigned int xmllistindex = 0;
 	int prev = 0;
 	char *rtn = NULL;
-
-	errno = 0;
+	int myerrno;
 
 	if (strncmp(query, "/", 1)) {
 		errno = EINVAL;
@@ -351,8 +348,10 @@ char *_ccs_get_fullxpath(confdb_handle_t handle, hdb_handle_t connection_handle,
 		errno = EINVAL;
 
 fail:
+	myerrno = errno;
 	if (obj)
 		xmlXPathFreeObject(obj);
 
+	errno = myerrno;
 	return rtn;
 }
diff --git a/config/libs/libccsconfdb/libccs.c b/config/libs/libccsconfdb/libccs.c
index d9cddc0..bfc2d29 100644
--- a/config/libs/libccsconfdb/libccs.c
+++ b/config/libs/libccsconfdb/libccs.c
@@ -468,6 +468,7 @@ static int _ccs_get(int desc, const char *query, char **rtn, int list)
 	char data[128];
 	size_t datalen = 0;
 	int fullxpathint = 0;
+	int myerrno;
 
 	*rtn = NULL;
 
@@ -499,8 +500,11 @@ static int _ccs_get(int desc, const char *query, char **rtn, int list)
 		    _ccs_get_fullxpath(handle, connection_handle, query, list);
 
 fail:
+	myerrno = errno;
+
 	confdb_disconnect(handle);
 
+	errno = myerrno;
 	if (!*rtn)
 		return -1;
 
@@ -518,6 +522,7 @@ int ccs_connect(void)
 {
 	confdb_handle_t handle = 0;
 	int ccs_handle = 0;
+	int myerrno;
 
 	handle = confdb_connect();
 	if (handle == -1)
@@ -535,8 +540,12 @@ int ccs_connect(void)
 	}
 
 fail:
+	myerrno = errno;
+
 	confdb_disconnect(handle);
 
+	errno = myerrno;
+
 	return ccs_handle;
 }
 
@@ -584,9 +593,10 @@ int ccs_disconnect(int desc)
 	char data[128];
 	size_t datalen = 0;
 	int fullxpathint = 0;
+	int myerrno;
 
 	handle = confdb_connect();
-	if (handle <= 0)
+	if (handle == -1)
 		return handle;
 
 	connection_handle = find_ccs_handle(handle, desc);
@@ -611,7 +621,9 @@ int ccs_disconnect(int desc)
 	ret = destroy_ccs_handle(handle, connection_handle);
 
 fail:
+	myerrno = errno;
 	confdb_disconnect(handle);
+	errno = myerrno;
 	return ret;
 }
 
-- 
1.7.4.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]