X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fpostgresql.c;h=7c140e0a3d7967b918c8f38b380b47ea13a8fb22;hp=3b702aeef83491d590a631e142f37fec856151c1;hb=d486225f89ea52d8ed2b4242eba2ad94c409f837;hpb=aecd05a0a0ec4d745506a67a937de6d1d6b33db5 diff --git a/src/postgresql.c b/src/postgresql.c index 3b702aee..7c140e0a 100644 --- a/src/postgresql.c +++ b/src/postgresql.c @@ -102,7 +102,7 @@ typedef struct { typedef struct { char *name; char *statement; - _Bool store_rates; + bool store_rates; } c_psql_writer_t; typedef struct { @@ -155,14 +155,14 @@ static const char *const def_queries[] = { "table_states", "disk_io", "disk_usage"}; static int def_queries_num = STATIC_ARRAY_SIZE(def_queries); -static c_psql_database_t **databases = NULL; -static size_t databases_num = 0; +static c_psql_database_t **databases; +static size_t databases_num; -static udb_query_t **queries = NULL; -static size_t queries_num = 0; +static udb_query_t **queries; +static size_t queries_num; -static c_psql_writer_t *writers = NULL; -static size_t writers_num = 0; +static c_psql_writer_t *writers; +static size_t writers_num; static int c_psql_begin(c_psql_database_t *db) { PGresult *r = PQexec(db->conn, "BEGIN"); @@ -340,6 +340,7 @@ static int c_psql_connect(c_psql_database_t *db) { C_PSQL_PAR_APPEND(buf, buf_len, "sslmode", db->sslmode); C_PSQL_PAR_APPEND(buf, buf_len, "krbsrvname", db->krbsrvname); C_PSQL_PAR_APPEND(buf, buf_len, "service", db->service); + C_PSQL_PAR_APPEND(buf, buf_len, "application_name", "collectd_postgresql"); db->conn = PQconnectdb(conninfo); db->proto_version = PQprotocolVersion(db->conn); @@ -347,10 +348,10 @@ static int c_psql_connect(c_psql_database_t *db) { } /* c_psql_connect */ static int c_psql_check_connection(c_psql_database_t *db) { - _Bool init = 0; + bool init = false; if (!db->conn) { - init = 1; + init = true; /* trigger c_release() */ if (0 == db->conn_complaint.interval) @@ -546,8 +547,8 @@ static int c_psql_exec_query(c_psql_database_t *db, udb_query_t *q, status = udb_query_prepare_result( q, prep_area, host, - (db->plugin_name != NULL) ? db->plugin_name : "postgresql", - db->instance, column_names, (size_t)column_num, db->interval); + (db->plugin_name != NULL) ? db->plugin_name : "postgresql", db->instance, + column_names, (size_t)column_num, db->interval); if (0 != status) { log_err("udb_query_prepare_result failed with status %i.", status); @@ -663,7 +664,7 @@ static char *values_name_to_sqlarray(const data_set_t *ds, char *string, } /* values_name_to_sqlarray */ static char *values_type_to_sqlarray(const data_set_t *ds, char *string, - size_t string_len, _Bool store_rates) { + size_t string_len, bool store_rates) { char *str_ptr; size_t str_len; @@ -706,7 +707,7 @@ static char *values_type_to_sqlarray(const data_set_t *ds, char *string, static char *values_to_sqlarray(const data_set_t *ds, const value_list_t *vl, char *string, size_t string_len, - _Bool store_rates) { + bool store_rates) { char *str_ptr; size_t str_len; @@ -741,7 +742,8 @@ static char *values_to_sqlarray(const data_set_t *ds, const value_list_t *vl, status = snprintf(str_ptr, str_len, ",%lf", rates[i]); } else if (ds->ds[i].type == DS_TYPE_COUNTER) - status = snprintf(str_ptr, str_len, ",%llu", vl->values[i].counter); + status = snprintf(str_ptr, str_len, ",%" PRIu64, + (uint64_t)vl->values[i].counter); else if (ds->ds[i].type == DS_TYPE_DERIVE) status = snprintf(str_ptr, str_len, ",%" PRIi64, vl->values[i].derive); else if (ds->ds[i].type == DS_TYPE_ABSOLUTE) @@ -934,7 +936,7 @@ static int c_psql_flush(cdtime_t timeout, } /* c_psql_flush */ static int c_psql_shutdown(void) { - _Bool had_flush = 0; + bool had_flush = false; plugin_unregister_read_group("postgresql"); @@ -947,7 +949,7 @@ static int c_psql_shutdown(void) { if (!had_flush) { plugin_unregister_flush("postgresql"); - had_flush = 1; + had_flush = true; } plugin_unregister_flush(cb_name); @@ -1095,7 +1097,7 @@ static int c_psql_config_writer(oconfig_item_t *ci) { writer->name = sstrdup(ci->values[0].value.string); writer->statement = NULL; - writer->store_rates = 1; + writer->store_rates = true; for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *c = ci->children + i; @@ -1122,7 +1124,7 @@ static int c_psql_config_database(oconfig_item_t *ci) { c_psql_database_t *db; char cb_name[DATA_MAX_NAME_LEN]; - static _Bool have_flush = 0; + static bool have_flush; if ((1 != ci->values_num) || (OCONFIG_TYPE_STRING != ci->values[0].type)) { log_err(" expects a single string argument."); @@ -1146,8 +1148,8 @@ static int c_psql_config_database(oconfig_item_t *ci) { cf_util_get_string(c, &db->password); else if (0 == strcasecmp(c->key, "Instance")) cf_util_get_string(c, &db->instance); - else if (0 == strcasecmp (c->key, "Plugin")) - cf_util_get_string (c, &db->plugin_name); + else if (0 == strcasecmp(c->key, "Plugin")) + cf_util_get_string(c, &db->plugin_name); else if (0 == strcasecmp(c->key, "SSLMode")) cf_util_get_string(c, &db->sslmode); else if (0 == strcasecmp(c->key, "KRBSrvName")) @@ -1219,7 +1221,7 @@ static int c_psql_config_database(oconfig_item_t *ci) { if (!have_flush) { /* flush all */ plugin_register_flush("postgresql", c_psql_flush, /* user data = */ NULL); - have_flush = 1; + have_flush = true; } /* flush this connection only */ @@ -1235,7 +1237,7 @@ static int c_psql_config_database(oconfig_item_t *ci) { } /* c_psql_config_database */ static int c_psql_config(oconfig_item_t *ci) { - static int have_def_config = 0; + static int have_def_config; if (0 == have_def_config) { oconfig_item_t *c;