summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2007-08-06 20:51:52 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2007-08-06 20:51:52 +0000
commitacb7dae3ae782dae451f2f7a2322138ee495244a (patch)
tree0268f8febf92e3b03186c12fbc85ca5cb6b4f07c
parenta7a9e013291754e27e5d074fae5b65cc045ce51b (diff)
downloadrsyslog-acb7dae3ae782dae451f2f7a2322138ee495244a.tar.gz
rsyslog-acb7dae3ae782dae451f2f7a2322138ee495244a.tar.xz
rsyslog-acb7dae3ae782dae451f2f7a2322138ee495244a.zip
moved action object out of syslogd.c to its own fileset (action.c/h)
-rw-r--r--Makefile.am2
-rw-r--r--action.c178
-rw-r--r--action.h80
-rw-r--r--syslogd.c178
-rw-r--r--template.h5
5 files changed, 265 insertions, 178 deletions
diff --git a/Makefile.am b/Makefile.am
index a51173bf..08db3296 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,7 +7,7 @@ rfc3195d_SOURCES=rfc3195d.c rsyslog.h
man_MANS = rfc3195d.8 rklogd.8 rsyslogd.8 rsyslog.conf.5
-rsyslogd_SOURCES=syslogd.c pidfile.c template.c outchannel.c stringbuf.c srUtils.c parse.c syslogd-types.h template.h outchannel.h syslogd.h stringbuf.h parse.h srUtils.h liblogging-stub.h net.c net.h msg.c msg.h omshell.c omshell.h omusrmsg.c omusrmsg.h ommysql.c ommysql.h omfwd.c omfwd.h tcpsyslog.c tcpsyslog.h omfile.h omfile.c omdiscard.c omdiscard.h modules.c modules.h module-template.h objomsr.c objomsr.h cfsysline.c cfsysline.h linkedlist.c linkedlist.h iminternal.c iminternal.h
+rsyslogd_SOURCES=syslogd.c pidfile.c template.c outchannel.c stringbuf.c srUtils.c parse.c syslogd-types.h template.h outchannel.h syslogd.h stringbuf.h parse.h srUtils.h liblogging-stub.h net.c net.h msg.c msg.h omshell.c omshell.h omusrmsg.c omusrmsg.h ommysql.c ommysql.h omfwd.c omfwd.h tcpsyslog.c tcpsyslog.h omfile.h omfile.c omdiscard.c omdiscard.h modules.c modules.h module-template.h objomsr.c objomsr.h cfsysline.c cfsysline.h linkedlist.c linkedlist.h iminternal.c iminternal.h action.c action.h
rsyslogd_CPPFLAGS=$(mysql_includes)
rsyslogd_LDADD=$(mysql_libs) $(zlib_libs) $(pthreads_libs)
diff --git a/action.c b/action.c
new file mode 100644
index 00000000..99e86c3d
--- /dev/null
+++ b/action.c
@@ -0,0 +1,178 @@
+/* action.c
+ *
+ * Implementation of the action object.
+ *
+ * File begun on 2007-08-06 by RGerhards (extracted from syslogd.c)
+ *
+ * Copyright 2007 Rainer Gerhards and Adiscon GmbH.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * A copy of the GPL can be found in the file "COPYING" in this distribution.
+ */
+#include "config.h"
+#include <stdio.h>
+#include <assert.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <time.h>
+
+#include "rsyslog.h"
+#include "syslogd.h" /* to get the own definition of dprintf() - not a smart thing... */
+#include "template.h"
+#include "action.h"
+#include "modules.h"
+
+
+/* destructs an action descriptor object
+ * rgerhards, 2007-08-01
+ */
+rsRetVal actionDestruct(action_t *pThis)
+{
+ assert(pThis != NULL);
+
+ if(pThis->pMod != NULL)
+ pThis->pMod->freeInstance(pThis->pModData);
+
+ if(pThis->f_pMsg != NULL)
+ MsgDestruct(pThis->f_pMsg);
+
+ if(pThis->ppTpl != NULL)
+ free(pThis->ppTpl);
+ if(pThis->ppMsgs != NULL)
+ free(pThis->ppMsgs);
+ free(pThis);
+
+ return RS_RET_OK;
+}
+
+
+/* create a new action descriptor object
+ * rgerhards, 2007-08-01
+ */
+rsRetVal actionConstruct(action_t **ppThis)
+{
+ DEFiRet;
+ action_t *pThis;
+
+ assert(ppThis != NULL);
+
+ if((pThis = (action_t*) calloc(1, sizeof(action_t))) == NULL) {
+ ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
+ }
+
+finalize_it:
+ *ppThis = pThis;
+ return iRet;
+}
+
+
+/* set an action back to active state -- rgerhards, 2007-08-02
+ */
+static rsRetVal actionResume(action_t *pThis)
+{
+ DEFiRet;
+
+ assert(pThis != NULL);
+ pThis->bSuspended = 0;
+
+ return iRet;
+}
+
+
+#define ACTION_RESUME_INTERVAL 30 /* TODO: make this dynamic from conf file */
+/* suspend an action -- rgerhards, 2007-08-02
+ */
+rsRetVal actionSuspend(action_t *pThis)
+{
+ DEFiRet;
+
+ assert(pThis != NULL);
+ pThis->bSuspended = 1;
+ pThis->ttResumeRtry = time(NULL) + ACTION_RESUME_INTERVAL;
+ pThis->iNbrResRtry = 0; /* tell that we did not yet retry to resume */
+
+ return iRet;
+}
+
+/* try to resume an action -- rgerhards, 2007-08-02
+ * returns RS_RET_OK if resumption worked, RS_RET_SUSPEND if the
+ * action is still suspended.
+ */
+rsRetVal actionTryResume(action_t *pThis)
+{
+ DEFiRet;
+ time_t ttNow;
+
+ assert(pThis != NULL);
+
+ ttNow = time(NULL); /* do the system call just once */
+
+ /* first check if it is time for a re-try */
+ if(ttNow > pThis->ttResumeRtry) {
+ iRet = pThis->pMod->tryResume(pThis->pModData);
+ if(iRet == RS_RET_SUSPENDED) {
+ /* set new tryResume time */
+ ++pThis->iNbrResRtry;
+ /* if we have more than 10 retries, we prolong the
+ * retry interval. If something is really stalled, it will
+ * get re-tried only very, very seldom - but that saves
+ * CPU time. TODO: maybe a config option for that?
+ * rgerhards, 2007-08-02
+ */
+ pThis->ttResumeRtry = ttNow + ACTION_RESUME_INTERVAL * (pThis->iNbrResRtry / 10 + 1);
+ }
+ } else {
+ /* it's too early, we are still suspended --> indicate this */
+ iRet = RS_RET_SUSPENDED;
+ }
+
+ if(iRet == RS_RET_OK)
+ actionResume(pThis);
+
+ dprintf("actionTryResume: iRet: %d, next retry (if applicable): %u [now %u]\n",
+ iRet, (unsigned) pThis->ttResumeRtry, (unsigned) ttNow);
+
+ return iRet;
+}
+
+
+/* debug-print the contents of an action object
+ * rgerhards, 2007-08-02
+ */
+rsRetVal actionDbgPrint(action_t *pThis)
+{
+ DEFiRet;
+
+ printf("%s: ", modGetStateName(pThis->pMod));
+ pThis->pMod->dbgPrintInstInfo(pThis->pModData);
+ printf("\n\tInstance data: 0x%x\n", (unsigned) pThis->pModData);
+ printf("\tRepeatedMsgReduction: %d\n", pThis->f_ReduceRepeated);
+ printf("\tSuspended: %d", pThis->bSuspended);
+ if(pThis->bSuspended) {
+ printf(" next retry: %u, number retries: %d", (unsigned) pThis->ttResumeRtry, pThis->iNbrResRtry);
+ }
+ printf("\n");
+ printf("\tDisabled: %d\n", !pThis->bEnabled);
+ printf("\tExec only when previous is suspended: %d\n", pThis->bExecWhenPrevSusp);
+ printf("\n");
+
+ return iRet;
+}
+
+
+/*
+ * vi:set ai:
+ */
diff --git a/action.h b/action.h
new file mode 100644
index 00000000..cda4130d
--- /dev/null
+++ b/action.h
@@ -0,0 +1,80 @@
+/* action.h
+ * Header file for the action object
+ *
+ * File begun on 2007-08-06 by RGerhards (extracted from syslogd.c)
+ *
+ * Copyright 2007 Rainer Gerhards and Adiscon GmbH.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * A copy of the GPL can be found in the file "COPYING" in this distribution.
+ */
+#ifndef ACTION_H_INCLUDED
+#define ACTION_H_INCLUDED 1
+
+#include "syslogd-types.h"
+
+/* the following struct defines the action object data structure
+ */
+struct action_s {
+ time_t f_time; /* time this was last written */
+ int bExecWhenPrevSusp;/* execute only when previous action is suspended? */
+ short bEnabled; /* is the related action enabled (1) or disabled (0)? */
+ short bSuspended; /* is the related action temporarily suspended? */
+ time_t ttResumeRtry; /* when is it time to retry the resume? */
+ int iNbrResRtry; /* number of retries since last suspend */
+ struct moduleInfo *pMod;/* pointer to output module handling this selector */
+ void *pModData; /* pointer to module data - contents is module-specific */
+ int f_ReduceRepeated;/* reduce repeated lines 0 - no, 1 - yes */
+ int f_prevcount; /* repetition cnt of prevline */
+ int f_repeatcount; /* number of "repeated" msgs */
+ int iNumTpls; /* number of array entries for template element below */
+ struct template **ppTpl;/* array of template to use - strings must be passed to doAction
+ * in this order. */
+
+ uchar **ppMsgs; /* array of message pointers for doAction */
+ struct msg* f_pMsg; /* pointer to the message (this will replace the other vars with msg
+ * content later). This is preserved after the message has been
+ * processed - it is also used to detect duplicates.
+ */
+};
+typedef struct action_s action_t;
+
+
+/* function prototypes
+ */
+rsRetVal actionConstruct(action_t **ppThis);
+rsRetVal actionDestruct(action_t *pThis);
+rsRetVal actionTryResume(action_t *pThis);
+rsRetVal actionSuspend(action_t *pThis);
+rsRetVal actionDbgPrint(action_t *pThis);
+
+#if 1
+#define actionIsSuspended(pThis) ((pThis)->bSuspended == 1)
+#else
+/* The function is a debugging aid */
+inline int actionIsSuspended(action_t *pThis)
+{
+ int i;
+ i = pThis->bSuspended == 1;
+ dprintf("in IsSuspend(), returns %d\n", i);
+ return i;
+}
+#endif
+
+#endif /* #ifndef ACTION_H_INCLUDED */
+/*
+ * vi:set ai:
+ */
diff --git a/syslogd.c b/syslogd.c
index 773f0c96..4c031ea7 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -210,6 +210,7 @@
#include "parse.h"
#include "msg.h"
#include "modules.h"
+#include "action.h"
#include "tcpsyslog.h"
#include "iminternal.h"
#include "cfsysline.h"
@@ -554,32 +555,6 @@ static int Initialized = 0; /* set when we have initialized ourselves
extern int errno;
-/* the following struct defines an syslogd-action descriptor
- */
-struct action_s {
- time_t f_time; /* time this was last written */
- int bExecWhenPrevSusp;/* execute only when previous action is suspended? */
- short bEnabled; /* is the related action enabled (1) or disabled (0)? */
- short bSuspended; /* is the related action temporarily suspended? */
- time_t ttResumeRtry; /* when is it time to retry the resume? */
- int iNbrResRtry; /* number of retries since last suspend */
- struct moduleInfo *pMod;/* pointer to output module handling this selector */
- void *pModData; /* pointer to module data - contents is module-specific */
- int f_ReduceRepeated;/* reduce repeated lines 0 - no, 1 - yes */
- int f_prevcount; /* repetition cnt of prevline */
- int f_repeatcount; /* number of "repeated" msgs */
- int iNumTpls; /* number of array entries for template element below */
- struct template **ppTpl;/* array of template to use - strings must be passed to doAction
- * in this order. */
-
- uchar **ppMsgs; /* array of message pointers for doAction */
- struct msg* f_pMsg; /* pointer to the message (this will replace the other vars with msg
- * content later). This is preserved after the message has been
- * processed - it is also used to detect duplicates.
- */
-};
-typedef struct action_s action_t;
-
/* This structure represents the files that will have log
* copies printed.
@@ -714,7 +689,6 @@ static void sighup_handler();
static void die(int sig);
static void freeSelectors(void);
static rsRetVal processConfFile(uchar *pConfFile);
-static rsRetVal actionDestruct(action_t *pThis);
static rsRetVal selectorAddList(selector_t *f);
static void processImInternal(void);
@@ -1852,156 +1826,6 @@ static int *create_udp_socket()
#endif
-/* destructs an action descriptor object
- * rgerhards, 2007-08-01
- */
-static rsRetVal actionDestruct(action_t *pThis)
-{
- assert(pThis != NULL);
-
- if(pThis->pMod != NULL)
- pThis->pMod->freeInstance(pThis->pModData);
-
- if(pThis->f_pMsg != NULL)
- MsgDestruct(pThis->f_pMsg);
-
- if(pThis->ppTpl != NULL)
- free(pThis->ppTpl);
- if(pThis->ppMsgs != NULL)
- free(pThis->ppMsgs);
- free(pThis);
-
- return RS_RET_OK;
-}
-
-
-/* create a new action descriptor object
- * rgerhards, 2007-08-01
- */
-static rsRetVal actionConstruct(action_t **ppThis)
-{
- DEFiRet;
- action_t *pThis;
-
- assert(ppThis != NULL);
-
- if((pThis = (action_t*) calloc(1, sizeof(action_t))) == NULL) {
- glblHadMemShortage = 1;
- ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
- }
-
-finalize_it:
- *ppThis = pThis;
- return iRet;
-}
-
-
-/* set an action back to active state -- rgerhards, 2007-08-02
- */
-static rsRetVal actionResume(action_t *pThis)
-{
- DEFiRet;
-
- assert(pThis != NULL);
- pThis->bSuspended = 0;
-
- return iRet;
-}
-
-
-#define ACTION_RESUME_INTERVAL 5 /* TODO: make this dynamic from conf file */
-/* suspend an action -- rgerhards, 2007-08-02
- */
-static rsRetVal actionSuspend(action_t *pThis)
-{
- DEFiRet;
-
- assert(pThis != NULL);
- pThis->bSuspended = 1;
- pThis->ttResumeRtry = time(NULL) + ACTION_RESUME_INTERVAL;
- pThis->iNbrResRtry = 0; /* tell that we did not yet retry to resume */
-
- return iRet;
-}
-
-#if 1
-#define actionIsSuspended(pThis) ((pThis)->bSuspended == 1)
-#else
-static int actionIsSuspended(action_t *pThis)
-{
- int i;
- i = pThis->bSuspended == 1;
- dprintf("in IsSuspend(), returns %d\n", i);
- return i;
-}
-#endif
-
-/* try to resume an action -- rgerhards, 2007-08-02
- * returns RS_RET_OK if resumption worked, RS_RET_SUSPEND if the
- * action is still suspended.
- */
-static rsRetVal actionTryResume(action_t *pThis)
-{
- DEFiRet;
- time_t ttNow;
-
- assert(pThis != NULL);
-
- ttNow = time(NULL); /* do the system call just once */
-
- /* first check if it is time for a re-try */
- if(ttNow > pThis->ttResumeRtry) {
- iRet = pThis->pMod->tryResume(pThis->pModData);
- if(iRet == RS_RET_SUSPENDED) {
- /* set new tryResume time */
- ++pThis->iNbrResRtry;
- /* if we have more than 10 retries, we prolong the
- * retry interval. If something is really stalled, it will
- * get re-tried only very, very seldom - but that saves
- * CPU time. TODO: maybe a config option for that?
- * rgerhards, 2007-08-02
- */
- pThis->ttResumeRtry = ttNow + ACTION_RESUME_INTERVAL * (pThis->iNbrResRtry / 10 + 1);
- }
- } else {
- /* it's too early, we are still suspended --> indicate this */
- iRet = RS_RET_SUSPENDED;
- }
-
- if(iRet == RS_RET_OK)
- actionResume(pThis);
-
- dprintf("actionTryResume: iRet: %d, next retry (if applicable): %u [now %u]\n",
- iRet, pThis->ttResumeRtry, (unsigned) ttNow);
-
- return iRet;
-}
-
-
-/* debug-print the contents of an action object
- * rgerhards, 2007-08-02
- */
-static rsRetVal actionDbgPrint(action_t *pThis)
-{
- DEFiRet;
-
- printf("%s: ", modGetStateName(pThis->pMod));
- pThis->pMod->dbgPrintInstInfo(pThis->pModData);
- printf("\n\tInstance data: 0x%x\n", (unsigned) pThis->pModData);
- printf("\tRepeatedMsgReduction: %d\n", pThis->f_ReduceRepeated);
- printf("\tSuspended: %d", pThis->bSuspended);
- if(pThis->bSuspended) {
- printf(" next retry: %u, number retries: %d", (unsigned) pThis->ttResumeRtry, pThis->iNbrResRtry);
- }
- printf("\n");
- printf("\tDisabled: %d\n", !pThis->bEnabled);
- printf("\tExec only when previous is suspended: %d\n", pThis->bExecWhenPrevSusp);
- printf("\n");
-
- return iRet;
-}
-
-
/* function to destruct a selector_t object
* rgerhards, 2007-08-01
*/
diff --git a/template.h b/template.h
index 95ffb221..bbd77090 100644
--- a/template.h
+++ b/template.h
@@ -78,6 +78,11 @@ void tplDeleteAll(void);
void tplDeleteNew(void);
void tplPrintList(void);
void tplLastStaticInit(struct template *tpl);
+/* note: if a compiler warning for undefined type tells you to look at this
+ * code line below, the actual cause is that you currently MUST include template.h
+ * BEFORE msg.h, even if your code file does not actually need it.
+ * rgerhards, 2007-08-06
+ */
uchar *tplToString(struct template *pTpl, msg_t *pMsg);
void doSQLEscape(char **pp, size_t *pLen, unsigned short *pbMustBeFreed, int escapeMode);