summaryrefslogtreecommitdiffstats
path: root/ulogd
diff options
context:
space:
mode:
authorlaforge <laforge>2005-02-09 16:46:29 +0000
committerlaforge <laforge>2005-02-09 16:46:29 +0000
commit193857e99c423e6bd66f75c2f1ac2747a7fd645a (patch)
treecbd67bc1dc578e887611143df8d9e5d6c6ad1fe8 /ulogd
parentbac170f20471177eb90818011acc3f235cd58a8f (diff)
forward-port 'port' config option from mysql plugin
Diffstat (limited to 'ulogd')
-rw-r--r--ulogd/pgsql/ulogd_PGSQL.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/ulogd/pgsql/ulogd_PGSQL.c b/ulogd/pgsql/ulogd_PGSQL.c
index e6b6f17..b077fee 100644
--- a/ulogd/pgsql/ulogd_PGSQL.c
+++ b/ulogd/pgsql/ulogd_PGSQL.c
@@ -79,6 +79,13 @@ static config_entry_t table_ce = {
.options = CONFIG_OPT_MANDATORY,
};
+static config_entry_t port_ce = {
+ .next = &port_ce,
+ .key = "port",
+ .type = CONFIG_TYPE_INT,
+ .options = CONFIG_OPT_NONE,
+};
+
/* our main output function, called by ulogd */
static int pgsql_output(ulog_iret_t *result)
{
@@ -303,7 +310,8 @@ static int exit_nicely(PGconn *conn)
}
/* make connection and select database */
-static int pgsql_open_db(char *server, char *user, char *pass, char *db)
+static int pgsql_open_db(char *server, int port, char *user, char *pass,
+ char *db)
{
int len;
char *connstr;
@@ -316,6 +324,8 @@ static int pgsql_open_db(char *server, char *user, char *pass, char *db)
len += strlen(server);
if (pass)
len += strlen(pass);
+ if (port)
+ len += 20;
connstr = (char *) malloc(len);
if (!connstr)
@@ -326,6 +336,12 @@ static int pgsql_open_db(char *server, char *user, char *pass, char *db)
strcat(connstr, server);
}
+ if (port) {
+ char portbuf[20];
+ snprintf(portbuf, sizeof(portbuf), " port=%u", port);
+ strcat(connstr, portbuf);
+ }
+
strcat(connstr, " dbname=");
strcat(connstr, db);
strcat(connstr, " user=");
@@ -348,9 +364,9 @@ static int pgsql_open_db(char *server, char *user, char *pass, char *db)
static int pgsql_init(void)
{
/* have the opts parsed */
- config_parse_file("PGSQL", &table_ce);
+ config_parse_file("PGSQL", &port_ce);
- if (pgsql_open_db(host_ce.u.string, user_ce.u.string,
+ if (pgsql_open_db(host_ce.u.string, port_ce.u.value, user_ce.u.string,
pass_ce.u.string, db_ce.u.string)) {
ulogd_log(ULOGD_ERROR, "can't establish database connection\n");
return;