mirror of
https://github.com/rsyslog/rsyslog.git
synced 2025-12-19 15:00:43 +01:00
- added doGetInt() to cfsysline.c and adapted dynaFileChaceSize handler to
use it
This commit is contained in:
parent
c135ef6de2
commit
e123f620d3
57
cfsysline.c
57
cfsysline.c
@ -28,6 +28,7 @@
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
|
||||
@ -50,10 +51,9 @@ cslCmd_t *pCmdListLast = NULL;
|
||||
* HINT: check if char is ' and, if so, use 'c' where c may also be things
|
||||
* like \t etc.
|
||||
*/
|
||||
//static void doControlCharEscPrefix(uchar **pp)
|
||||
rsRetVal doGetChar(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal)
|
||||
{
|
||||
rsRetVal iRet = RS_RET_OK;
|
||||
DEFiRet;
|
||||
|
||||
assert(pp != NULL);
|
||||
assert(*pp != NULL);
|
||||
@ -80,6 +80,47 @@ finalize_it:
|
||||
}
|
||||
|
||||
|
||||
/* Parse a number from the configuration line.
|
||||
* rgerhards, 2007-07-31
|
||||
*/
|
||||
rsRetVal doGetInt(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal)
|
||||
{
|
||||
uchar *p;
|
||||
DEFiRet;
|
||||
int i;
|
||||
|
||||
assert(pp != NULL);
|
||||
assert(*pp != NULL);
|
||||
|
||||
skipWhiteSpace(pp); /* skip over any whitespace */
|
||||
p = *pp;
|
||||
|
||||
if(!isdigit((int) *p)) {
|
||||
errno = 0;
|
||||
logerror("invalid number");
|
||||
iRet = RS_RET_INVALID_INT;
|
||||
goto finalize_it;
|
||||
}
|
||||
|
||||
/* pull value */
|
||||
for(i = 0 ; *p && isdigit((int) *p) ; ++p)
|
||||
i = i * 10 + *p - '0';
|
||||
|
||||
if(pSetHdlr == NULL) {
|
||||
/* we should set value directly to var */
|
||||
*((int*)pVal) = i;
|
||||
} else {
|
||||
/* we set value via a set function */
|
||||
CHKiRet(pSetHdlr(pVal, i));
|
||||
}
|
||||
|
||||
*pp = p;
|
||||
|
||||
finalize_it:
|
||||
return iRet;
|
||||
}
|
||||
|
||||
|
||||
/* Parse and interpet a $FileCreateMode and $umask line. This function
|
||||
* pulls the creation mode and, if successful, stores it
|
||||
* into the global variable so that the rest of rsyslogd
|
||||
@ -95,7 +136,7 @@ finalize_it:
|
||||
rsRetVal doFileCreateMode(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal)
|
||||
{
|
||||
uchar *p;
|
||||
rsRetVal iRet = RS_RET_OK;
|
||||
DEFiRet;
|
||||
uchar errMsg[128]; /* for dynamic error messages */
|
||||
int iVal;
|
||||
|
||||
@ -184,7 +225,7 @@ rsRetVal doGetGID(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal)
|
||||
{
|
||||
struct group *pgBuf;
|
||||
struct group gBuf;
|
||||
rsRetVal iRet = RS_RET_OK;
|
||||
DEFiRet;
|
||||
uchar szName[256];
|
||||
char stringBuf[2048]; /* I hope this is large enough... */
|
||||
|
||||
@ -227,7 +268,7 @@ rsRetVal doGetUID(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal)
|
||||
{
|
||||
struct passwd *ppwBuf;
|
||||
struct passwd pwBuf;
|
||||
rsRetVal iRet = RS_RET_OK;
|
||||
DEFiRet;
|
||||
uchar szName[256];
|
||||
char stringBuf[2048]; /* I hope this is large enough... */
|
||||
|
||||
@ -271,7 +312,7 @@ finalize_it:
|
||||
rsRetVal doBinaryOptionLine(uchar **pp, rsRetVal (*pSetHdlr)(void*, int), void *pVal)
|
||||
{
|
||||
int iOption;
|
||||
rsRetVal iRet = RS_RET_OK;
|
||||
DEFiRet;
|
||||
|
||||
assert(pp != NULL);
|
||||
assert(*pp != NULL);
|
||||
@ -312,7 +353,7 @@ rsRetVal cslchDestruct(cslCmdHdlr_t *pThis)
|
||||
rsRetVal cslchConstruct(cslCmdHdlr_t **ppThis)
|
||||
{
|
||||
cslCmdHdlr_t *pThis;
|
||||
rsRetVal iRet = RS_RET_OK;
|
||||
DEFiRet;
|
||||
|
||||
assert(ppThis != NULL);
|
||||
if((pThis = calloc(1, sizeof(cslCmdHdlr_t))) == NULL) {
|
||||
@ -380,7 +421,7 @@ rsRetVal cslcDestruct(cslCmd_t *pThis)
|
||||
rsRetVal cslcConstruct(cslCmd_t **ppThis)
|
||||
{
|
||||
cslCmd_t *pThis;
|
||||
rsRetVal iRet = RS_RET_OK;
|
||||
DEFiRet;
|
||||
|
||||
assert(ppThis != NULL);
|
||||
if((pThis = calloc(1, sizeof(cslCmd_t))) == NULL) {
|
||||
|
||||
@ -31,6 +31,7 @@ typedef enum cslCmdHdlrType {
|
||||
eCmdHdlrGUID,
|
||||
eCmdHdlrBinary,
|
||||
eCmdHdlrFileCreateMode,
|
||||
eCmdHdlrInt,
|
||||
eCmdHdlrFileGetChar
|
||||
} ecslCmdHdrlType;
|
||||
|
||||
@ -71,5 +72,6 @@ rsRetVal doGetUID(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal);
|
||||
rsRetVal doGetGID(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal);
|
||||
rsRetVal doFileCreateMode(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal);
|
||||
rsRetVal doGetChar(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal);
|
||||
rsRetVal doGetInt(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal);
|
||||
|
||||
#endif /* #ifndef CFSYSLINE_H_INCLUDED */
|
||||
|
||||
@ -60,6 +60,8 @@ enum rsRetVal_ /** return value. All methods return this if not specified oth
|
||||
RS_RET_SUSPENDED = -2007, /**< something was suspended, not neccesarily an error */
|
||||
RS_RET_RQD_TPLOPT_MISSING = -2008,/**< a required template option is missing */
|
||||
RS_RET_INVALID_VALUE = -2009,/**< some value is invalid (e.g. user-supplied data) */
|
||||
RS_RET_INVALID_INT = -2010,/**< invalid integer */
|
||||
RS_RET_VAL_OUT_OF_RANGE = -2011, /**< value out of range */
|
||||
RS_RET_OK = 0 /**< operation successful */
|
||||
};
|
||||
typedef enum rsRetVal_ rsRetVal; /**< friendly type for global return value */
|
||||
@ -69,6 +71,7 @@ typedef enum rsRetVal_ rsRetVal; /**< friendly type for global return value */
|
||||
* the function finalizer always "finalize_it".
|
||||
*/
|
||||
#define CHKiRet(code) if((iRet = code) != RS_RET_OK) goto finalize_it
|
||||
#define DEFiRet rsRetVal iRet = RS_RET_OK
|
||||
|
||||
/** Object ID. These are for internal checking. Each
|
||||
* object is assigned a specific ID. This is contained in
|
||||
|
||||
58
syslogd.c
58
syslogd.c
@ -3431,57 +3431,37 @@ static rsRetVal addAllowedSenderLine(char* pName, uchar** ppRestOfConfLine)
|
||||
}
|
||||
|
||||
|
||||
/* Parse and interpret a $DynaFileCacheSize line.
|
||||
* Parameter **pp has a pointer to the current config line.
|
||||
* On exit, it will be updated to the processed position.
|
||||
* rgerhards, 2007-07-4 (happy independence day to my US friends!)
|
||||
/* set the dynaFile cache size. Does some limit checking.
|
||||
* rgerhards, 2007-07-31
|
||||
*/
|
||||
static void doDynaFileCacheSizeLine(uchar **pp)
|
||||
static rsRetVal setDynaFileCacheSize(void __attribute__((unused)) *pVal, int iNewVal)
|
||||
{
|
||||
uchar *p;
|
||||
DEFiRet;
|
||||
uchar errMsg[128]; /* for dynamic error messages */
|
||||
int i;
|
||||
|
||||
assert(pp != NULL);
|
||||
assert(*pp != NULL);
|
||||
|
||||
skipWhiteSpace(pp); /* skip over any whitespace */
|
||||
p = *pp;
|
||||
|
||||
if(!isdigit((int) *p)) {
|
||||
if(iNewVal < 1) {
|
||||
snprintf((char*) errMsg, sizeof(errMsg)/sizeof(uchar),
|
||||
"DynaFileCacheSize invalid, value '%s'.", p);
|
||||
"DynaFileCacheSize must be greater 0 (%d given), changed to 1.", iNewVal);
|
||||
errno = 0;
|
||||
logerror((char*) errMsg);
|
||||
return;
|
||||
iRet = RS_RET_VAL_OUT_OF_RANGE;
|
||||
iNewVal = 1;
|
||||
} else if(iNewVal > 10000) {
|
||||
snprintf((char*) errMsg, sizeof(errMsg)/sizeof(uchar),
|
||||
"DynaFileCacheSize maximum is 10,000 (%d given), changed to 10,000.", iNewVal);
|
||||
errno = 0;
|
||||
logerror((char*) errMsg);
|
||||
iRet = RS_RET_VAL_OUT_OF_RANGE;
|
||||
iNewVal = 10000;
|
||||
}
|
||||
|
||||
/* pull value */
|
||||
for(i = 0 ; *p && isdigit((int) *p) ; ++p)
|
||||
i = i * 10 + *p - '0';
|
||||
|
||||
if(i < 1) {
|
||||
snprintf((char*) errMsg, sizeof(errMsg)/sizeof(uchar),
|
||||
"DynaFileCacheSize must be greater 0 (%d given), changed to 1.", i);
|
||||
errno = 0;
|
||||
logerror((char*) errMsg);
|
||||
i = 1;
|
||||
} else if(i > 10000) {
|
||||
snprintf((char*) errMsg, sizeof(errMsg)/sizeof(uchar),
|
||||
"DynaFileCacheSize maximum is 10,000 (%d given), changed to 10,000.", i);
|
||||
errno = 0;
|
||||
logerror((char*) errMsg);
|
||||
i = 10000;
|
||||
}
|
||||
iDynaFileCacheSize = iNewVal;
|
||||
dprintf("DynaFileCacheSize changed to %d.\n", iNewVal);
|
||||
|
||||
iDynaFileCacheSize = i;
|
||||
dprintf("DynaFileCacheSize changed to %d.\n", i);
|
||||
|
||||
*pp = p;
|
||||
return iRet;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* process a $ModLoad config line.
|
||||
* As of now, it is a dummy, that will later evolve into the
|
||||
* loader for plug-ins.
|
||||
@ -3621,7 +3601,7 @@ void cfsysline(uchar *p)
|
||||
} else if(!strcasecmp((char*) szCmd, "filegroup")) {
|
||||
doGetGID(&p, NULL, &fileGID);
|
||||
} else if(!strcasecmp((char*) szCmd, "dynafilecachesize")) {
|
||||
doDynaFileCacheSizeLine(&p);
|
||||
doGetInt(&p, (void*) setDynaFileCacheSize, NULL);
|
||||
} else if(!strcasecmp((char*) szCmd, "repeatedmsgreduction")) {
|
||||
doBinaryOptionLine(&p, NULL, &bReduceRepeatMsgs);
|
||||
} else if(!strcasecmp((char*) szCmd, "controlcharacterescapeprefix")) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user