summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2007-07-26 12:07:23 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2007-07-26 12:07:23 +0000
commit54669873b0469aa69a4c9f88bcf88470218082f8 (patch)
tree1042b7096d3332dc92abbb8c4ee9fdc0af1f7e55
parent1904ce3f5aa11f190c881ccda650c1f464fe9271 (diff)
downloadrsyslog-54669873b0469aa69a4c9f88bcf88470218082f8.tar.gz
rsyslog-54669873b0469aa69a4c9f88bcf88470218082f8.tar.xz
rsyslog-54669873b0469aa69a4c9f88bcf88470218082f8.zip
- implemented needUDPSocket() interface
- replaced (mis) use of f_prevcount in omfwd.c -> now data element in instance data is used for retry counting - removed f->f_type from syslogd.c, omfwd.c - removed f->f_file from omfwd.c, omfile.c - f->f_flags is gone away
-rw-r--r--module-template.h32
-rw-r--r--modules.c4
-rw-r--r--modules.h1
-rw-r--r--omdiscard.c5
-rw-r--r--omfile.c80
-rw-r--r--omfwd.c82
-rw-r--r--ommysql.c7
-rw-r--r--omshell.c5
-rw-r--r--omusrmsg.c5
-rw-r--r--rsyslog.h3
-rw-r--r--syslogd-types.h5
-rw-r--r--syslogd.c21
12 files changed, 153 insertions, 97 deletions
diff --git a/module-template.h b/module-template.h
index 55b8f821..c8f1e79e 100644
--- a/module-template.h
+++ b/module-template.h
@@ -120,6 +120,27 @@ static rsRetVal dbgPrintInstInfo(selector_t *f, void *pModData)\
}
+/* needUDPSocket()
+ * Talks back to syslogd if the global UDP syslog socket is needed for
+ * sending. Returns 0 if not, 1 if needed. This interface hopefully goes
+ * away at some time, because it is kind of a hack. However, currently
+ * there is no way around it, so we need to support it.
+ * rgerhards, 2007-07-26
+ */
+#define BEGINneedUDPSocket \
+static rsRetVal needUDPSocket(void *pModData)\
+{\
+ rsRetVal iRet = RS_RET_FALSE;\
+ instanceData *pData = NULL;
+
+#define CODESTARTneedUDPSocket \
+ pData = (instanceData*) pModData;
+
+#define ENDneedUDPSocket \
+ return iRet;\
+}
+
+
/* onSelectReadyWrite()
* Extra comments:
* This is called when select() returned with a writable file descriptor
@@ -230,6 +251,8 @@ static rsRetVal queryEtryPt(uchar *name, rsRetVal (**pEtryPoint)())\
*pEtryPoint = getWriteFDForSelect;\
} else if(!strcmp((char*) name, "onSelectReadyWrite")) {\
*pEtryPoint = onSelectReadyWrite;\
+ } else if(!strcmp((char*) name, "needUDPSocket")) {\
+ *pEtryPoint = needUDPSocket;\
}
/* modInit()
@@ -261,15 +284,6 @@ rsRetVal modInit##uniqName(int iIFVersRequested __attribute__((unused)), int *ip
return iRet;\
}
-/*
- */
-#define BEGIN \
-
-#define CODESTART \
-
-#define END \
-
-
#endif /* #ifndef MODULE_TEMPLATE_H_INCLUDED */
/*
* vi:set ai:
diff --git a/modules.c b/modules.c
index 067a7531..ec18d4cb 100644
--- a/modules.c
+++ b/modules.c
@@ -188,6 +188,10 @@ rsRetVal doModInit(rsRetVal (*modInit)(int, int*, rsRetVal(**)()), uchar *name)
moduleDestruct(pNew);
return iRet;
}
+ if((iRet = (*pNew->modQueryEtryPt)((uchar*)"needUDPSocket", &pNew->needUDPSocket)) != RS_RET_OK) {
+ moduleDestruct(pNew);
+ return iRet;
+ }
if((iRet = (*pNew->modQueryEtryPt)((uchar*)"freeInstance", &pNew->freeInstance)) != RS_RET_OK) {
moduleDestruct(pNew);
return iRet;
diff --git a/modules.h b/modules.h
index b2d040de..f78b1714 100644
--- a/modules.h
+++ b/modules.h
@@ -57,6 +57,7 @@ typedef struct moduleInfo {
rsRetVal (*freeInstance)(struct filed*, void*);/* called before termination or module unload */
rsRetVal (*getWriteFDForSelect)(struct filed*, void*,short *);/* called before termination or module unload */
rsRetVal (*onSelectReadyWrite)(struct filed*, void*);/* called when fd is writeable after select() */
+ rsRetVal (*needUDPSocket)(void*);/* called when fd is writeable after select() */
rsRetVal (*dbgPrintInstInfo)(struct filed*, void*);/* called before termination or module unload */
rsRetVal (*modExit)(); /* called before termination or module unload */
/* below: parse a configuration line - return if processed
diff --git a/omdiscard.c b/omdiscard.c
index b12474c5..54eab33d 100644
--- a/omdiscard.c
+++ b/omdiscard.c
@@ -88,6 +88,11 @@ CODESTARTparseSelectorAct
ENDparseSelectorAct
+BEGINneedUDPSocket
+CODESTARTneedUDPSocket
+ENDneedUDPSocket
+
+
BEGINonSelectReadyWrite
CODESTARTonSelectReadyWrite
ENDonSelectReadyWrite
diff --git a/omfile.c b/omfile.c
index 40885dac..9fbc44cd 100644
--- a/omfile.c
+++ b/omfile.c
@@ -55,6 +55,7 @@
*/
typedef struct _instanceData {
char f_fname[MAXFNAME];/* file or template name (display only) */
+ short fd; /* file descriptor for (current) file */
enum {
eTypeFILE,
eTypeTTY,
@@ -66,6 +67,7 @@ typedef struct _instanceData {
int fCreateMode; /* file creation mode for open() */
int fDirCreateMode; /* creation mode for mkdir() */
int bCreateDirs; /* auto-create directories? */
+ int bSyncFile; /* should the file by sync()'ed? 1- yes, 0- no */
uid_t fileUID; /* IDs for creation */
uid_t dirUID;
gid_t fileGID;
@@ -109,7 +111,7 @@ CODESTARTdbgPrintInstInfo
);
} else { /* regular file */
printf("%s", pData->f_fname);
- if (f->f_file == -1)
+ if (pData->fd == -1)
printf(" (unused)");
}
ENDdbgPrintInstInfo
@@ -208,7 +210,7 @@ static rsRetVal cflineParseOutchannel(selector_t *f, instanceData *pData, uchar*
* returns 0 if ok, 1 otherwise
* TODO: consider moving the initial check in here, too
*/
-int resolveFileSizeLimit(selector_t *f, instanceData *pData)
+int resolveFileSizeLimit(instanceData *pData)
{
uchar *pParams;
uchar *pCmd;
@@ -246,10 +248,10 @@ int resolveFileSizeLimit(selector_t *f, instanceData *pData)
execProg(pCmd, 1, pParams);
- f->f_file = open(pData->f_fname, O_WRONLY|O_APPEND|O_CREAT|O_NOCTTY,
+ pData->fd = open(pData->f_fname, O_WRONLY|O_APPEND|O_CREAT|O_NOCTTY,
pData->fCreateMode);
- actualFileSize = lseek(f->f_file, 0, SEEK_END);
+ actualFileSize = lseek(pData->fd, 0, SEEK_END);
if(actualFileSize >= pData->f_sizeLimit) {
/* OK, it didn't work out... */
return 1;
@@ -311,7 +313,7 @@ static void dynaFileFreeCache(instanceData *pData)
* based on the current message, checks if that file is already open
* and, if not, does everything needed to switch to the new one.
* Function returns 0 if all went well and non-zero otherwise.
- * On successful return f->f_file must point to the correct file to
+ * On successful return pData->fd must point to the correct file to
* be written.
* This is a helper to writeFile(). rgerhards, 2007-07-03
*/
@@ -362,7 +364,7 @@ static int prepareDynFile(selector_t *f, instanceData *pData)
} else { /* got an element, let's see if it matches */
if(!strcmp((char*) newFileName, (char*) pCache[i]->pName)) {
/* we found our element! */
- f->f_file = pCache[i]->fd;
+ pData->fd = pCache[i]->fd;
pData->iCurrElt = i;
free(newFileName);
pCache[i]->lastUsed = time(NULL); /* update timestamp for LRU */
@@ -399,7 +401,7 @@ static int prepareDynFile(selector_t *f, instanceData *pData)
/* Ok, we finally can open the file */
if(access((char*)newFileName, F_OK) == 0) {
/* file already exists */
- f->f_file = open((char*) newFileName, O_WRONLY|O_APPEND|O_CREAT|O_NOCTTY,
+ pData->fd = open((char*) newFileName, O_WRONLY|O_APPEND|O_CREAT|O_NOCTTY,
pData->fCreateMode);
} else {
/* file does not exist, create it (and eventually parent directories */
@@ -411,18 +413,18 @@ static int prepareDynFile(selector_t *f, instanceData *pData)
if(makeFileParentDirs(newFileName, strlen((char*)newFileName),
pData->fDirCreateMode, pData->dirUID,
pData->dirGID, pData->bFailOnChown) == 0) {
- f->f_file = open((char*) newFileName, O_WRONLY|O_APPEND|O_CREAT|O_NOCTTY,
+ pData->fd = open((char*) newFileName, O_WRONLY|O_APPEND|O_CREAT|O_NOCTTY,
pData->fCreateMode);
- if(f->f_file != -1) {
+ if(pData->fd != -1) {
/* check and set uid/gid */
if(pData->fileUID != (uid_t)-1 || pData->fileGID != (gid_t) -1) {
/* we need to set owner/group */
- if(fchown(f->f_file, pData->fileUID,
+ if(fchown(pData->fd, pData->fileUID,
pData->fileGID) != 0) {
if(pData->bFailOnChown) {
int eSave = errno;
- close(f->f_file);
- f->f_file = -1;
+ close(pData->fd);
+ pData->fd = -1;
errno = eSave;
}
/* we will silently ignore the chown() failure
@@ -436,7 +438,7 @@ static int prepareDynFile(selector_t *f, instanceData *pData)
}
/* file is either open now or an error state set */
- if(f->f_file == -1) {
+ if(pData->fd == -1) {
/* do not report anything if the message is an internally-generated
* message. Otherwise, we could run into a never-ending loop. The bad
* news is that we also lose errors on startup messages, but so it is.
@@ -450,7 +452,7 @@ static int prepareDynFile(selector_t *f, instanceData *pData)
return -1;
}
- pCache[iFirstFree]->fd = f->f_file;
+ pCache[iFirstFree]->fd = pData->fd;
pCache[iFirstFree]->pName = newFileName;
pCache[iFirstFree]->lastUsed = time(NULL);
pData->iCurrElt = iFirstFree;
@@ -488,16 +490,16 @@ again:
* obey to it.
*/
if(pData->f_sizeLimit != 0) {
- actualFileSize = lseek(f->f_file, 0, SEEK_END);
+ actualFileSize = lseek(pData->fd, 0, SEEK_END);
if(actualFileSize >= pData->f_sizeLimit) {
char errMsg[256];
/* for now, we simply disable a file once it is
* beyond the maximum size. This is better than having
* us aborted by the OS... rgerhards 2005-06-21
*/
- (void) close(f->f_file);
+ (void) close(pData->fd);
/* try to resolve the situation */
- if(resolveFileSizeLimit(f, pData) != 0) {
+ if(resolveFileSizeLimit(pData) != 0) {
/* didn't work out, so disable... */
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",
@@ -515,7 +517,7 @@ again:
}
}
- if (writev(f->f_file, f->f_iov, f->f_iIovUsed) < 0) {
+ if (writev(pData->fd, f->f_iov, f->f_iIovUsed) < 0) {
int e = errno;
/* If a named pipe is full, just ignore it for now
@@ -530,7 +532,7 @@ again:
if (pData->fileType == eTypeFILE && e == ENOSPC)
return RS_RET_OK;
- (void) close(f->f_file);
+ (void) close(pData->fd);
/*
* Check for EBADF on TTY's due to vhangup()
* Linux uses EIO instead (mrn 12 May 96)
@@ -541,8 +543,8 @@ again:
#else
&& e == EBADF) {
#endif
- f->f_file = open(pData->f_fname, O_WRONLY|O_APPEND|O_NOCTTY);
- if (f->f_file < 0) {
+ pData->fd = open(pData->f_fname, O_WRONLY|O_APPEND|O_NOCTTY);
+ if (pData->fd < 0) {
iRet = RS_RET_DISABLE_ACTION;
logerror(pData->f_fname);
} else {
@@ -554,8 +556,8 @@ again:
errno = e;
logerror(pData->f_fname);
}
- } else if (f->f_flags & SYNC_FILE)
- fsync(f->f_file);
+ } else if (pData->bSyncFile)
+ fsync(pData->fd);
return(iRet);
}
@@ -570,7 +572,7 @@ CODESTARTfreeInstance
if(pData->bDynamicName) {
dynaFileFreeCache(pData);
} else
- close(f->f_file);
+ close(pData->fd);
ENDfreeInstance
@@ -579,6 +581,11 @@ CODESTARTonSelectReadyWrite
ENDonSelectReadyWrite
+BEGINneedUDPSocket
+CODESTARTneedUDPSocket
+ENDneedUDPSocket
+
+
BEGINgetWriteFDForSelect
CODESTARTgetWriteFDForSelect
ENDgetWriteFDForSelect
@@ -587,17 +594,16 @@ ENDgetWriteFDForSelect
BEGINdoAction
CODESTARTdoAction
dprintf(" (%s)\n", pData->f_fname);
- /* f->f_file == -1 is an indicator that the we couldn't
+ /* pData->fd == -1 is an indicator that the we couldn't
* open the file at startup. For dynaFiles, this is ok,
* all others are doomed.
*/
- if(pData->bDynamicName || (f->f_file != -1))
+ if(pData->bDynamicName || (pData->fd != -1))
iRet = writeFile(f, pData);
ENDdoAction
BEGINparseSelectorAct
- int syncfile;
CODESTARTparseSelectorAct
/* yes, the if below is redundant, but I need it now. Will go away as
* the code further changes. -- rgerhards, 2007-07-25
@@ -615,10 +621,10 @@ dprintf("parseSelActFile 1\n");
dprintf("parseSelActFile 2\n");
if (*p == '-') {
- syncfile = 0;
+ pData->bSyncFile = 0;
p++;
} else
- syncfile = 1;
+ pData->bSyncFile = 1;
pData->f_sizeLimit = 0; /* default value, use outchannels to configure! */
@@ -636,7 +642,7 @@ dprintf("parseSelActFile 2\n");
pData->bDynamicName = 0;
pData->fCreateMode = fCreateMode; /* preserve current setting */
pData->fDirCreateMode = fDirCreateMode; /* preserve current setting */
- f->f_file = open(pData->f_fname, O_WRONLY|O_APPEND|O_CREAT|O_NOCTTY,
+ pData->fd = open(pData->f_fname, O_WRONLY|O_APPEND|O_CREAT|O_NOCTTY,
pData->fCreateMode);
}
break;
@@ -655,8 +661,6 @@ dprintf("parseSelActFile 2\n");
break;
}
- if(syncfile)
- f->f_flags |= SYNC_FILE;
pData->bDynamicName = 1;
pData->iCurrElt = -1; /* no current element */
pData->fCreateMode = fCreateMode; /* freeze current setting */
@@ -695,24 +699,22 @@ dprintf("parseSelActFile 2\n");
if((iRet = cflineParseFileName(f, p, (uchar*) pData->f_fname)) != RS_RET_OK)
break;
- if(syncfile)
- f->f_flags |= SYNC_FILE;
pData->bDynamicName = 0;
pData->fCreateMode = fCreateMode; /* preserve current setting */
if(pData->fileType == eTypePIPE) {
- f->f_file = open(pData->f_fname, O_RDWR|O_NONBLOCK);
+ pData->fd = open(pData->f_fname, O_RDWR|O_NONBLOCK);
} else {
- f->f_file = open(pData->f_fname, O_WRONLY|O_APPEND|O_CREAT|O_NOCTTY,
+ pData->fd = open(pData->f_fname, O_WRONLY|O_APPEND|O_CREAT|O_NOCTTY,
pData->fCreateMode);
}
- if ( f->f_file < 0 ){
- f->f_file = -1;
+ if ( pData->fd < 0 ){
+ pData->fd = -1;
dprintf("Error opening log file: %s\n", pData->f_fname);
logerror(pData->f_fname);
break;
}
- if (isatty(f->f_file)) {
+ if (isatty(pData->fd)) {
pData->fileType = eTypeTTY;
untty();
}
diff --git a/omfwd.c b/omfwd.c
index 43309a10..4761b804 100644
--- a/omfwd.c
+++ b/omfwd.c
@@ -71,9 +71,15 @@ static const char *sys_h_errlist[] = {
/* internal structures
*/
-
typedef struct _instanceData {
char f_hname[MAXHOSTNAMELEN+1];
+ short sock; /* file descriptor */
+ enum { /* TODO: we shoud revisit these definitions */
+ eDestFORW,
+ eDestFORW_SUSP,
+ eDestFORW_UNKN
+ } eDestState;
+ int iRtryCnt;
struct addrinfo *f_addr;
int compressionLevel; /* 0 - no compression, else level for zlib */
char *port;
@@ -110,12 +116,12 @@ ENDisCompatibleWithFeature
BEGINfreeInstance
CODESTARTfreeInstance
- switch (f->f_type) {
- case F_FORW:
- case F_FORW_SUSP:
+ switch (pData->eDestState) {
+ case eDestFORW:
+ case eDestFORW_SUSP:
freeaddrinfo(pData->f_addr);
/* fall through */
- case F_FORW_UNKN:
+ case eDestFORW_UNKN:
if(pData->port != NULL)
free(pData->port);
break;
@@ -296,9 +302,9 @@ static int TCPSend(selector_t *f, instanceData *pData, char *msg, size_t len)
framingToUse = bIsCompressed ? TCP_FRAMING_OCTET_COUNTING : pData->tcp_framing;
do { /* try to send message */
- if(f->f_file <= 0) {
+ if(pData->sock <= 0) {
/* we need to open the socket first */
- if((f->f_file = TCPSendCreateSocket(pData, pData->f_addr)) <= 0) {
+ if((pData->sock = TCPSendCreateSocket(pData, pData->f_addr)) <= 0) {
return -1;
}
}
@@ -432,7 +438,7 @@ static int TCPSend(selector_t *f, instanceData *pData, char *msg, size_t len)
/* frame building complete, on to actual sending */
- lenSend = send(f->f_file, msg, len, 0);
+ lenSend = send(pData->sock, msg, len, 0);
dprintf("TCP sent %d bytes, requested %d, msg: '%s'\n", lenSend, len,
bIsCompressed ? "***compressed***" : msg);
if((unsigned)lenSend == len) {
@@ -485,9 +491,9 @@ static int TCPSend(selector_t *f, instanceData *pData, char *msg, size_t len)
if(retry == 0) {
++retry;
/* try to recover */
- close(f->f_file);
+ close(pData->sock);
TCPSendSetStatus(pData, TCP_SEND_NOTCONNECTED);
- f->f_file = -1;
+ pData->sock = -1;
} else {
if(buf != NULL)
free(buf);
@@ -527,12 +533,12 @@ BEGINdoAction
struct addrinfo *res, *r;
struct addrinfo hints;
CODESTARTdoAction
- switch (f->f_type) {
- case F_FORW_SUSP:
+ switch (pData->eDestState) {
+ case eDestFORW_SUSP:
fwd_suspend = time(NULL) - pData->ttSuspend;
if ( fwd_suspend >= INET_SUSPEND_TIME ) {
dprintf("\nForwarding suspension over, retrying FORW ");
- f->f_type = F_FORW;
+ pData->eDestState = eDestFORW;
goto f_forw;
}
else {
@@ -549,7 +555,7 @@ CODESTARTdoAction
* need for resolving the address is on the same machine, but
* is started after syslogd.
*/
- case F_FORW_UNKN:
+ case eDestFORW_UNKN:
/* The remote address is not yet known and needs to be obtained */
dprintf(" %s\n", pData->f_hname);
fwd_suspend = time(NULL) - pData->ttSuspend;
@@ -566,19 +572,19 @@ CODESTARTdoAction
if((e = getaddrinfo(pData->f_hname,
getFwdSyslogPt(pData), &hints, &res)) != 0) {
dprintf("Failure: %s\n", sys_h_errlist[h_errno]);
- dprintf("Retries: %d\n", f->f_prevcount);
- if ( --f->f_prevcount < 0 ) {
+ dprintf("Retries: %d\n", pData->iRtryCnt);
+ if ( --pData->iRtryCnt < 0 ) {
dprintf("Giving up.\n");
iRet = RS_RET_DISABLE_ACTION;
}
else
- dprintf("Left retries: %d\n", f->f_prevcount);
+ dprintf("Left retries: %d\n", pData->iRtryCnt);
}
else {
dprintf("%s found, resuming.\n", pData->f_hname);
pData->f_addr = res;
- f->f_prevcount = 0;
- f->f_type = F_FORW;
+ pData->iRtryCnt = 0;
+ pData->eDestState = eDestFORW;
goto f_forw;
}
}
@@ -587,7 +593,7 @@ CODESTARTdoAction
"left: %d\n", INET_SUSPEND_TIME - fwd_suspend);
break;
- case F_FORW:
+ case eDestFORW:
f_forw:
dprintf(" %s:%s/%s\n", pData->f_hname, getFwdSyslogPt(pData),
pData->protocol == FORW_UDP ? "udp" : "tcp");
@@ -668,7 +674,7 @@ CODESTARTdoAction
}
/* finished looping */
if (bSendSuccess == FALSE) {
- f->f_type = F_FORW_SUSP;
+ pData->eDestState = eDestFORW_SUSP;
errno = 0;
logerror("error forwarding via udp, suspending");
}
@@ -677,7 +683,7 @@ CODESTARTdoAction
/* forward via TCP */
if(TCPSend(f, pData, psz, l) != 0) {
/* error! */
- f->f_type = F_FORW_SUSP;
+ pData->eDestState = eDestFORW_SUSP;
errno = 0;
logerror("error forwarding via tcp, suspending...");
}
@@ -685,6 +691,16 @@ CODESTARTdoAction
}
break;
}
+
+ if(pData->eDestState != eDestFORW) {
+ /* TODO: think somewhat more about this code at the end of modularization. I think
+ * it is clean right now, but we could build a better interface for suspension. I
+ * think we will naturally re-visit this when we implement global suspension and
+ * queueing - I anticipate that the whole FORW_SUSP/FORW_UNKN goes away by then.
+ * rgerhards, 2007-07-26
+ */
+ iRet = RS_RET_SUSPENDED;
+ }
ENDdoAction
@@ -825,7 +841,7 @@ CODESTARTparseSelectorAct
strcpy(szTemplateName, " StdFwdFmt");
}
- /* first set the f->f_type */
+ /* first set the pData->eDestState */
strcpy(pData->f_hname, (char*) q);
memset(&hints, 0, sizeof(hints));
/* port must be numeric, because config file syntax requests this */
@@ -833,11 +849,11 @@ CODESTARTparseSelectorAct
hints.ai_family = family;
hints.ai_socktype = pData->protocol == FORW_UDP ? SOCK_DGRAM : SOCK_STREAM;
if( (error = getaddrinfo(pData->f_hname, getFwdSyslogPt(pData), &hints, &res)) != 0) {
- f->f_type = F_FORW_UNKN;
- f->f_prevcount = INET_RETRY_MAX;
+ pData->eDestState = eDestFORW_UNKN;
+ pData->iRtryCnt = INET_RETRY_MAX;
pData->ttSuspend = time(NULL);
} else {
- f->f_type = F_FORW;
+ pData->eDestState = eDestFORW;
pData->f_addr = res;
}
@@ -863,16 +879,22 @@ CODESTARTparseSelectorAct
ENDparseSelectorAct
+BEGINneedUDPSocket
+CODESTARTneedUDPSocket
+ iRet = RS_RET_TRUE;
+ENDneedUDPSocket
+
+
BEGINonSelectReadyWrite
CODESTARTonSelectReadyWrite
- dprintf("tcp send socket %d ready for writing.\n", f->f_file);
+ dprintf("tcp send socket %d ready for writing.\n", pData->sock);
TCPSendSetStatus(pData, TCP_SEND_READY);
/* Send stored message (if any) */
if(pData->savedMsg != NULL) {
if(TCPSend(f, pData, pData->savedMsg,
pData->savedMsgLen) != 0) {
/* error! */
- f->f_type = F_FORW_SUSP;
+ pData->eDestState = eDestFORW_SUSP;
errno = 0;
logerror("error forwarding via tcp, suspending...");
}
@@ -884,10 +906,10 @@ ENDonSelectReadyWrite
BEGINgetWriteFDForSelect
CODESTARTgetWriteFDForSelect
- if( (f->f_type == F_FORW)
+ if( (pData->eDestState == eDestFORW)
&& (pData->protocol == FORW_TCP)
&& TCPSendGetStatus(pData) == TCP_SEND_CONNECTING) {
- *fd = f->f_file;
+ *fd = pData->sock;
iRet = RS_RET_OK;
}
ENDgetWriteFDForSelect
diff --git a/ommysql.c b/ommysql.c
index 0dac4b77..b23c4a39 100644
--- a/ommysql.c
+++ b/ommysql.c
@@ -95,6 +95,11 @@ CODESTARTfreeInstance
ENDfreeInstance
+BEGINneedUDPSocket
+CODESTARTneedUDPSocket
+ENDneedUDPSocket
+
+
BEGINdbgPrintInstInfo
CODESTARTdbgPrintInstInfo
/* nothing special here */
@@ -182,7 +187,7 @@ rsRetVal checkDBErrorState(instanceData *pData)
{
time_t now;
assert(pData != NULL);
- /* dprintf("in checkDBErrorState, timeResumeOnError: %d\n", f->f_timeResumeOnError); */
+ /* dprintf("in checkDBErrorState, timeResumeOnError: %d\n", pData->f_timeResumeOnError); */
/* If timeResumeOnError == 0 no error occured,
we can return with 0 (no error) */
diff --git a/omshell.c b/omshell.c
index b1a77aca..62a83c8c 100644
--- a/omshell.c
+++ b/omshell.c
@@ -116,6 +116,11 @@ CODESTARTparseSelectorAct
ENDparseSelectorAct
+BEGINneedUDPSocket
+CODESTARTneedUDPSocket
+ENDneedUDPSocket
+
+
BEGINonSelectReadyWrite
CODESTARTonSelectReadyWrite
ENDonSelectReadyWrite
diff --git a/omusrmsg.c b/omusrmsg.c
index 82f23af2..b031bb68 100644
--- a/omusrmsg.c
+++ b/omusrmsg.c
@@ -81,6 +81,11 @@ CODESTARTfreeInstance
ENDfreeInstance
+BEGINneedUDPSocket
+CODESTARTneedUDPSocket
+ENDneedUDPSocket
+
+
BEGINdbgPrintInstInfo
register int i;
CODESTARTdbgPrintInstInfo
diff --git a/rsyslog.h b/rsyslog.h
index 5b7d8c34..560e0f10 100644
--- a/rsyslog.h
+++ b/rsyslog.h
@@ -36,6 +36,8 @@ enum rsRetVal_ /** return value. All methods return this if not specified oth
{
RS_RET_OUT_OF_MEMORY = -6, /**< memory allocation failed */
RS_RET_PROVIDED_BUFFER_TOO_SMALL = -50,/**< the caller provided a buffer, but the called function sees the size of this buffer is too small - operation not carried out */
+ RS_RET_TRUE = -1,
+ RS_RET_FALSE = -2,
RS_RET_ERR = -3000, /**< generic failure */
RS_TRUNCAT_TOO_LARGE = -3001, /**< truncation operation where too many chars should be truncated */
RS_RET_FOUND_AT_STRING_END = -3002, /**< some value found, but at the last pos of string */
@@ -55,6 +57,7 @@ enum rsRetVal_ /** return value. All methods return this if not specified oth
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_SUSPENDED = -2007, /**< something was suspended, not neccesarily an error */
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 ef333b3d..f986cb33 100644
--- a/syslogd-types.h
+++ b/syslogd-types.h
@@ -114,8 +114,6 @@ struct syslogTime {
};
-/* values for f_type in struct filed below*/
-
/* This structure represents the files that will have log
* copies printed.
* RGerhards 2004-11-08: Each instance of the filed structure
@@ -130,8 +128,6 @@ struct syslogTime {
*/
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 */
@@ -162,7 +158,6 @@ struct filed {
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 f_flags; /* store some additional flags */
struct template *f_pTpl; /* pointer to template to use */
struct iovec *f_iov; /* dyn allocated depinding on template */
unsigned short *f_bMustBeFreed; /* indicator, if iov_base must be freed to destruct */
diff --git a/syslogd.c b/syslogd.c
index 57932485..c6ee316e 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -3262,8 +3262,8 @@ rsRetVal fprintlog(register selector_t *f)
if(iRet == RS_RET_DISABLE_ACTION)
f->bEnabled = 0; /* that's it... */
- if (f->f_type != F_FORW_UNKN)
- f->f_prevcount = 0;
+ if(iRet == RS_RET_OK)
+ f->f_prevcount = 0; /* message process, so we start a new cycle */
if(pMsgSave != NULL) {
/* we had saved the original message pointer. That was
@@ -4038,14 +4038,13 @@ static void freeSelectors(void)
f = Files;
while (f != NULL) {
/* flush any pending output */
- /* TODO: the output module must handle this internally in the
- * future - implement it when moving f_type out of selector_t
- * rgerhards, 2007-07-24
- */
- if(f->f_type != F_FORW_UNKN && f->f_prevcount) {
+ if(f->f_prevcount) {
fprintlog(f);
}
+ /* free the action instances */
+ f->pMod->freeInstance(f, f->pModData);
+
/* free iovec if it was allocated */
if(f->f_iov != NULL) {
if(f->f_bMustBeFreed != NULL) {
@@ -4059,9 +4058,6 @@ static void freeSelectors(void)
if (f->f_psziov != NULL)
free(f->f_psziov);
- /* free the action instances */
- f->pMod->freeInstance(f, f->pModData);
-
if(f->f_pMsg != NULL)
MsgDestruct(f->f_pMsg);
/* done with this entry, we now need to delete itself */
@@ -4247,7 +4243,7 @@ static void init()
nextp->f_next = f;
}
nextp = f;
- if (f->f_type == F_FORW || f->f_type == F_FORW_SUSP || f->f_type == F_FORW_UNKN) {
+ if(f->pMod->needUDPSocket(f->pModData) == RS_RET_TRUE) {
Forwarding++;
}
}
@@ -4560,7 +4556,6 @@ static rsRetVal cflineProcessTradPRIFilter(uchar **pline, register selector_t *f
*/
for (i = 0; i <= LOG_NFACILITIES; i++) {
f->f_filterData.f_pmask[i] = TABLE_NOPRI;
- f->f_flags = 0;
}
/* scan through the list of selectors */
@@ -5368,7 +5363,7 @@ static void mainloop(void)
rsRetVal iRet;
for (f = Files; f != NULL ; f = f->f_next) {
if(f->pMod->getWriteFDForSelect(f, f->pModData, &fdMod) == RS_RET_OK) {
- if(FD_ISSET(f->f_file, &writefds)) {
+ if(FD_ISSET(fdMod, &writefds)) {
if((iRet = f->pMod->onSelectReadyWrite(f, f->pModData)) != RS_RET_OK) {
dprintf("error %d from onSelectReadyWrite() - continuing\n", iRet);
}