AIX_port: corrects style and compatibility issues

This commit is contained in:
Philippe Duveau 2019-02-14 16:15:07 +01:00
parent 5bd9237874
commit dda425dc91
5 changed files with 959 additions and 965 deletions

View File

@ -96,9 +96,9 @@ DEFobjCurrIf(prop)
#define ADD_METADATA_UNSPECIFIED -1
typedef enum action_batchreport_t {
action_nothing,
action_rename,
action_delete
action_nothing,
action_rename,
action_delete
} action_batchreport_t;
struct instanceConf_s {
@ -119,7 +119,7 @@ struct instanceConf_s {
int len_rename;
char *ff_reject;
int len_reject;
int len_reject;
int filename_oversize;
ruleset_t *pBindRuleset; /* ruleset to bind listener to (use system default if unspecified) */
@ -145,19 +145,20 @@ typedef struct myConfData_s {
instanceConf_t *root, *tail;
uchar *buffer;
uchar *buffer_minsize;
int iPollInterval; /* number of seconds to sleep when there was no file activity */
uchar *buffer;
uchar *buffer_minsize;
int iPollInterval; /* number of seconds to sleep when there was no file activity */
} myConfData_t;
static myConfData_t fixedModConf;/* modConf ptr to use for the current load process */
/* config variables */
struct modConfData_s {
rsconf_t *pConf; /* our overall config object */
rsconf_t *pConf; /* our overall config object */
};
static prop_t *pInputName = NULL; /* there is only one global inputName for all messages generated by this input */
static prop_t *pInputName = NULL;
/* there is only one global inputName for all messages generated by this input */
/* module-global parameters */
static struct cnfparamdescr modpdescr[] = {
@ -165,8 +166,8 @@ static struct cnfparamdescr modpdescr[] = {
};
static struct cnfparamblk modpblk =
{ CNFPARAMBLK_VERSION,
sizeof(modpdescr)/sizeof(struct cnfparamdescr),
modpdescr
sizeof(modpdescr)/sizeof(struct cnfparamdescr),
modpdescr
};
/* input instance parameters */
@ -181,8 +182,8 @@ static struct cnfparamdescr inppdescr[] = {
};
static struct cnfparamblk inppblk =
{ CNFPARAMBLK_VERSION,
sizeof(inppdescr)/sizeof(struct cnfparamdescr),
inppdescr
sizeof(inppdescr)/sizeof(struct cnfparamdescr),
inppdescr
};
#include "im-helper.h" /* must be included AFTER the type definitions! */
@ -191,11 +192,11 @@ static struct cnfparamblk inppblk =
* not freed - thuis must be done by the caller.
*/
static rsRetVal send_msg(instanceConf_t *const __restrict__ pInst,
uchar *const __restrict__ cstr, size_t clen,
struct timeval *recvts, time_t gents,
uchar *structuredData, int structuredDataLen,
uchar *prog, int progLen,
uchar *pszNewFname)
uchar *const __restrict__ cstr, size_t clen,
struct timeval *recvts, time_t gents,
uchar *structuredData, int structuredDataLen,
uchar *prog, int progLen,
uchar *pszNewFname)
{
DEFiRet;
smsg_t *pMsg;
@ -215,15 +216,15 @@ static rsRetVal send_msg(instanceConf_t *const __restrict__ pInst,
MsgSetHOSTNAME(pMsg, (uchar*)fixedModConf.hostname, (const int) fixedModConf.lhostname);
MsgSetTAG(pMsg, pInst->pszTag, pInst->lenTag);
MsgSetStructuredData(pMsg, "");
if (structuredData && structuredDataLen)
MsgAddToStructuredData(pMsg, structuredData, structuredDataLen);
MsgSetStructuredData(pMsg, "");
if (structuredData && structuredDataLen)
MsgAddToStructuredData(pMsg, structuredData, structuredDataLen);
pMsg->iFacility = pInst->iFacility >> 3;
pMsg->iSeverity = pInst->iSeverity;
pMsg->iFacility = pInst->iFacility >> 3;
pMsg->iSeverity = pInst->iSeverity;
cstrConstruct(&pMsg->pCSPROCID);
rsCStrAppendStrWithLen(pMsg->pCSPROCID, prog, progLen);
cstrConstruct(&pMsg->pCSPROCID);
rsCStrAppendStrWithLen(pMsg->pCSPROCID, prog, progLen);
MsgSetRuleset(pMsg, pInst->pBindRuleset);
@ -244,7 +245,7 @@ static void pollFileCancelCleanup(void *pArg)
if (ppInst->fd > 0)
close(ppInst->fd);
if (ppInst->pszNewFName)
free(ppInst->pszNewFName);
free(ppInst->pszNewFName);
}
/* poll a file, need to check file rollover etc. open file if not open */
@ -255,10 +256,10 @@ static void pollFileCancelCleanup(void *pArg)
static rsRetVal pollFile(instanceConf_t *pInst)
{
DEFiRet;
uchar *structured_data = NULL, *start;
int structured_data_len = 0;
int toobig;
pInst->fd = 0;
uchar *structured_data = NULL, *start;
int structured_data_len = 0;
int toolarge;
pInst->fd = 0;
/* Note: we must do pthread_cleanup_push() immediately, because the POXIS macros
* otherwise do not work if I include the _cleanup_pop() inside an if... -- rgerhards, 2008-08-14
@ -274,222 +275,229 @@ static rsRetVal pollFile(instanceConf_t *pInst)
if (!glob((char*)pInst->pszFollow_glob, GLOB_NOSORT, 0, &res))
{
for (size_t i = 0; i < res.gl_pathc && glbl.GetGlobalInputTermState() == 0; i++)
{
char *pszCurrFName = res.gl_pathv[i];
DBGPRINTF("imbatchreport : File found '%s')\n",pszCurrFName);
for (size_t i = 0; i < res.gl_pathc && glbl.GetGlobalInputTermState() == 0; i++)
{
char *pszCurrFName = res.gl_pathv[i];
DBGPRINTF("imbatchreport : File found '%s')\n",pszCurrFName);
toobig = 0;
toolarge = 0;
if (!stat(pszCurrFName, &fstate) && S_ISREG(fstate.st_mode) )
{
regmatch_t matches[1];
if (!stat(pszCurrFName, &fstate) && S_ISREG(fstate.st_mode) )
{
regmatch_t matches[1];
if (regexec(&pInst->ff_preg, pszCurrFName, 1, matches, 0))
{ /* as this test was already made on glob's file search it must not be possible but let's check it anyway */
LogError(0, RS_RET_INVALID_PARAMS, "imbatchreport: regex does not match to filename: Aborting module to avoid loops.");
pInst->must_stop = TRUE;
if (regexec(&pInst->ff_preg, pszCurrFName, 1, matches, 0))
{ /* as this test was already made on glob's file search it
* must not be possible but let's check it anyway */
LogError(0, RS_RET_INVALID_PARAMS,
"imbatchreport: regex does not match to filename: Aborting module to avoid loops.");
pInst->must_stop = TRUE;
globfree(&res);
return RS_RET_INVALID_PARAMS;
}
globfree(&res);
return RS_RET_INVALID_PARAMS;
}
pInst->fd = open(pszCurrFName, O_NOCTTY | O_RDONLY | O_NONBLOCK | O_LARGEFILE, 0);
pInst->fd = open(pszCurrFName, O_NOCTTY | O_RDONLY | O_NONBLOCK | O_LARGEFILE, 0);
if (pInst->fd > 0)
{
size_t file_len, file_in_buffer, msg_len;
char *filename;
if (pInst->fd > 0)
{
size_t file_len, file_in_buffer, msg_len;
char *filename;
uchar *local_program = (uchar*)"-";
size_t local_program_len = 1;
uchar *local_program = (uchar*)"-";
size_t local_program_len = 1;
time_t start_ts = fstate.st_ctim.tv_sec;
time_t start_ts = fstate.st_ctim.tv_sec;
file_len = lseek(pInst->fd, 0, SEEK_END);
file_len = lseek(pInst->fd, 0, SEEK_END);
filename = strrchr(pszCurrFName, '/');
if (filename)
filename++;
else
filename = pszCurrFName;
filename = strrchr(pszCurrFName, '/');
if (filename)
filename++;
else
filename = pszCurrFName;
/* First read the end of the file to get Structured Data */
/* First read the end of the file to get Structured Data */
msg_len = (file_len < BUFFER_MINSIZE) ? file_len : BUFFER_MINSIZE;
msg_len = (file_len < BUFFER_MINSIZE) ? file_len : BUFFER_MINSIZE;
lseek(pInst->fd, -msg_len, SEEK_END);
lseek(pInst->fd, -msg_len, SEEK_END);
file_in_buffer = read(pInst->fd, fixedModConf.buffer_minsize, msg_len);
DBGPRINTF("imbatchreport : file end read %ld %ld\n", file_in_buffer, msg_len);
file_in_buffer = read(pInst->fd, fixedModConf.buffer_minsize, msg_len);
DBGPRINTF("imbatchreport : file end read %ld %ld\n", file_in_buffer, msg_len);
if (file_in_buffer == msg_len)
{
for (; msg_len && fixedModConf.buffer_minsize[msg_len-1] == '\n'; msg_len--)
;
if (file_in_buffer == msg_len)
{
for (; msg_len && fixedModConf.buffer_minsize[msg_len-1] == '\n'; msg_len--)
;
if (fixedModConf.buffer_minsize[msg_len-1] == ']')
{ /* We read the last part of the report to get structured data */
if (fixedModConf.buffer_minsize[msg_len-1] == ']')
{ /* We read the last part of the report to get structured data */
for (structured_data = fixedModConf.buffer_minsize + msg_len, structured_data_len = 0;
structured_data >= fixedModConf.buffer_minsize && *structured_data != '[';
structured_data--, structured_data_len++)
;
for (structured_data = fixedModConf.buffer_minsize + msg_len, structured_data_len = 0;
structured_data >= fixedModConf.buffer_minsize && *structured_data != '[';
structured_data--, structured_data_len++)
;
if (*structured_data == '[')
{
uchar *struct_field = (uchar*)strstr((char*)structured_data, "START="), v;
if (struct_field)
{
start_ts = 0;
for (struct_field += 7; (v = *struct_field - (uchar)'0') <= 9; struct_field++ )
start_ts = start_ts*10 + v;
if (*structured_data == '[')
{
uchar *struct_field = (uchar*)strstr((char*)structured_data, "START="), v;
if (struct_field)
{
start_ts = 0;
for (struct_field += 7; (v = *struct_field - (uchar)'0') <= 9; struct_field++ )
start_ts = start_ts*10 + v;
}
}
struct_field = (uchar*)strstr((char*)structured_data, "KSH=\"");
if (struct_field)
{
local_program = struct_field + 5;
struct_field = (uchar*)strstr((char*)local_program, "\"");
if (struct_field)
local_program_len = struct_field - local_program;
else
local_program = (uchar*)"-";
}
struct_field = (uchar*)strstr((char*)structured_data, "KSH=\"");
if (struct_field)
{
local_program = struct_field + 5;
struct_field = (uchar*)strstr((char*)local_program, "\"");
if (struct_field)
local_program_len = struct_field - local_program;
else
local_program = (uchar*)"-";
}
msg_len -= structured_data_len;
}
else
{
structured_data = NULL;
structured_data_len = 0;
}
} /* if (fixedModConf.buffer_minsize[msg_len -1] == ']') */
msg_len -= structured_data_len;
}
else
{
structured_data = NULL;
structured_data_len = 0;
}
} /* if (fixedModConf.buffer_minsize[msg_len -1] == ']') */
if (file_len > fixedModConf.msg_size)
{
if ((size_t)(structured_data_len + FILE_TOO_BIG_LEN) > fixedModConf.msg_size)
{
LogError(0, RS_RET_INVALID_PARAMS, "afbatchreport_notify : the msg_size options (%lu) is really too small even to handle batch reports notification of %ld octets (file too big)",
fixedModConf.msg_size,
60 + fixedModConf.lhostname + pInst->lenTag + structured_data_len);
pInst->must_stop = 1;
if (file_len > fixedModConf.msg_size)
{
if ((size_t)(structured_data_len + FILE_TOO_BIG_LEN) > fixedModConf.msg_size)
{
LogError(0, RS_RET_INVALID_PARAMS, "pollFile : the msg_size options (%lu) is"
"really too small even to handle batch reports notification of %ld "
"octets (file too large)", fixedModConf.msg_size,
60 + fixedModConf.lhostname + pInst->lenTag + structured_data_len);
pInst->must_stop = 1;
close(pInst->fd);
pInst->fd = -1;
close(pInst->fd);
pInst->fd = -1;
globfree(&res);
return RS_RET_INVALID_PARAMS;
}
globfree(&res);
return RS_RET_INVALID_PARAMS;
}
LogError(0, RS_RET_INVALID_PARAMS,
"afbatchreport_notify : the batch report is too big (rejecting) filename=%s, max_size=%lu, msg_size=%ld",
pszCurrFName,fixedModConf.msg_size, file_len);
LogError(0, RS_RET_INVALID_PARAMS,
"pollFile : the batch report is too large (rejecting) filename=%s,"
"max_size=%lu, msg_size=%ld",
pszCurrFName,fixedModConf.msg_size, file_len);
toobig = 1;
toolarge = 1;
start = (uchar*)FILE_TOO_BIG;
start = (uchar*)FILE_TOO_BIG;
msg_len = FILE_TOO_BIG_LEN;
}
else
{
if (file_len > file_in_buffer)
{
size_t file_to_read = file_len - file_in_buffer, buffer_used = 0, r;
start = fixedModConf.buffer_minsize - file_to_read;
msg_len = FILE_TOO_BIG_LEN;
}
else
{
if (file_len > file_in_buffer)
{
size_t file_to_read = file_len - file_in_buffer, buffer_used = 0, r;
start = fixedModConf.buffer_minsize - file_to_read;
lseek(pInst->fd, 0, SEEK_SET);
lseek(pInst->fd, 0, SEEK_SET);
do
{
r = read(pInst->fd, start + buffer_used, file_to_read - buffer_used);
buffer_used += r;
}
while (r && file_to_read > buffer_used);
do
{
r = read(pInst->fd, start + buffer_used, file_to_read - buffer_used);
buffer_used += r;
}
while (r && file_to_read > buffer_used);
msg_len += file_to_read;
msg_len += file_to_read;
}
else
start = fixedModConf.buffer_minsize;
}
else
start = fixedModConf.buffer_minsize;
for (uchar*p=start+msg_len; p>=start; p--)
if (!*p) *p = ' ';
}
for (uchar*p=start+msg_len; p>=start; p--)
if (!*p) *p = ' ';
}
close(pInst->fd);
pInst->fd = 0;
close(pInst->fd);
pInst->fd = 0;
struct timeval tv;
struct timeval tv;
tv.tv_sec = fstate.st_mtime;
tv.tv_usec = fstate.st_mtim.tv_nsec / 1000;
tv.tv_sec = fstate.st_mtime;
tv.tv_usec = fstate.st_mtim.tv_nsec / 1000;
if (send_msg(pInst, start, (start[msg_len]=='\n') ? msg_len : msg_len+1,
&tv, start_ts, structured_data, structured_data_len,
local_program, local_program_len,
(uchar*)pszCurrFName) == RS_RET_OK)
{
if (pInst->action == action_rename || toobig)
{
char *pszNewFName = (char*)malloc(strlen(pszCurrFName)+pInst->filename_oversize);
memcpy(pszNewFName, pszCurrFName, matches[0].rm_so);
strcpy((char*)pszNewFName + matches[0].rm_so,
(toobig) ? pInst->ff_reject : pInst->ff_rename);
if (send_msg(pInst, start, (start[msg_len]=='\n') ? msg_len : msg_len+1,
&tv, start_ts, structured_data, structured_data_len,
local_program, local_program_len,
(uchar*)pszCurrFName) == RS_RET_OK)
{
if (pInst->action == action_rename || toolarge)
{
char *pszNewFName = (char*)malloc(strlen(pszCurrFName)+pInst->filename_oversize);
memcpy(pszNewFName, pszCurrFName, matches[0].rm_so);
strcpy((char*)pszNewFName + matches[0].rm_so,
(toolarge) ? pInst->ff_reject : pInst->ff_rename);
if (rename(pszCurrFName, pszNewFName))
{
LogError(0, RS_RET_STREAM_DISABLED,
"imbatchreport: module stops because it was unable to rename form %s to %s.",
pszCurrFName , pszNewFName);
pInst->must_stop = 1;
}
else
DBGPRINTF("imbatchreport : file %s sent and renamed to %s.\n", pszCurrFName, pszNewFName);
free(pszNewFName);
}
else
{
if (unlink(pszCurrFName))
{
LogError(0, RS_RET_STREAM_DISABLED,
"imbatchreport: module stops because it was unable to delete %s.",
pszCurrFName);
pInst->must_stop = 1;
}
else
DBGPRINTF("imbatchreport : file %s sent and deleted\n", pszCurrFName);
}
}
} /* if (file_in_buffer == msg_len) */
else
{ /* if (file_in_buffer == msg_len) */
/* failed to read end of file so rename it */
close(pInst->fd);
pInst->fd = 0;
if (rename(pszCurrFName, pszNewFName))
{
LogError(0, RS_RET_STREAM_DISABLED,
"imbatchreport: module stops because it was"
" unable to rename form %s to %s.",
pszCurrFName , pszNewFName);
pInst->must_stop = 1;
}
else
DBGPRINTF("imbatchreport : file %s sent and renamed to %s.\n",
pszCurrFName, pszNewFName);
free(pszNewFName);
}
else
{
if (unlink(pszCurrFName))
{
LogError(0, RS_RET_STREAM_DISABLED,
"imbatchreport: module stops because it was unable to delete %s.",
pszCurrFName);
pInst->must_stop = 1;
}
else
DBGPRINTF("imbatchreport : file %s sent and deleted\n", pszCurrFName);
}
}
} /* if (file_in_buffer == msg_len) */
else
{ /* if (file_in_buffer == msg_len) */
/* failed to read end of file so rename it */
close(pInst->fd);
pInst->fd = 0;
char *pszNewFName = (char*)malloc(strlen(pszCurrFName)+pInst->filename_oversize);
memcpy(pszNewFName, pszCurrFName, matches[0].rm_so);
strcpy((char*)pszNewFName + matches[0].rm_so, pInst->ff_reject);
char *pszNewFName = (char*)malloc(strlen(pszCurrFName)+pInst->filename_oversize);
memcpy(pszNewFName, pszCurrFName, matches[0].rm_so);
strcpy((char*)pszNewFName + matches[0].rm_so, pInst->ff_reject);
if (rename(pszCurrFName, pszNewFName))
{
LogError(0, RS_RET_STREAM_DISABLED,
"imbatchreport: module stops because it was unable to rename form %s to %s.",
pszCurrFName , pszNewFName);
pInst->must_stop = 1;
}
else
DBGPRINTF("imbatchreport : file %s renamed to %s due to error while reading it.\n", pszCurrFName, pszNewFName);
free(pszNewFName);
if (rename(pszCurrFName, pszNewFName))
{
LogError(0, RS_RET_STREAM_DISABLED,
"imbatchreport: module stops because it was unable to rename form %s to %s.",
pszCurrFName , pszNewFName);
pInst->must_stop = 1;
}
else
DBGPRINTF("imbatchreport : file %s renamed to %s due to error while reading it.\n",
pszCurrFName, pszNewFName);
free(pszNewFName);
} /* if (file_in_buffer == msg_len) */
} /* if (pInst->fd > 0) */
} /* if stat */
} /* for */
} /* if (file_in_buffer == msg_len) */
} /* if (pInst->fd > 0) */
} /* if stat */
} /* for */
} /* glob */
globfree(&res);
}
@ -525,10 +533,10 @@ createInstance(instanceConf_t **pinst)
inst->iSeverity = LOG_NOTICE;
inst->iFacility = LOG_LOCAL0;
inst->ff_regex = NULL;
inst->ff_rename = NULL;
inst->len_rename = 0;
inst->ff_reject = NULL;
inst->len_reject = 0;
inst->ff_rename = NULL;
inst->len_rename = 0;
inst->ff_reject = NULL;
inst->len_reject = 0;
inst->goon = 0;
inst->ratelimiter = NULL;
@ -608,7 +616,7 @@ static rsRetVal checkInstance(instanceConf_t *inst)
ABORT_FINALIZE(RS_RET_CONFIG_ERROR);
}
dbgprintf("imbatchreport: instance checked");
dbgprintf("imbatchreport: instance checked");
finalize_it:
RETiRet;
@ -618,7 +626,7 @@ BEGINnewInpInst
struct cnfparamvals *pvals;
instanceConf_t *inst;
int i;
char *temp;
char *temp;
CODESTARTnewInpInst
DBGPRINTF("newInpInst (imbatchreport)\n");
@ -648,97 +656,98 @@ CODESTARTnewInpInst
inst->iSeverity = pvals[i].val.d.n;
} else if(!strcmp(inppblk.descr[i].name, "facility")) {
inst->iFacility = pvals[i].val.d.n;
} else if(!strcmp(inppblk.descr[i].name, "rename")) {
if (inst->action == action_delete)
{
LogError(0, RS_RET_PARAM_ERROR,
"'rename' and 'delete' are exclusive !");
ABORT_FINALIZE(RS_RET_PARAM_ERROR);
}
} else if(!strcmp(inppblk.descr[i].name, "rename")) {
if (inst->action == action_delete)
{
LogError(0, RS_RET_PARAM_ERROR,
"'rename' and 'delete' are exclusive !");
ABORT_FINALIZE(RS_RET_PARAM_ERROR);
}
inst->ff_regex = es_str2cstr(pvals[i].val.d.estr, NULL);
inst->len_reject = 0;
inst->len_reject = 0;
if ((inst->ff_rename = strchr(inst->ff_regex, ' ')) != NULL ) {
*inst->ff_rename++ = '\0';
if ((inst->ff_reject = strchr(inst->ff_rename, ' ')) != NULL ) {
if ((inst->ff_rename = strchr(inst->ff_regex, ' ')) != NULL ) {
*inst->ff_rename++ = '\0';
if ((inst->ff_reject = strchr(inst->ff_rename, ' ')) != NULL ) {
*inst->ff_reject++ = '\0';
temp = strchr(inst->ff_reject, ' ');
if (temp) *temp = '\0';
*inst->ff_reject++ = '\0';
temp = strchr(inst->ff_reject, ' ');
if (temp) *temp = '\0';
if (strcmp(inst->ff_rename, "-")){
inst->ff_rename = strdup(inst->ff_rename);
inst->len_rename = strlen(inst->ff_rename);
}else{
inst->ff_rename = strdup("");
inst->len_rename = 0;
}
if (strcmp(inst->ff_rename, "-")){
inst->ff_rename = strdup(inst->ff_rename);
inst->len_rename = strlen(inst->ff_rename);
}else{
inst->ff_rename = strdup("");
inst->len_rename = 0;
}
inst->ff_reject = strdup(inst->ff_reject);
inst->len_reject = strlen(inst->ff_reject);
inst->ff_reject = strdup(inst->ff_reject);
inst->len_reject = strlen(inst->ff_reject);
if (inst->len_reject && regcomp(&inst->ff_preg, (char*)inst->ff_regex, REG_EXTENDED))
{
inst->len_reject = 0;
LogError(0, RS_RET_SYNTAX_ERROR,
"The first part of 'rename' parameter does not contain a valid regex");
ABORT_FINALIZE(RS_RET_SYNTAX_ERROR);
}
}
}
if (inst->len_reject == 0)
{
LogError(0, RS_RET_PARAM_ERROR,
"'rename' must specify THREE parameters separated by exactly ONE space ! The second parameter can be a null string to get this use a '-'.");
ABORT_FINALIZE(RS_RET_PARAM_ERROR);
}
if (inst->len_reject && regcomp(&inst->ff_preg, (char*)inst->ff_regex, REG_EXTENDED))
{
inst->len_reject = 0;
LogError(0, RS_RET_SYNTAX_ERROR,
"The first part of 'rename' parameter does not contain a valid regex");
ABORT_FINALIZE(RS_RET_SYNTAX_ERROR);
}
}
}
if (inst->len_reject == 0)
{
LogError(0, RS_RET_PARAM_ERROR,
"'rename' must specify THREE parameters separated by exactly ONE space ! The second "
"parameter can be a null string to get this use a '-'.");
ABORT_FINALIZE(RS_RET_PARAM_ERROR);
}
inst->action = action_rename;
inst->action = action_rename;
} else if(!strcmp(inppblk.descr[i].name, "delete")) {
if (inst->action == action_rename)
{
LogError(0, RS_RET_PARAM_ERROR,
"'rename' and 'delete' are exclusive !");
ABORT_FINALIZE(RS_RET_PARAM_ERROR);
}
} else if(!strcmp(inppblk.descr[i].name, "delete")) {
if (inst->action == action_rename)
{
LogError(0, RS_RET_PARAM_ERROR,
"'rename' and 'delete' are exclusive !");
ABORT_FINALIZE(RS_RET_PARAM_ERROR);
}
inst->ff_regex = es_str2cstr(pvals[i].val.d.estr, NULL);
inst->ff_regex = es_str2cstr(pvals[i].val.d.estr, NULL);
inst->len_reject = 0;
inst->len_reject = 0;
if ((inst->ff_reject = strchr(inst->ff_regex, ' ')) != NULL ) {
*inst->ff_reject++ = '\0';
if ((inst->ff_reject = strchr(inst->ff_regex, ' ')) != NULL ) {
*inst->ff_reject++ = '\0';
temp = strchr(inst->ff_reject, ' ');
if (temp) *temp = '\0';
temp = strchr(inst->ff_reject, ' ');
if (temp) *temp = '\0';
inst->ff_reject = strdup(inst->ff_reject);
inst->len_reject = strlen(inst->ff_reject);
inst->ff_reject = strdup(inst->ff_reject);
inst->len_reject = strlen(inst->ff_reject);
if (inst->len_reject && regcomp(&inst->ff_preg, (char*)inst->ff_regex, REG_EXTENDED))
{
inst->len_reject = 0;
LogError(0, RS_RET_SYNTAX_ERROR,
"The first part of 'delete' parameter does not contain a valid regex");
ABORT_FINALIZE(RS_RET_SYNTAX_ERROR);
}
if (inst->len_reject && regcomp(&inst->ff_preg, (char*)inst->ff_regex, REG_EXTENDED))
{
inst->len_reject = 0;
LogError(0, RS_RET_SYNTAX_ERROR,
"The first part of 'delete' parameter does not contain a valid regex");
ABORT_FINALIZE(RS_RET_SYNTAX_ERROR);
}
}
}
if (inst->len_reject == 0)
{
LogError(0, RS_RET_PARAM_ERROR,
"'delete' must specify TWO parameters separated by exactly ONE space !");
ABORT_FINALIZE(RS_RET_PARAM_ERROR);
}
inst->action = action_delete;
if (inst->len_reject == 0)
{
LogError(0, RS_RET_PARAM_ERROR,
"'delete' must specify TWO parameters separated by exactly ONE space !");
ABORT_FINALIZE(RS_RET_PARAM_ERROR);
}
inst->action = action_delete;
} else {
dbgprintf("imbatchreport: program error, non-handled "
"param '%s'\n", inppblk.descr[i].name);
"param '%s'\n", inppblk.descr[i].name);
}
}
@ -763,8 +772,8 @@ ENDnewInpInst
BEGINbeginCnfLoad
CODESTARTbeginCnfLoad
pModConf->pConf = pConf;
fixedModConf.iPollInterval = DFLT_PollInterval;
pModConf->pConf = pConf;
fixedModConf.iPollInterval = DFLT_PollInterval;
ENDbeginCnfLoad
@ -789,14 +798,14 @@ CODESTARTsetModCnf
if(!pvals[i].bUsed)
continue;
if(!strcmp(modpblk.descr[i].name, "pollinginterval")) {
fixedModConf.iPollInterval = (int) pvals[i].val.d.n;
fixedModConf.iPollInterval = (int) pvals[i].val.d.n;
} else {
dbgprintf("imbatchreport: program error, non-handled "
"param '%s' in beginCnfLoad\n", modpblk.descr[i].name);
"param '%s' in beginCnfLoad\n", modpblk.descr[i].name);
}
}
fixedModConf.hostname = strdup((char*)glbl.GetLocalHostName());
fixedModConf.lhostname = strlen(fixedModConf.hostname);
fixedModConf.lhostname = strlen(fixedModConf.hostname);
finalize_it:
if(pvals != NULL)
cnfparamvalsDestruct(pvals, &modpblk);
@ -806,7 +815,7 @@ ENDsetModCnf
BEGINendCnfLoad
CODESTARTendCnfLoad
dbgprintf("imbatchreport: polling interval is %d\n",
fixedModConf.iPollInterval);
fixedModConf.iPollInterval);
ENDendCnfLoad
@ -835,7 +844,7 @@ BEGINfreeCnf
instanceConf_t *inst, *del;
CODESTARTfreeCnf
for(inst = fixedModConf.root ; inst != NULL ; ) {
if (inst->pszBindRuleset) free(inst->pszBindRuleset);
if (inst->pszBindRuleset) free(inst->pszBindRuleset);
if (inst->pszFollow_glob) free(inst->pszFollow_glob);
if (inst->pszDirName) free(inst->pszDirName);
if (inst->pszFileBaseName) free(inst->pszFileBaseName);
@ -844,18 +853,18 @@ CODESTARTfreeCnf
if (inst->len_reject) regfree(&inst->ff_preg);
if (inst->ff_regex) free(inst->ff_regex);
if (inst->ff_rename) free(inst->ff_rename);
if (inst->ff_reject) free(inst->ff_reject);
if (inst->ff_rename) free(inst->ff_rename);
if (inst->ff_reject) free(inst->ff_reject);
if (inst->ratelimiter) ratelimitDestruct(inst->ratelimiter);
del = inst;
inst = inst->next;
free(del);
}
if (fixedModConf.hostname) {
free(fixedModConf.hostname);
fixedModConf.hostname = NULL;
}
if (fixedModConf.hostname) {
free(fixedModConf.hostname);
fixedModConf.hostname = NULL;
}
ENDfreeCnf
/* This function is called by the framework to gather the input. The module stays
@ -868,18 +877,18 @@ CODESTARTrunInput
while(glbl.GetGlobalInputTermState() == 0) {
instanceConf_t *pInst;
for(pInst = fixedModConf.root ; pInst != NULL ; pInst = pInst->next) {
if (pInst->goon) {
if(glbl.GetGlobalInputTermState() == 1)
break;
pollFile(pInst);
}
if (pInst->goon) {
if(glbl.GetGlobalInputTermState() == 1)
break;
pollFile(pInst);
}
}
if(glbl.GetGlobalInputTermState() == 0)
srSleep(fixedModConf.iPollInterval, 10);
}
DBGPRINTF("imbatchreport: terminating upon request of rsyslog core\n");
RETiRet;
DBGPRINTF("imbatchreport: terminating upon request of rsyslog core\n");
RETiRet;
ENDrunInput
/* The function is called by rsyslog before runInput() is called. It is a last chance
@ -895,15 +904,15 @@ CODESTARTwillRun
CHKiRet(prop.SetString(pInputName, UCHAR_CONSTANT("imbatchreport"), sizeof("imbatchreport") - 1));
CHKiRet(prop.ConstructFinalize(pInputName));
fixedModConf.msg_size = glbl.GetMaxLine();
fixedModConf.msg_size = glbl.GetMaxLine();
size_t alloc_s = ((fixedModConf.msg_size > BUFFER_MINSIZE) ? fixedModConf.msg_size : BUFFER_MINSIZE) + 1;
size_t alloc_s = ((fixedModConf.msg_size > BUFFER_MINSIZE) ? fixedModConf.msg_size : BUFFER_MINSIZE) + 1;
CHKmalloc(fixedModConf.buffer = (uchar*)malloc(alloc_s));
CHKmalloc(fixedModConf.buffer = (uchar*)malloc(alloc_s));
fixedModConf.buffer_minsize = &fixedModConf.buffer[alloc_s - (BUFFER_MINSIZE+1)];
fixedModConf.buffer_minsize = &fixedModConf.buffer[alloc_s - (BUFFER_MINSIZE+1)];
fixedModConf.buffer_minsize[BUFFER_MINSIZE] = '\0';
fixedModConf.buffer_minsize[BUFFER_MINSIZE] = '\0';
finalize_it:
ENDwillRun
@ -912,7 +921,7 @@ ENDwillRun
*/
BEGINafterRun
CODESTARTafterRun
if (fixedModConf.buffer) free(fixedModConf.buffer);
if (fixedModConf.buffer) free(fixedModConf.buffer);
if(pInputName != NULL)
prop.Destruct(&pInputName);
ENDafterRun
@ -976,6 +985,3 @@ std_checkRuleset_genErrMsg(__attribute__((unused)) modConfData_t *modConf, insta
"using default ruleset instead", inst->pszBindRuleset,
inst->pszFollow_glob);
}
/* vim:set ai:
*/

