summaryrefslogtreecommitdiffstats
path: root/ommysql.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2007-08-03 14:58:24 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2007-08-03 14:58:24 +0000
commit51971302280a9789b794e6c0c534a6e02767a39e (patch)
tree39234fe7dab5a0ac5ff51f0d55b5e1a19e159c43 /ommysql.c
parentadbf55ece666c71e882c370a74efa0bbf3239226 (diff)
downloadrsyslog-51971302280a9789b794e6c0c534a6e02767a39e.tar.gz
rsyslog-51971302280a9789b794e6c0c534a6e02767a39e.tar.xz
rsyslog-51971302280a9789b794e6c0c534a6e02767a39e.zip
- I found out that we finally have problems with the (somewhat recursive)
call to logerror() that many of the modules do. I have not tried it, but I think things will become wild when we compile without pthread support. Threading prevents full recursion, so we have not seen any bad effects so far. However, the problems that I experienced in ommysl (that caused me to re-structure startWorker()) are actually rooted in this issue. I first thought to fix it via a module interace, but I now came to the conclusion that it is not more effort and much cleaner to do an internal error buffering class. This is implemented in errbuf.c/h. - I just noticed that this is not actually an error buf, but the core of an input module for all internal messages. As such, I implement it now as iminternal.c/h. Of course, there is no input module interface yet designed, but that doesn't matter. Worst-case, I need to re-write the im, best case I can use the im (at least partly) to define the interface. - added a few functions to the linkedlist class - error messages during startup are now buffered - so we do no longer need to think about how emergency logging might work. Actually, these are logged to whatever is instatiated in the log file. This enhances the chance that we will be able to drop the error message somewhere it is seen.
Diffstat (limited to 'ommysql.c')
-rw-r--r--ommysql.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/ommysql.c b/ommysql.c
index 573e72ec..801bf5ac 100644
--- a/ommysql.c
+++ b/ommysql.c
@@ -1,4 +1,4 @@
-/* omusrmsg.c
+/* ommysql.c
* This is the implementation of the build-in output module for MySQL.
*
* NOTE: read comments in module-template.h to understand how this file
@@ -115,7 +115,7 @@ ENDgetWriteFDForSelect
* We check if we have a valid MySQL handle. If not, we simply
* report an error, but can not be specific. RGerhards, 2007-01-30
*/
-static void reportDBError(instanceData *pData)
+static void reportDBError(instanceData *pData, int bSilent)
{
char errMsg[512];
@@ -128,7 +128,10 @@ static void reportDBError(instanceData *pData)
} else { /* we can ask mysql for the error description... */
snprintf(errMsg, sizeof(errMsg)/sizeof(char), "db error (%d): %s\n", mysql_errno(pData->f_hmysql),
mysql_error(pData->f_hmysql));
- logerror(errMsg);
+ if(bSilent)
+ dprintf("mysql, DBError(silent): %s\n", errMsg);
+ else
+ logerror(errMsg);
}
return;
@@ -139,7 +142,7 @@ static void reportDBError(instanceData *pData)
* MySQL connection.
* Initially added 2004-10-28 mmeckelein
*/
-static rsRetVal initMySQL(instanceData *pData)
+static rsRetVal initMySQL(instanceData *pData, int bSilent)
{
DEFiRet;
@@ -154,7 +157,7 @@ static rsRetVal initMySQL(instanceData *pData)
/* Connect to database */
if(mysql_real_connect(pData->f_hmysql, pData->f_dbsrv, pData->f_dbuid,
pData->f_dbpwd, pData->f_dbname, 0, NULL, 0) == NULL) {
- reportDBError(pData);
+ reportDBError(pData, bSilent);
closeMySQL(pData); /* ignore any error we may get */
iRet = RS_RET_SUSPENDED;
}
@@ -179,10 +182,10 @@ rsRetVal writeMySQL(uchar *psz, instanceData *pData)
if(mysql_query(pData->f_hmysql, (char*)psz)) {
/* error occured, try to re-init connection and retry */
closeMySQL(pData); /* close the current handle */
- CHKiRet(initMySQL(pData)); /* try to re-open */
+ CHKiRet(initMySQL(pData, 0)); /* try to re-open */
if(mysql_query(pData->f_hmysql, (char*)psz)) { /* re-try insert */
/* we failed, giving up for now */
- reportDBError(pData);
+ reportDBError(pData, 0);
closeMySQL(pData); /* free ressources */
ABORT_FINALIZE(RS_RET_SUSPENDED);
}
@@ -196,7 +199,7 @@ finalize_it:
BEGINtryResume
CODESTARTtryResume
if(pData->f_hmysql == NULL) {
- iRet = initMySQL(pData);
+ iRet = initMySQL(pData, 1);
}
ENDtryResume
@@ -273,7 +276,7 @@ CODE_STD_STRING_REQUESTparseSelectorAct(1)
logerror("Trouble with MySQL connection properties. -MySQL logging disabled");
ABORT_FINALIZE(RS_RET_INVALID_PARAMS);
} else {
- CHKiRet(initMySQL(pData));
+ CHKiRet(initMySQL(pData, 0));
}
#endif /* #ifdef WITH_DB */