summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d9152ff)
raw | patch | inline | side by side (parent: d9152ff)
author | Sebastian Harl <sh@tokkee.org> | |
Fri, 18 Jul 2008 19:36:41 +0000 (21:36 +0200) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Thu, 24 Jul 2008 12:18:04 +0000 (14:18 +0200) |
Allocation and freeing of c_psql_database_t objects is now handled by the new
functions. This increases readability of the code.
Signed-off-by: Sebastian Harl <sh@tokkee.org>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
functions. This increases readability of the code.
Signed-off-by: Sebastian Harl <sh@tokkee.org>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
src/postgresql.c | patch | blob | history |
diff --git a/src/postgresql.c b/src/postgresql.c
index 40f8ec57dadaa91c5cfc414cbfdf7bf0a1bc0284..e477348836a98a081400eacd959fe52eee2f88b7 100644 (file)
--- a/src/postgresql.c
+++ b/src/postgresql.c
static c_psql_database_t *databases = NULL;
static int databases_num = 0;
+static c_psql_database_t *c_psql_database_new (const char *name)
+{
+ c_psql_database_t *db;
+
+ ++databases_num;
+ if (NULL == (databases = (c_psql_database_t *)realloc (databases,
+ databases_num * sizeof (*databases)))) {
+ log_err ("Out of memory.");
+ exit (5);
+ }
+
+ db = databases + (databases_num - 1);
+
+ db->conn = NULL;
+
+ db->conn_complaint.last = 0;
+ db->conn_complaint.interval = 0;
+
+ db->database = sstrdup (name);
+ db->host = NULL;
+ db->port = NULL;
+ db->user = NULL;
+ db->password = NULL;
+
+ db->sslmode = NULL;
+
+ db->krbsrvname = NULL;
+
+ db->service = NULL;
+ return db;
+} /* c_psql_database_new */
+
+static void c_psql_database_delete (c_psql_database_t *db)
+{
+ PQfinish (db->conn);
+
+ sfree (db->database);
+ sfree (db->host);
+ sfree (db->port);
+ sfree (db->user);
+ sfree (db->password);
+
+ sfree (db->sslmode);
+
+ sfree (db->krbsrvname);
+
+ sfree (db->service);
+ return;
+} /* c_psql_database_delete */
+
static void submit (const c_psql_database_t *db,
const char *type, const char *type_instance,
value_t *values, size_t values_len)
for (i = 0; i < databases_num; ++i) {
c_psql_database_t *db = databases + i;
-
- PQfinish (db->conn);
-
- sfree (db->database);
- sfree (db->host);
- sfree (db->port);
- sfree (db->user);
- sfree (db->password);
-
- sfree (db->sslmode);
-
- sfree (db->krbsrvname);
-
- sfree (db->service);
+ c_psql_database_delete (db);
}
sfree (databases);
return 1;
}
- ++databases_num;
- if (NULL == (databases = (c_psql_database_t *)realloc (databases,
- databases_num * sizeof (*databases)))) {
- log_err ("Out of memory.");
- exit (5);
- }
-
- db = databases + (databases_num - 1);
-
- db->conn = NULL;
-
- db->conn_complaint.last = 0;
- db->conn_complaint.interval = 0;
-
- db->database = sstrdup (ci->values[0].value.string);
- db->host = NULL;
- db->port = NULL;
- db->user = NULL;
- db->password = NULL;
-
- db->sslmode = NULL;
-
- db->krbsrvname = NULL;
-
- db->service = NULL;
+ db = c_psql_database_new (ci->values[0].value.string);
for (i = 0; i < ci->children_num; ++i) {
oconfig_item_t *c = ci->children + i;