File diff suppressed because it is too large Load Diff

View File

@ -59,32 +59,32 @@
#include "ratelimit.h"
struct instanceConf_s {
uchar *pszUlogBaseName;
uchar *pszCurrFName;
struct tm currTm;
uchar *pszTag;
size_t lenTag;
uchar *pszStructuredDataName;
size_t lenStructuredDataName;
uchar *pszStateFile;
uchar *pszBindRuleset;
int nMultiSub;
int iPersistStateInterval;
int iFacility;
int iSeverity;
strm_t *pStrm; /* its stream (NULL if not assigned) */
int maxLinesAtOnce;
ruleset_t *pBindRuleset; /* ruleset to bind listener to (use system default if unspecified) */
ratelimit_t *ratelimiter;
multi_submit_t multiSub;
int nRecords;
struct instanceConf_s *next;
struct instanceConf_s *prev;
uchar *pszUlogBaseName;
uchar *pszCurrFName;
struct tm currTm;
uchar *pszTag;
size_t lenTag;
uchar *pszStructuredDataName;
size_t lenStructuredDataName;
uchar *pszStateFile;
uchar *pszBindRuleset;
int nMultiSub;
int iPersistStateInterval;
int iFacility;
int iSeverity;
strm_t *pStrm; /* its stream (NULL if not assigned) */
int maxLinesAtOnce;
ruleset_t *pBindRuleset; /* ruleset to bind listener to (use system default if unspecified) */
ratelimit_t *ratelimiter;
multi_submit_t multiSub;
int nRecords;
struct instanceConf_s *next;
struct instanceConf_s *prev;
};
/* config variables */
struct modConfData_s {
rsconf_t *pConf; /* our overall config object */
rsconf_t *pConf; /* our overall config object */
};
static instanceConf_t *confRoot = NULL;
@ -132,9 +132,9 @@ DEFobjCurrIf(ruleset)
#pragma pack(push,1)
#endif
typedef
union {
uint64_t ui64;
uchar uc[8];
union {
uint64_t ui64;
uchar uc[8];
} date6_t;
#pragma pack(pop)
@ -157,20 +157,20 @@ static struct cnfparamdescr inppdescr[] = {
{ "structureddataname", eCmdHdlrString, 0},
{ "ruleset", eCmdHdlrString, 0 },
{ "maxlinesatonce", eCmdHdlrInt, 0 },
{ "persiststateinterval", eCmdHdlrInt, 0 },
{ "persiststateinterval", eCmdHdlrInt, 0 },
{ "maxsubmitatonce", eCmdHdlrInt, 0 }
};
static struct cnfparamblk inppblk =
{ CNFPARAMBLK_VERSION,
sizeof(inppdescr)/sizeof(struct cnfparamdescr),
inppdescr
sizeof(inppdescr)/sizeof(struct cnfparamdescr),
inppdescr
};
#include "im-helper.h" /* must be included AFTER the type definitions! */
static uchar * mkFileNameWithTime(instanceConf_t *in)
{
uchar out[MAXFNAME];
uchar out[MAXFNAME];
struct timeval tp;
#if defined(__hpux)
struct timezone tz;
@ -180,7 +180,7 @@ static uchar * mkFileNameWithTime(instanceConf_t *in)
#endif
localtime_r(&tp.tv_sec, &(in->currTm));
snprintf((char*)out, MAXFNAME, "%s.%02d%02d%02d", (char*)in->pszUlogBaseName,
in->currTm.tm_mon+1, in->currTm.tm_mday, in->currTm.tm_year % 100);
in->currTm.tm_mon+1, in->currTm.tm_mday, in->currTm.tm_year % 100);
return ustrdup(out);
}
@ -197,7 +197,7 @@ static int getFullStateFileName(uchar* pszstatefile, uchar* pszout, int ilenout)
/* Construct file name */
lenout = snprintf((char*)pszout, ilenout, "%s/%s",
(char*) (pszworkdir == NULL ? "." : (char*) pszworkdir), (char*)pszstatefile);
(char*) (pszworkdir == NULL ? "." : (char*) pszworkdir), (char*)pszstatefile);
/* return out length */
return lenout;
@ -209,9 +209,9 @@ static int getFullStateFileName(uchar* pszstatefile, uchar* pszout, int ilenout)
* RETURN VALUE!
*/
static uchar * ATTR_NONNULL(2) getStateFileName(instanceConf_t *const __restrict__ pInst,
uchar *const __restrict__ buf,
const size_t lenbuf,
const uchar *pszFileName)
uchar *const __restrict__ buf,
const size_t lenbuf,
const uchar *pszFileName)
{
uchar *ret;
@ -235,121 +235,109 @@ static uchar * ATTR_NONNULL(2) getStateFileName(instanceConf_t *const __restrict
}
static rsRetVal parseMsg(smsg_t *pMsg, char *rawMsg, size_t msgLen,
instanceConf_t *const __restrict__ pInst) {
char *prog, *host, *text, *ecid, *t;
char *newMsg;
int lprog, lcid;
instanceConf_t *const __restrict__ pInst) {
char *prog, *host, *text, *ecid, *t;
char *newMsg;
int lprog, lcid;
dbgprintf("Message will now be parsed.\n");
/*
dbgprintf("Message will now be parsed.\n");
Case 1 :
105211.704.host___!IMSproxiCSFI4EC.26607818.1.0: ECID <000003GBORvD4iopwSXBiW01xG2M00001n>: 4563628752 ; I ;TPSUCCESS service
^host ^prog lprog> ^ecid ^text
host = rawMsg + ((rawMsg[10] == '.') ? 11 : 10);
Case 2 :
011458.705.sic-tst-tmsl1!LMS.5243392.772.3: TSAM_CAT:305: WARN: (23498) times logon TSAM Plus manager fail
^host ^prog lprog> ^text
ecid is ignored in this case
date6_t t1, t2;
t1.ui64 = be64toh(*((uint64_t*)rawMsg)) >> 16;
uint64_t t3 = (t1.ui64 & 0x0000F0F0F0F0F0F0) ^ 0x0000303030303030; /* check that every char is like 0x3N what ever is N */
t2.ui64 = t1.ui64 & 0x00000F0F0F0F0F0F; /* we keep only the n part of 0xMN what ever is M */
*/
host = rawMsg + ((rawMsg[10] == '.') ? 11 : 10);
date6_t t1, t2;
t1.ui64 = be64toh(*((uint64_t*)rawMsg)) >> 16;
uint64_t t3 = (t1.ui64 & 0x0000F0F0F0F0F0F0) ^ 0x0000303030303030; /* check that every char is like 0x3N what ever is N */
t2.ui64 = t1.ui64 & 0x00000F0F0F0F0F0F; /* we keep only the n part of 0xMN what ever is M */
/* so just check that t2 is 0 and each N part is not more than 9 */
if (t3 || t2.UC0 > 9 || t2.UC1 > 9 || t2.UC2 > 9
|| t2.UC3 > 9 || t2.UC4 > 9 || t2.UC5 > 9
|| host[-1] != '.'
|| (prog = memchr(host, '!', msgLen-(host - rawMsg))) == NULL
|| (ecid = memchr(prog, ':', msgLen-(prog - rawMsg))) == NULL)
{
return -2;
}
/* so just check that t2 is 0 and each N part is not more than 9 */
if (t3 || t2.UC0 > 9 || t2.UC1 > 9 || t2.UC2 > 9
|| t2.UC3 > 9 || t2.UC4 > 9 || t2.UC5 > 9
|| host[-1] != '.'
|| (prog = memchr(host, '!', msgLen-(host - rawMsg))) == NULL
|| (ecid = memchr(prog, ':', msgLen-(prog - rawMsg))) == NULL)
{
return -2;
}
pMsg->tTIMESTAMP.year = pInst->currTm.tm_year + 1900;
pMsg->tTIMESTAMP.month = pInst->currTm.tm_mon + 1;
pMsg->tTIMESTAMP.day = pInst->currTm.tm_mday;
pMsg->tTIMESTAMP.hour = t2.UC0 * 10 + t2.UC1;
pMsg->tTIMESTAMP.minute = t2.UC2 * 10 + t2.UC3;
pMsg->tTIMESTAMP.second = t2.UC4 * 10 + t2.UC5;
pMsg->tTIMESTAMP.OffsetMode = syslogTz.OffsetMode;
pMsg->tTIMESTAMP.OffsetHour = syslogTz.OffsetHour;
pMsg->tTIMESTAMP.OffsetMinute = syslogTz.OffsetMinute;
pMsg->tTIMESTAMP.year = pInst->currTm.tm_year + 1900;
pMsg->tTIMESTAMP.month = pInst->currTm.tm_mon + 1;
pMsg->tTIMESTAMP.day = pInst->currTm.tm_mday;
pMsg->tTIMESTAMP.hour = t2.UC0 * 10 + t2.UC1;
pMsg->tTIMESTAMP.minute = t2.UC2 * 10 + t2.UC3;
pMsg->tTIMESTAMP.second = t2.UC4 * 10 + t2.UC5;
pMsg->tTIMESTAMP.OffsetMode = syslogTz.OffsetMode;
pMsg->tTIMESTAMP.OffsetHour = syslogTz.OffsetHour;
pMsg->tTIMESTAMP.OffsetMinute = syslogTz.OffsetMinute;
pMsg->tTIMESTAMP.secfrac = atoi(rawMsg+7);
pMsg->tTIMESTAMP.secfracPrecision = (rawMsg[9]=='.') ? 2 : 3;
pMsg->tTIMESTAMP.secfrac = atoi(rawMsg+7);
pMsg->tTIMESTAMP.secfracPrecision = (rawMsg[9]=='.') ? 2 : 3;
prog++;
prog++;
for (t = ecid; t>prog && *t!='.'; t--)
{}
for (t = ecid; t>prog && *t!='.'; t--)
{}
lprog = t - prog;
lprog = t - prog;
ecid += 2;
ecid += 2;
if (*((uint32_t*)ecid) == ECID && (text = memchr(ecid + 4, ':', msgLen-(ecid-rawMsg)-4)) != NULL)
{
ecid += 6;
lcid = text - ecid - 1;
if (lcid>64) lcid = 64;
text++;
}
else
{
text = ecid;
lcid = 0;
}
if (*((uint32_t*)ecid) == ECID && (text = memchr(ecid + 4, ':', msgLen-(ecid-rawMsg)-4)) != NULL)
{
ecid += 6;
lcid = text - ecid - 1;
if (lcid>64) lcid = 64;
text++;
}
else
{
text = ecid;
lcid = 0;
}
msgLen -= text - rawMsg;
msgLen -= text - rawMsg;
if ((newMsg = (char*)alloca(msgLen)) == NULL)
return -3;
if ((newMsg = (char*)alloca(msgLen)) == NULL)
return -3;
MsgSetHOSTNAME(pMsg, (const uchar*)host, prog - host - 1);
MsgSetHOSTNAME(pMsg, (const uchar*)host, prog - host - 1);
if (lprog > 0)
{
prog[lprog] = '\0';
MsgSetPROCID(pMsg, prog);
}
if (lprog > 0)
{
prog[lprog] = '\0';
MsgSetPROCID(pMsg, prog);
}
if (lcid)
{
int lenSDN;
ecid[lcid] = '\0';
MsgSetMSGID(pMsg, ecid);
if (lcid)
{
int lenSDN;
ecid[lcid] = '\0';
MsgSetMSGID(pMsg, ecid);
uchar *structData;
if (pInst->lenStructuredDataName != 0) {
structData = (uchar*)alloca(lcid + 10 + pInst->lenStructuredDataName);
*structData = '[';
memcpy(structData + 1, pInst->pszStructuredDataName, pInst->lenStructuredDataName);
memcpy(structData + 1 + pInst->lenStructuredDataName, " ECID=\"", 7);
lenSDN = 8 + pInst->lenStructuredDataName;
}else{
structData = (uchar*)alloca(lcid+11);
memcpy(structData, "[M ECID=\"", 9);
lenSDN = 9;
}
memcpy(structData+lenSDN, ecid, lcid);
structData[lenSDN+lcid]=(uchar)'\"';
structData[lenSDN+lcid]=(uchar)']';
uchar *structData;
if (pInst->lenStructuredDataName != 0) {
structData = (uchar*)alloca(lcid + 10 + pInst->lenStructuredDataName);
*structData = '[';
memcpy(structData + 1, pInst->pszStructuredDataName, pInst->lenStructuredDataName);
memcpy(structData + 1 + pInst->lenStructuredDataName, " ECID=\"", 7);
lenSDN = 8 + pInst->lenStructuredDataName;
}else{
structData = (uchar*)alloca(lcid+11);
memcpy(structData, "[M ECID=\"", 9);
lenSDN = 9;
}
memcpy(structData+lenSDN, ecid, lcid);
structData[lenSDN+lcid]=(uchar)'\"';
structData[lenSDN+lcid]=(uchar)']';
MsgAddToStructuredData(pMsg, structData, lenSDN + lcid + 2);
}
MsgAddToStructuredData(pMsg, structData, lenSDN + lcid + 2);
}
memcpy(newMsg, text, msgLen);
MsgSetRawMsg(pMsg, newMsg, msgLen);
MsgSetMSGoffs(pMsg, 0);
memcpy(newMsg, text, msgLen);
MsgSetRawMsg(pMsg, newMsg, msgLen);
MsgSetMSGoffs(pMsg, 0);
return 0;
return 0;
}
/* enqueue the read file line as a message. The provided string is
@ -371,13 +359,13 @@ static rsRetVal enqLine(instanceConf_t *const __restrict__ pInst,
CHKiRet(msgConstruct(&pMsg));
if (parseMsg(pMsg, (char*)rsCStrGetSzStrNoNULL(cstrLine), msgLen, pInst)) {
msgDestruct(&pMsg);
FINALIZE;
msgDestruct(&pMsg);
FINALIZE;
}
MsgSetFlowControlType(pMsg, eFLOWCTL_FULL_DELAY);
MsgSetInputName(pMsg, pInputName);
MsgSetAPPNAME(pMsg, (const char*)pInst->pszTag);
MsgSetAPPNAME(pMsg, (const char*)pInst->pszTag);
MsgSetTAG(pMsg, pInst->pszTag, pInst->lenTag);
msgSetPRI(pMsg, pInst->iFacility | pInst->iSeverity);
MsgSetRuleset(pMsg, pInst->pBindRuleset);
@ -401,7 +389,7 @@ static rsRetVal ATTR_NONNULL(1) openFileWithStateFile(instanceConf_t *const __re
uchar *const statefn = getStateFileName(pInst, statefile, sizeof(statefile), NULL);
DBGPRINTF("trying to open state for '%s', state file '%s'\n",
pInst->pszUlogBaseName, statefn);
pInst->pszUlogBaseName, statefn);
/* Get full path and file name */
lenSFNam = getFullStateFileName(statefn, pszSFNam, sizeof(pszSFNam));
@ -415,7 +403,7 @@ static rsRetVal ATTR_NONNULL(1) openFileWithStateFile(instanceConf_t *const __re
char errStr[1024];
rs_strerror_r(errno, errStr, sizeof(errStr));
DBGPRINTF("error trying to access state file for '%s':%s\n",
pInst->pszUlogBaseName, errStr);
pInst->pszUlogBaseName, errStr);
ABORT_FINALIZE(RS_RET_IO_ERROR);
}
}
@ -432,16 +420,16 @@ static rsRetVal ATTR_NONNULL(1) openFileWithStateFile(instanceConf_t *const __re
/* read back in the object */
CHKiRet(obj.Deserialize(&pInst->pStrm, (uchar*) "strm", psSF, NULL, pInst));
DBGPRINTF("deserialized state file, state file base name '%s', "
"configured base name '%s'\n", pInst->pStrm->pszFName,
pInst->pszUlogBaseName);
"configured base name '%s'\n", pInst->pStrm->pszFName,
pInst->pszUlogBaseName);
if(ustrcmp(pInst->pStrm->pszFName, pInst->pszCurrFName)) {
LogError(0, RS_RET_STATEFILE_WRONG_FNAME, "imtuxedoulog: state file '%s' "
"contains file name '%s', but is used for file '%s'. State "
"file deleted, starting from begin of file.",
pszSFNam, pInst->pStrm->pszFName, pInst->pszCurrFName);
LogError(0, RS_RET_STATEFILE_WRONG_FNAME, "imtuxedoulog: state file '%s' "
"contains file name '%s', but is used for file '%s'. State "
"file deleted, starting from begin of file.",
pszSFNam, pInst->pStrm->pszFName, pInst->pszCurrFName);
unlink((char*)pszSFNam);
ABORT_FINALIZE(RS_RET_STATEFILE_WRONG_FNAME);
unlink((char*)pszSFNam);
ABORT_FINALIZE(RS_RET_STATEFILE_WRONG_FNAME);
}
strm.CheckFileChange(pInst->pStrm);
@ -504,41 +492,41 @@ finalize_it:
*/
static rsRetVal persistStrmState(instanceConf_t *pInst)
{
DEFiRet;
strm_t *psSF = NULL; /* state file (stream) */
size_t lenDir;
uchar statefile[MAXFNAME];
DEFiRet;
strm_t *psSF = NULL; /* state file (stream) */
size_t lenDir;
uchar statefile[MAXFNAME];
uchar *const statefn = getStateFileName(pInst, statefile, sizeof(statefile), NULL);
DBGPRINTF("persisting state for '%s' to file '%s'\n",
pInst->pszUlogBaseName, statefn);
CHKiRet(strm.Construct(&psSF));
lenDir = ustrlen(glbl.GetWorkDir());
if(lenDir > 0)
CHKiRet(strm.SetDir(psSF, glbl.GetWorkDir(), lenDir));
CHKiRet(strm.SettOperationsMode(psSF, STREAMMODE_WRITE_TRUNC));
CHKiRet(strm.SetsType(psSF, STREAMTYPE_FILE_SINGLE));
CHKiRet(strm.SetFName(psSF, statefn, strlen((char*) statefn)));
CHKiRet(strm.SetFileNotFoundError(psSF, 1));
CHKiRet(strm.ConstructFinalize(psSF));
uchar *const statefn = getStateFileName(pInst, statefile, sizeof(statefile), NULL);
DBGPRINTF("persisting state for '%s' to file '%s'\n",
pInst->pszUlogBaseName, statefn);
CHKiRet(strm.Construct(&psSF));
lenDir = ustrlen(glbl.GetWorkDir());
if(lenDir > 0)
CHKiRet(strm.SetDir(psSF, glbl.GetWorkDir(), lenDir));
CHKiRet(strm.SettOperationsMode(psSF, STREAMMODE_WRITE_TRUNC));
CHKiRet(strm.SetsType(psSF, STREAMTYPE_FILE_SINGLE));
CHKiRet(strm.SetFName(psSF, statefn, strlen((char*) statefn)));
CHKiRet(strm.SetFileNotFoundError(psSF, 1));
CHKiRet(strm.ConstructFinalize(psSF));
CHKiRet(strm.Serialize(pInst->pStrm, psSF));
CHKiRet(strm.Flush(psSF));
CHKiRet(strm.Serialize(pInst->pStrm, psSF));
CHKiRet(strm.Flush(psSF));
CHKiRet(strm.Destruct(&psSF));
CHKiRet(strm.Destruct(&psSF));
finalize_it:
if(psSF != NULL)
strm.Destruct(&psSF);
if(psSF != NULL)
strm.Destruct(&psSF);
if(iRet != RS_RET_OK) {
LogError(0, iRet, "imtuxedoulog: could not persist state "
"file %s - data may be repeated on next "
"startup. Is WorkDirectory set?",
statefn);
}
if(iRet != RS_RET_OK) {
LogError(0, iRet, "imtuxedoulog: could not persist state "
"file %s - data may be repeated on next "
"startup. Is WorkDirectory set?",
statefn);
}
RETiRet;
RETiRet;
}
/* The following is a cancel cleanup handler for strmReadLine(). It is necessary in case
@ -566,7 +554,7 @@ static rsRetVal ATTR_NONNULL(1, 3) pollFileReal(instanceConf_t *pInst, int *pbHa
while(glbl.GetGlobalInputTermState() == 0) {
if(pInst->maxLinesAtOnce != 0 && nProcessed >= pInst->maxLinesAtOnce)
break;
CHKiRet(strm.ReadLine(pInst->pStrm, pCStr, 0, 0, -1, NULL));
CHKiRet(strm.ReadLine(pInst->pStrm, pCStr, 0, 0, -1, NULL));
++nProcessed;
if(pbHadFileData != NULL)
*pbHadFileData = 1; /* this is just a flag, so set it and forget it */
@ -616,7 +604,7 @@ static rsRetVal ATTR_NONNULL(1) createInstance(instanceConf_t **const pinst)
inst->ratelimiter = NULL;
inst->pszBindRuleset = NULL;
inst->pszUlogBaseName = NULL;
inst->pszUlogBaseName = NULL;
inst->pszCurrFName = NULL;
inst->pszTag = NULL;
inst->pszStructuredDataName = NULL;
@ -668,19 +656,19 @@ int ATTR_NONNULL() getBasename(uchar *const __restrict__ basen, uchar *const __r
static rsRetVal ATTR_NONNULL() lstnAdd(instanceConf_t *pInst)
{
DEFiRet;
CHKiRet(ratelimitNew(&pInst->ratelimiter, "imtuxedoulog", (char*)pInst->pszUlogBaseName));
CHKmalloc(pInst->multiSub.ppMsgs = malloc(pInst->nMultiSub * sizeof(smsg_t *)));
pInst->multiSub.maxElem = pInst->nMultiSub;
pInst->multiSub.nElem = 0;
CHKiRet(ratelimitNew(&pInst->ratelimiter, "imtuxedoulog", (char*)pInst->pszUlogBaseName));
CHKmalloc(pInst->multiSub.ppMsgs = malloc(pInst->nMultiSub * sizeof(smsg_t *)));
pInst->multiSub.maxElem = pInst->nMultiSub;
pInst->multiSub.nElem = 0;
/* insert it at the begin of the list */
pInst->prev = NULL;
pInst->next = confRoot;
pInst->next = confRoot;
if (confRoot != NULL)
confRoot->prev = pInst;
if (confRoot != NULL)
confRoot->prev = pInst;
confRoot = pInst;
confRoot = pInst;
finalize_it:
RETiRet;
@ -695,21 +683,21 @@ void ATTR_NONNULL(1) lstnDel(instanceConf_t *pInst)
strm.Destruct(&(pInst->pStrm));
}
if (pInst->ratelimiter != NULL)
ratelimitDestruct(pInst->ratelimiter);
ratelimitDestruct(pInst->ratelimiter);
if (pInst->multiSub.ppMsgs != NULL)
free(pInst->multiSub.ppMsgs);
free(pInst->multiSub.ppMsgs);
free(pInst->pszUlogBaseName);
if (pInst->pszCurrFName != NULL)
free(pInst->pszCurrFName);
if (pInst->pszTag)
free(pInst->pszTag);
if (pInst->pszStructuredDataName)
free(pInst->pszStructuredDataName);
free(pInst->pszUlogBaseName);
if (pInst->pszCurrFName != NULL)
free(pInst->pszCurrFName);
if (pInst->pszTag)
free(pInst->pszTag);
if (pInst->pszStructuredDataName)
free(pInst->pszStructuredDataName);
if (pInst->pszStateFile)
free(pInst->pszStateFile);
if (pInst->pszBindRuleset != NULL)
free(pInst->pszBindRuleset);
free(pInst->pszStateFile);
if (pInst->pszBindRuleset != NULL)
free(pInst->pszBindRuleset);
free(pInst);
}
@ -718,7 +706,7 @@ void ATTR_NONNULL(1) lstnDel(instanceConf_t *pInst)
static rsRetVal do_polling(void)
{
int bHadFileData; /* were there at least one file with data during this run? */
struct stat sb;
struct stat sb;
DEFiRet;
while(glbl.GetGlobalInputTermState() == 0) {
do {
@ -727,36 +715,36 @@ static rsRetVal do_polling(void)
for(pInst = confRoot ; pInst != NULL ; pInst = pInst->next) {
uchar *temp = mkFileNameWithTime(pInst);
DBGPRINTF("imtuxedoulog: do_polling start '%s' / '%s'\n", pInst->pszUlogBaseName, temp);
/*
* Is the file name is different : a rotation time is reached
* If so, then it the new file exists ? and is a file ?
*/
if (temp && stat((const char*)temp, &sb) == 0 && S_ISREG(sb.st_mode) &&
(pInst->pszCurrFName == NULL || strcmp((char*)temp, (char*)pInst->pszCurrFName) != 0))
{
DBGPRINTF("imtuxedoulog: timed file : rotation reach switching form '%s' to '%s' !",
(char*)pInst->pszUlogBaseName, temp );
DBGPRINTF("imtuxedoulog: do_polling start '%s' / '%s'\n", pInst->pszUlogBaseName, temp);
/*
* Is the file name is different : a rotation time is reached
* If so, then it the new file exists ? and is a file ?
*/
if (temp && stat((const char*)temp, &sb) == 0 && S_ISREG(sb.st_mode) &&
(pInst->pszCurrFName == NULL || strcmp((char*)temp, (char*)pInst->pszCurrFName) != 0))
{
DBGPRINTF("imtuxedoulog: timed file : rotation reach switching form '%s' to '%s' !",
(char*)pInst->pszUlogBaseName, temp );
/* first of all change the listener datas */
if (pInst->pszCurrFName != NULL) {
free(pInst->pszCurrFName);
strm.Destruct(&pInst->pStrm);
}
pInst->pszCurrFName = temp;
temp = NULL;
/* first of all change the listener datas */
if (pInst->pszCurrFName != NULL) {
free(pInst->pszCurrFName);
strm.Destruct(&pInst->pStrm);
}
pInst->pszCurrFName = temp;
temp = NULL;
/* And finish by destroy the stream object, so the next polling will recreate
* it based on new data.
*/
if(glbl.GetGlobalInputTermState() == 1)
break; /* terminate input! */
}
if (temp) free(temp);
/* And finish by destroy the stream object, so the next polling will recreate
* it based on new data.
*/
if(glbl.GetGlobalInputTermState() == 1)
break; /* terminate input! */
}
if (temp) free(temp);
/* let's poll the new file immediately */
if (pInst->pszCurrFName != NULL)
pollFile(pInst, &bHadFileData);
/* let's poll the new file immediately */
if (pInst->pszCurrFName != NULL)
pollFile(pInst, &bHadFileData);
DBGPRINTF("imtuxedoulog: do_polling end for '%s'\n", pInst->pszUlogBaseName);
if (pInst->iPersistStateInterval == -1)
@ -820,7 +808,7 @@ CODESTARTnewInpInst
inst->nMultiSub = pvals[i].val.d.n;
} else {
DBGPRINTF("program error, non-handled "
"param '%s'\n", inppblk.descr[i].name);
"param '%s'\n", inppblk.descr[i].name);
}
}
if(inst->pszUlogBaseName == NULL) {
@ -830,8 +818,8 @@ CODESTARTnewInpInst
}
if ((iRet = lstnAdd(inst)) != RS_RET_OK) {
lstnDel(inst);
ABORT_FINALIZE(iRet);
lstnDel(inst);
ABORT_FINALIZE(iRet);
}
finalize_it:
@ -841,7 +829,7 @@ ENDnewInpInst
BEGINbeginCnfLoad
CODESTARTbeginCnfLoad
pModConf->pConf = pConf;
pModConf->pConf = pConf;
ENDbeginCnfLoad
BEGINendCnfLoad
@ -851,9 +839,9 @@ ENDendCnfLoad
BEGINcheckCnf
instanceConf_t *inst;
CODESTARTcheckCnf
for(inst = confRoot ; inst != NULL ; inst = inst->next) {
std_checkRuleset(pModConf , inst);
}
for(inst = confRoot ; inst != NULL ; inst = inst->next) {
std_checkRuleset(pModConf , inst);
}
ENDcheckCnf
BEGINactivateCnf
@ -900,8 +888,8 @@ ENDwillRun
BEGINafterRun
CODESTARTafterRun
while(confRoot != NULL) {
instanceConf_t *inst = confRoot;
confRoot = confRoot->next;
instanceConf_t *inst = confRoot;
confRoot = confRoot->next;
lstnDel(inst);
}

View File

@ -143,33 +143,33 @@ CODESTARTparse2
pMsg->tTIMESTAMP.OffsetHour = tz / 60;
pMsg->tTIMESTAMP.OffsetMinute = tz % 60;
pid = (char*)pMsg->pszRawMsg + pInst->levelpos + levels_len[i] + 11;
if (pid>=end) ABORT_FINALIZE(0);
lpid = strchr(pid, ' ') - pid;
pid = (char*)pMsg->pszRawMsg + pInst->levelpos + levels_len[i] + 11;
if (pid>=end) ABORT_FINALIZE(0);
lpid = strchr(pid, ' ') - pid;
prog = pid + 49;
if (prog>=end) ABORT_FINALIZE(0);
prog = pid + 49;
if (prog>=end) ABORT_FINALIZE(0);
e = strchr(prog, ' ');
if (e && e>=end) ABORT_FINALIZE(0);
e = strchr(prog, ' ');
if (e && e>=end) ABORT_FINALIZE(0);
f = strchr(prog, '\\');
if (!f || f>=end) ABORT_FINALIZE(0);
f = strchr(prog, '\\');
if (!f || f>=end) ABORT_FINALIZE(0);
lprog = (e && e<f) ? e-prog : f-prog;
lprog = (CONF_PROGNAME_BUFSIZE-1 < lprog) ? CONF_PROGNAME_BUFSIZE-1 : lprog;
lprog = (e && e<f) ? e-prog : f-prog;
lprog = (CONF_PROGNAME_BUFSIZE-1 < lprog) ? CONF_PROGNAME_BUFSIZE-1 : lprog;
strncpy((char*)pMsg->PROGNAME.szBuf, prog, lprog);
pMsg->PROGNAME.szBuf[lprog] = '\0';
strncpy((char*)pMsg->PROGNAME.szBuf, prog, lprog);
pMsg->PROGNAME.szBuf[lprog] = '\0';
snprintf(procid, 128, "%.*s.%.*s", lprog, prog, lpid, pid);
MsgSetPROCID(pMsg, procid);
snprintf(procid, 128, "%.*s.%.*s", lprog, prog, lpid, pid);
MsgSetPROCID(pMsg, procid);
pProp.id = PROP_SYSLOGTAG;
val = (char*)MsgGetProp(pMsg, NULL, &pProp, &valLen, &mustBeFreed, NULL);
MsgSetAPPNAME(pMsg, val);
if (mustBeFreed)
free(val);
pProp.id = PROP_SYSLOGTAG;
val = (char*)MsgGetProp(pMsg, NULL, &pProp, &valLen, &mustBeFreed, NULL);
MsgSetAPPNAME(pMsg, val);
if (mustBeFreed)
free(val);
}
finalize_it:

View File

@ -790,7 +790,7 @@ finalize_it:
static void
PrintAllowedSenders(int iListToPrint)
{
static char *SENDER_TEXT[] = { "", "UDP", "TCP", "GSS" };
static const char *SENDER_TEXT[] = { "", "UDP", "TCP", "GSS" };
struct AllowedSenders *pSender;
uchar szIP[64];
#ifdef USE_GSSAPI
@ -815,8 +815,8 @@ PrintAllowedSenders(int iListToPrint)
dbgprintf ("\t%s\n", pSender->allowedSender.addr.HostWildcard);
else {
if(mygetnameinfo (pSender->allowedSender.addr.NetAddr,
SALEN(pSender->allowedSender.addr.NetAddr),
(char*)szIP, 64, NULL, 0, NI_NUMERICHOST) == 0) {
SALEN(pSender->allowedSender.addr.NetAddr),
(char*)szIP, 64, NULL, 0, NI_NUMERICHOST) == 0) {
dbgprintf ("\t%s/%u\n", szIP, pSender->SignificantBits);
} else {
/* getnameinfo() failed - but as this is only a