[collectd] [PATCH] postgresql plugin: Fixed determination of 'max_params_num'.

Sebastian Harl sh at tokkee.org
Sun Aug 17 14:10:29 CEST 2008


When adding the default queries to a database definition, 'max_params_num' has
not been updated at all, resulting in a failed assertion during query
execution. This is now fixed by splitting the common code for adding a query
definition to a database definition into a new function and using that
function where appropriate.

Signed-off-by: Sebastian Harl <sh at tokkee.org>
---
 src/postgresql.c |   36 +++++++++++++++---------------------
 1 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/src/postgresql.c b/src/postgresql.c
index f326a23..eb7587f 100644
--- a/src/postgresql.c
+++ b/src/postgresql.c
@@ -621,20 +621,14 @@ static int config_set_column (c_psql_query_t *query, const oconfig_item_t *ci)
 	return 0;
 } /* config_set_column */
 
-static int config_set_query (c_psql_database_t *db, const oconfig_item_t *ci)
+static int set_query (c_psql_database_t *db, const char *name)
 {
 	c_psql_query_t *query;
 
-	if ((0 != ci->children_num) || (1 != ci->values_num)
-			|| (OCONFIG_TYPE_STRING != ci->values[0].type)) {
-		log_err ("Query expects a single string argument.");
-		return 1;
-	}
-
-	query = c_psql_query_get (ci->values[0].value.string);
+	query = c_psql_query_get (name);
 	if (NULL == query) {
 		log_err ("Query \"%s\" not found - please check your configuration.",
-				ci->values[0].value.string);
+				name);
 		return 1;
 	}
 
@@ -650,6 +644,16 @@ static int config_set_query (c_psql_database_t *db, const oconfig_item_t *ci)
 
 	db->queries[db->queries_num - 1] = query;
 	return 0;
+} /* set_query */
+
+static int config_set_query (c_psql_database_t *db, const oconfig_item_t *ci)
+{
+	if ((0 != ci->children_num) || (1 != ci->values_num)
+			|| (OCONFIG_TYPE_STRING != ci->values[0].type)) {
+		log_err ("Query expects a single string argument.");
+		return 1;
+	}
+	return set_query (db, ci->values[0].value.string);
 } /* config_set_query */
 
 static int c_psql_config_query (oconfig_item_t *ci)
@@ -719,18 +723,8 @@ static int c_psql_config_database (oconfig_item_t *ci)
 	}
 
 	if (NULL == db->queries) {
-		db->queries = (c_psql_query_t **)malloc (def_queries_num
-				* sizeof (*db->queries));
-
-		for (i = 0; i < def_queries_num; ++i) {
-			db->queries[i] = c_psql_query_get (def_queries[i]);
-			if (NULL == db->queries[i])
-				log_err ("Query \"%s\" not found - "
-						"please check your installation.",
-						def_queries[i]);
-			else
-				++db->queries_num;
-		}
+		for (i = 0; i < def_queries_num; ++i)
+			set_query (db, def_queries[i]);
 	}
 	return 0;
 }
-- 
1.6.0.rc2

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20080817/7640bc5f/attachment.pgp 


More information about the collectd mailing list