summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-12-16 16:21:52 +0100
committerRainer Gerhards <rgerhards@adiscon.com>2009-12-16 16:21:52 +0100
commitd3592db45bfc4939c2d72c73a42ed9f79cb64052 (patch)
tree3634b6b5c0f522eb2ca9471744032d9a9103fd0a /plugins
parentb61be5dccaacfdfa7878e5e497022e073081f5f8 (diff)
downloadrsyslog-d3592db45bfc4939c2d72c73a42ed9f79cb64052.tar.gz
rsyslog-d3592db45bfc4939c2d72c73a42ed9f79cb64052.tar.xz
rsyslog-d3592db45bfc4939c2d72c73a42ed9f79cb64052.zip
bugfix: ompgsql did not properly check the server connection in tryResume()
what could lead to rsyslog running in a thight loop. Also did some code cleanup of previous patch.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/ompgsql/ompgsql.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/plugins/ompgsql/ompgsql.c b/plugins/ompgsql/ompgsql.c
index 784a722d..c13f58e9 100644
--- a/plugins/ompgsql/ompgsql.c
+++ b/plugins/ompgsql/ompgsql.c
@@ -65,6 +65,8 @@ typedef struct _instanceData {
} instanceData;
+static rsRetVal writePgSQL(uchar *psz, instanceData *pData);
+
BEGINcreateInstance
CODESTARTcreateInstance
ENDcreateInstance
@@ -170,9 +172,6 @@ tryExec(uchar *pszCmd, instanceData *pData)
int bHadError = 0;
/* try insert */
-BEGINfunc
-RUNLOG_VAR("%p", pData->f_hpgsql);
-RUNLOG_VAR("%s", pszCmd);
pgRet = PQexec(pData->f_hpgsql, (char*)pszCmd);
execState = PQresultStatus(pgRet);
if(execState != PGRES_COMMAND_OK && execState != PGRES_TUPLES_OK) {
@@ -181,7 +180,6 @@ RUNLOG_VAR("%s", pszCmd);
}
PQclear(pgRet);
-ENDfunc
return(bHadError);
}
@@ -193,7 +191,8 @@ ENDfunc
* a sql format error - connection aborts were properly handled
* before my patch. -- rgerhards, 2009-04-17
*/
-rsRetVal writePgSQL(uchar *psz, instanceData *pData)
+static rsRetVal
+writePgSQL(uchar *psz, instanceData *pData)
{
int bHadError = 0;
DEFiRet;
@@ -231,6 +230,16 @@ BEGINtryResume
CODESTARTtryResume
if(pData->f_hpgsql == NULL) {
iRet = initPgSQL(pData, 1);
+ if(iRet == RS_RET_OK) {
+ /* the code above seems not to actually connect to the database. As such, we do a
+ * dummy statement (a pointless select...) to verify the connection and return
+ * success only when that statemetn succeeds. Note that I am far from being a
+ * PostgreSQL expert, so any patch that does the desired result in a more
+ * intelligent way is highly welcome. -- rgerhards, 2009-12-16
+ */
+ iRet = writePgSQL((uchar*)"select 'a' as a", pData);
+ }
+
}
ENDtryResume