From 193857e99c423e6bd66f75c2f1ac2747a7fd645a Mon Sep 17 00:00:00 2001 From: laforge Date: Wed, 9 Feb 2005 16:46:29 +0000 Subject: forward-port 'port' config option from mysql plugin --- ulogd/pgsql/ulogd_PGSQL.c | 22 +++++++++++++++++++--- 1 file 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; -- cgit v1.2.3