summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--omfile.c62
-rw-r--r--omfwd.c5
-rw-r--r--ommysql.c41
-rw-r--r--ommysql.h7
-rw-r--r--omusrmsg.c12
-rw-r--r--rsyslog.h1
-rw-r--r--syslogd-types.h3
-rw-r--r--syslogd.c38
-rw-r--r--tcpsyslog.c6
9 files changed, 89 insertions, 86 deletions
diff --git a/omfile.c b/omfile.c
index 2e7c39f9..cb8061da 100644
--- a/omfile.c
+++ b/omfile.c
@@ -131,16 +131,16 @@ static rsRetVal cflineParseOutchannel(selector_t *f, uchar* p)
if(*p == ';')
++p; /* eat it */
- cflineParseTemplateName(&p, szBuf,
- sizeof(szBuf) / sizeof(char));
-
- if(szBuf[0] == '\0') /* no template? */
- strcpy(szBuf, " TradFmt"); /* use default! */
-
- iRet = cflineSetTemplateAndIOV(f, szBuf);
-
- dprintf("[outchannel]filename: '%s', template: '%s', size: %lu\n", f->f_un.f_file.f_fname, szBuf,
- f->f_un.f_file.f_sizeLimit);
+ if((iRet = cflineParseTemplateName(&p, szBuf,
+ sizeof(szBuf) / sizeof(char))) == RS_RET_OK) {
+ if(szBuf[0] == '\0') /* no template? */
+ strcpy(szBuf, " TradFmt"); /* use default! */
+
+ iRet = cflineSetTemplateAndIOV(f, szBuf);
+
+ dprintf("[outchannel]filename: '%s', template: '%s', size: %lu\n", f->f_un.f_file.f_fname, szBuf,
+ f->f_un.f_file.f_sizeLimit);
+ }
return(iRet);
}
@@ -408,9 +408,10 @@ static int prepareDynFile(selector_t *f)
* will be called for all outputs using file semantics,
* for example also for pipes.
*/
-void writeFile(selector_t *f)
+static rsRetVal writeFile(selector_t *f)
{
off_t actualFileSize;
+ rsRetVal iRet = RS_RET_OK;
assert(f != NULL);
@@ -419,7 +420,7 @@ void writeFile(selector_t *f)
*/
if(f->f_un.f_file.bDynamicName) {
if(prepareDynFile(f) != 0)
- return;
+ return RS_RET_ERR;
}
/* create the message based on format specified */
@@ -440,13 +441,12 @@ again:
/* try to resolve the situation */
if(resolveFileSizeLimit(f) != 0) {
/* didn't work out, so disable... */
- f->f_type = F_UNUSED;
snprintf(errMsg, sizeof(errMsg),
"no longer writing to file %s; grown beyond configured file size of %lld bytes, actual size %lld - configured command did not resolve situation",
f->f_un.f_file.f_fname, (long long) f->f_un.f_file.f_sizeLimit, (long long) actualFileSize);
errno = 0;
logerror(errMsg);
- return;
+ return RS_RET_DISABLE_ACTION;
} else {
snprintf(errMsg, sizeof(errMsg),
"file %s had grown beyond configured file size of %lld bytes, actual size was %lld - configured command resolved situation",
@@ -463,14 +463,14 @@ again:
/* If a named pipe is full, just ignore it for now
- mrn 24 May 96 */
if (f->f_type == F_PIPE && e == EAGAIN)
- return;
+ return RS_RET_OK;
/* If the filesystem is filled up, just ignore
* it for now and continue writing when possible
* based on patch for sysklogd by Martin Schulze on 2007-05-24
*/
if (f->f_type == F_FILE && e == ENOSPC)
- return;
+ return RS_RET_OK;
(void) close(f->f_file);
/*
@@ -485,19 +485,20 @@ again:
#endif
f->f_file = open(f->f_un.f_file.f_fname, O_WRONLY|O_APPEND|O_NOCTTY);
if (f->f_file < 0) {
- f->f_type = F_UNUSED;
+ iRet = RS_RET_DISABLE_ACTION;
logerror(f->f_un.f_file.f_fname);
} else {
untty();
goto again;
}
} else {
- f->f_type = F_UNUSED;
+ iRet = RS_RET_DISABLE_ACTION;
errno = e;
logerror(f->f_un.f_file.f_fname);
}
} else if (f->f_flags & SYNC_FILE)
fsync(f->f_file);
+ return(iRet);
}
@@ -520,6 +521,7 @@ rsRetVal freeInstanceFile(selector_t *f)
static rsRetVal doActionFile(selector_t *f)
{
assert(f != NULL);
+ rsRetVal iRet = RS_RET_OK;
dprintf(" (%s)\n", f->f_un.f_file.f_fname);
/* f->f_file == -1 is an indicator that the we couldn't
@@ -527,8 +529,9 @@ static rsRetVal doActionFile(selector_t *f)
* all others are doomed.
*/
if(f->f_un.f_file.bDynamicName || (f->f_file != -1))
- writeFile(f);
- return RS_RET_OK;
+ iRet = writeFile(f);
+
+ return iRet;
}
/* try to process a selector action line. Checks if the action
@@ -559,21 +562,24 @@ static rsRetVal parseSelectorAct(uchar **pp, selector_t *f)
* definitions. In the long term, this setting will probably replace
* anything else, but for the time being we must co-exist with the
* traditional mode lines.
+ * rgerhards, 2007-07-24: output-channels will go away. We keep them
+ * for compatibility reasons, but seems to have been a bad idea.
*/
- cflineParseOutchannel(f, p);
- /* TODO: provide status back if successful F_UNUSED */
- f->f_un.f_file.bDynamicName = 0;
- f->f_un.f_file.fCreateMode = fCreateMode; /* preserve current setting */
- f->f_un.f_file.fDirCreateMode = fDirCreateMode; /* preserve current setting */
- f->f_file = open(f->f_un.f_file.f_fname, O_WRONLY|O_APPEND|O_CREAT|O_NOCTTY,
- f->f_un.f_file.fCreateMode);
+ if((iRet = cflineParseOutchannel(f, p)) == RS_RET_OK) {
+ f->f_un.f_file.bDynamicName = 0;
+ f->f_un.f_file.fCreateMode = fCreateMode; /* preserve current setting */
+ f->f_un.f_file.fDirCreateMode = fDirCreateMode; /* preserve current setting */
+ f->f_file = open(f->f_un.f_file.f_fname, O_WRONLY|O_APPEND|O_CREAT|O_NOCTTY,
+ f->f_un.f_file.fCreateMode);
+ }
break;
case '?': /* This is much like a regular file handle, but we need to obtain
* a template name. rgerhards, 2007-07-03
*/
++p; /* eat '?' */
- cflineParseFileName(f, p); /* TODO: check if successful */
+ if((iRet = cflineParseFileName(f, p)) != RS_RET_OK)
+ break;
f->f_un.f_file.pTpl = tplFind((char*)f->f_un.f_file.f_fname,
strlen((char*) f->f_un.f_file.f_fname));
if(f->f_un.f_file.pTpl == NULL) {
diff --git a/omfwd.c b/omfwd.c
index 54811432..b9197e92 100644
--- a/omfwd.c
+++ b/omfwd.c
@@ -81,6 +81,7 @@ static rsRetVal doActionFwd(selector_t *f)
{
char *psz; /* temporary buffering */
register unsigned l;
+ rsRetVal iRet = RS_RET_OK;
int i;
unsigned e, lsent = 0;
int bSendSuccess;
@@ -132,7 +133,7 @@ static rsRetVal doActionFwd(selector_t *f)
dprintf("Retries: %d\n", f->f_prevcount);
if ( --f->f_prevcount < 0 ) {
dprintf("Giving up.\n");
- f->f_type = F_UNUSED;
+ iRet = RS_RET_DISABLE_ACTION;
}
else
dprintf("Left retries: %d\n", f->f_prevcount);
@@ -248,7 +249,7 @@ static rsRetVal doActionFwd(selector_t *f)
}
break;
}
- return RS_RET_OK;
+ return iRet;
}
diff --git a/ommysql.c b/ommysql.c
index 4d87d950..37ec0b22 100644
--- a/ommysql.c
+++ b/ommysql.c
@@ -45,6 +45,7 @@
#include "mysql/errmsg.h"
+static rsRetVal reInitMySQL(register selector_t *f);
/* query feature compatibility
*/
static rsRetVal isCompatibleWithFeature(syslogFeature eFeat)
@@ -120,7 +121,7 @@ static void DBErrorHandler(register selector_t *f)
*
* \ret int Returns 0 if successful (no error)
*/
-int checkDBErrorState(register selector_t *f)
+rsRetVal checkDBErrorState(register selector_t *f)
{
time_t now;
assert(f != NULL);
@@ -129,7 +130,7 @@ int checkDBErrorState(register selector_t *f)
/* If timeResumeOnError == 0 no error occured,
we can return with 0 (no error) */
if (f->f_un.f_mysql.f_timeResumeOnError == 0)
- return 0;
+ return RS_RET_OK;
(void) time(&now);
/* Now we know an error occured. We check timeResumeOnError
@@ -138,7 +139,7 @@ int checkDBErrorState(register selector_t *f)
if (f->f_un.f_mysql.f_timeResumeOnError > now)
{
/* dprintf("Wait time is not over yet.\n"); */
- return 1;
+ return RS_RET_ERR;
}
/* Ok, we can try to resume the database logging. First
@@ -161,9 +162,7 @@ int checkDBErrorState(register selector_t *f)
*/
f->f_un.f_mysql.f_timeResumeOnError = 0;
f->f_un.f_mysql.f_iLastDBErrNo = 0;
- reInitMySQL(f);
- return 0;
-
+ return reInitMySQL(f);
}
/*
@@ -171,13 +170,14 @@ int checkDBErrorState(register selector_t *f)
* MySQL connection.
* Initially added 2004-10-28 mmeckelein
*/
-void initMySQL(register selector_t *f)
+static rsRetVal initMySQL(register selector_t *f)
{
int iCounter = 0;
+ rsRetVal iRet = RS_RET_OK;
assert(f != NULL);
- if (checkDBErrorState(f))
- return;
+ if((iRet = checkDBErrorState(f)) != RS_RET_OK)
+ return iRet;
f->f_un.f_mysql.f_hmysql = mysql_init(NULL);
if(f->f_un.f_mysql.f_hmysql == NULL) {
@@ -185,7 +185,7 @@ void initMySQL(register selector_t *f)
/* The next statement causes a redundant message, but it is the
* best thing we can do in this situation. -- rgerhards, 2007-01-30
*/
- f->f_type = F_UNUSED;
+ iRet = RS_RET_DISABLE_ACTION;
} else { /* we could get the handle, now on with work... */
do {
/* Connect to database */
@@ -202,6 +202,7 @@ void initMySQL(register selector_t *f)
iCounter++;
} while (mysql_errno(f->f_un.f_mysql.f_hmysql) && iCounter<2);
}
+ return iRet;
}
/*
@@ -221,13 +222,13 @@ void closeMySQL(register selector_t *f)
* Reconnect a MySQL connection.
* Initially added 2004-12-02
*/
-void reInitMySQL(register selector_t *f)
+static rsRetVal reInitMySQL(register selector_t *f)
{
assert(f != NULL);
dprintf("reInitMySQL\n");
closeMySQL(f); /* close the current handle */
- initMySQL(f); /* new connection */
+ return initMySQL(f); /* new connection */
}
@@ -236,17 +237,17 @@ void reInitMySQL(register selector_t *f)
* to an established MySQL session.
* Initially added 2004-10-28 mmeckelein
*/
-void writeMySQL(register selector_t *f)
+rsRetVal writeMySQL(register selector_t *f)
{
char *psz;
int iCounter=0;
+ rsRetVal iRet = RS_RET_OK;
assert(f != NULL);
iovCreate(f);
psz = iovAsString(f);
-
- if (checkDBErrorState(f))
- return;
+ if((iRet = checkDBErrorState(f)) != RS_RET_OK)
+ return iRet;
/* Now we are trying to insert the data.
*
@@ -262,10 +263,11 @@ void writeMySQL(register selector_t *f)
DBErrorHandler(f);
}
else {
- /* dprintf("db insert sucessfully\n"); */
+ /* dprintf("db insert sucessfull\n"); */
}
iCounter++;
} while (mysql_errno(f->f_un.f_mysql.f_hmysql) && iCounter<2);
+ return iRet;
}
/* call the shell action
@@ -275,8 +277,7 @@ static rsRetVal doActionMySQL(selector_t *f)
assert(f != NULL);
dprintf("\n");
- writeMySQL(f);
- return RS_RET_OK;
+ return writeMySQL(f);
}
@@ -309,7 +310,7 @@ static rsRetVal parseSelectorAct(uchar **pp, selector_t *f)
logerror("To enable MySQL logging, a \"$ModLoad MySQL\" must be done - accepted for "
"the time being, but will fail in future releases.");
#ifndef WITH_DB
- f->f_type = F_UNUSED;
+ iRet = RS_RET_ERROR; /* this goes away anyhow, so it's not worth putting much effort in the return code */
errno = 0;
logerror("write to database action in config file, but rsyslogd compiled without "
"database functionality - ignored");
diff --git a/ommysql.h b/ommysql.h
index 7d828261..5ae065cb 100644
--- a/ommysql.h
+++ b/ommysql.h
@@ -29,11 +29,10 @@
/* prototypes will be removed as syslogd needs no longer to directly
* call into the module!
*/
-void initMySQL(register selector_t *f);
-void writeMySQL(register selector_t *f);
+//void initMySQL(register selector_t *f);
+rsRetVal writeMySQL(register selector_t *f);
void closeMySQL(register selector_t *f);
-void reInitMySQL(register selector_t *f);
-int checkDBErrorState(register selector_t *f);
+rsRetVal checkDBErrorState(register selector_t *f);
rsRetVal modInitMySQL(int iIFVersRequested, int *ipIFVersProvided, rsRetVal (**pQueryEtryPt)());
#endif /* #ifdef WITH_DB */
diff --git a/omusrmsg.c b/omusrmsg.c
index ecfc5862..5f743eff 100644
--- a/omusrmsg.c
+++ b/omusrmsg.c
@@ -293,15 +293,9 @@ static rsRetVal parseSelectorAct(uchar **pp, selector_t *f)
if(szTemplateName[0] == '\0')
strcpy(szTemplateName, " StdUsrMsgFmt");
iRet = cflineSetTemplateAndIOV(f, szTemplateName);
- /* Please note that we would need to check if the template
- * was found. If not, f->f_type would be F_UNUSED and we
- * can NOT carry on processing. These checks can be seen
- * on all other selector line code above. However, as we
- * do not have anything else to do here, we do not include
- * this check. Should you add any further processing at
- * this point here, you must first add a check for this
- * condition!
- * rgerhards 2005-07-29
+ /* NOTE: if you intend to do anything else here, be sure to
+ * chck iRet - as we currently have nothing else to do, we do not
+ * care (yet).
*/
}
diff --git a/rsyslog.h b/rsyslog.h
index 82515077..0f8666de 100644
--- a/rsyslog.h
+++ b/rsyslog.h
@@ -54,6 +54,7 @@ enum rsRetVal_ /** return value. All methods return this if not specified oth
RS_RET_INCOMPATIBLE = -2003, /**< function not compatible with requested feature */
RS_RET_NOENTRY = -2004, /**< do not create an entry for (whatever) - not necessary an error */
RS_RET_NO_SQL_STRING = -2005, /**< string is not suitable for use as SQL */
+ RS_RET_DISABLE_ACTION = -2006, /**< action requests that it be disabled */
RS_RET_OK = 0 /**< operation successful */
};
typedef enum rsRetVal_ rsRetVal; /**< friendly type for global return value */
diff --git a/syslogd-types.h b/syslogd-types.h
index 2865b81d..a9a045a1 100644
--- a/syslogd-types.h
+++ b/syslogd-types.h
@@ -115,7 +115,7 @@ struct syslogTime {
/* values for f_type in struct filed below*/
-#define F_UNUSED 0 /* unused entry */
+/* gone away #define F_UNUSED 0 */ /* unused entry */
#define F_FILE 1 /* regular file */
#define F_TTY 2 /* terminal */
#define F_CONSOLE 3 /* console terminal */
@@ -145,6 +145,7 @@ struct filed {
struct filed *f_next; /* next in linked list */
/*__attribute__((deprecated))*/ short f_type; /* entry type, see below */
short f_file; /* file descriptor */
+ short bEnabled; /* is the related action enabled (1) or disabled (0)? */
time_t f_time; /* time this was last written */
/* filter properties */
enum {
diff --git a/syslogd.c b/syslogd.c
index ea73370a..e5dbd2d1 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -2381,13 +2381,17 @@ static void processMsg(msg_t *pMsg)
bContinue = 1;
for (f = Files; f != NULL && bContinue ; f = f->f_next) {
- /* first, we need to check if this is a disabled (F_UNUSED)
- * entry. If so, we must not further process it, as the data
- * structure probably contains invalid pointers and other
- * such mess.
+ /* first, we need to check if this is a disabled
+ * entry. If so, we must not further process it.
* rgerhards 2005-09-26
+ * In the future, disabled modules may be re-probed from time
+ * to time. They are in a perfectly legal state, except that the
+ * doAction method indicated that it wanted to be disabled - but
+ * we do not consider this is a solution for eternity... So we
+ * should check from time to time if affairs have improved.
+ * rgerhards, 2007-07-24
*/
- if(f->f_type == F_UNUSED)
+ if(f->bEnabled == 0)
continue; /* on to next */
/* This is actually the "filter logic". Looks like we need
@@ -3309,12 +3313,14 @@ rsRetVal fprintlog(register selector_t *f)
/*dprintf("Called fprintlog, logging to %s", modGetName(pMod)); // TODO: this does not work with unused!*/
f->f_time = now; /* we need this for message repeation processing TODO: why must "now" be global? */
- if(f->f_type != F_UNUSED) {
- if(f->pMod->mod.om.doAction != NULL) { /* safety check */
- iRet = f->pMod->mod.om.doAction(f); /* call configured action */
- }
- // TODO: this causes problems for the emergency logging system!
- }
+
+ /* When we reach this point, we have a valid, non-disabled action.
+ * So let's execute it. -- rgerhards, 2007-07-24
+ */
+ iRet = f->pMod->mod.om.doAction(f); /* call configured action */
+ if(iRet == RS_RET_DISABLE_ACTION)
+ f->bEnabled = 0; /* that's it... */
+ // TODO: this causes problems for the emergency logging system!
if (f->f_type != F_FORW_UNKN)
f->f_prevcount = 0;
@@ -4514,13 +4520,11 @@ static void init()
for (i = 0; i < MAXUNAMES && *f->f_un.f_uname[i]; i++)
printf("%s, ", f->f_un.f_uname[i]);
break;
-
- case F_UNUSED:
- printf("UNUSED");
- break;
}
if(f->f_ReduceRepeated)
printf(" [RepeatedMsgReduction]");
+ if(f->bEnabled == 0)
+ printf(" [disabled]");
printf("\n");
}
}
@@ -5127,7 +5131,7 @@ static rsRetVal cfline(char *line, register selector_t *f)
pMod = omodGetNxt(NULL);
while(pMod != NULL) {
iRet = pMod->mod.om.parseSelectorAct(&p , f);
- dprintf("modprobe %s: %d\n", modGetName(pMod), iRet);
+ dprintf("trying selector action for %s: %d\n", modGetName(pMod), iRet);
if(iRet == RS_RET_CONFLINE_PROCESSED) {
dprintf("Module %s processed this config line.\n",
modGetName(pMod));
@@ -5139,6 +5143,7 @@ static rsRetVal cfline(char *line, register selector_t *f)
dprintf("module is incompatible with RepeatedMsgReduction - turned off\n");
f->f_ReduceRepeated = 0;
}
+ f->bEnabled = 1; /* action is enabled */
break;
}
else if(iRet != RS_RET_CONFLINE_UNPROCESSED) {
@@ -5154,7 +5159,6 @@ static rsRetVal cfline(char *line, register selector_t *f)
pMod = omodGetNxt(pMod);
}
-dprintf("cfline returns %d\n", iRet);
return (iRet == RS_RET_CONFLINE_PROCESSED) ? RS_RET_OK : RS_RET_NOENTRY;
}
diff --git a/tcpsyslog.c b/tcpsyslog.c
index 83204519..e8a52c97 100644
--- a/tcpsyslog.c
+++ b/tcpsyslog.c
@@ -826,7 +826,6 @@ int TCPSend(selector_t *f, char *msg, size_t len)
int done = 0;
int bIsCompressed;
int lenSend;
- short f_type;
char *buf = NULL; /* if this is non-NULL, it MUST be freed before return! */
enum TCPSendStatus eState;
TCPFRAMINGMODE framingToUse;
@@ -1025,10 +1024,7 @@ int TCPSend(selector_t *f, char *msg, size_t len)
return 0;
break;
default:
- f_type = f->f_type;
- f->f_type = F_UNUSED;
- logerror("message not (tcp)send");
- f->f_type = f_type;
+ dprintf("message not (tcp)send");
break;
}