mirror of
https://github.com/rsyslog/rsyslog.git
synced 2025-12-21 20:40:42 +01:00
omhiredis: error checking changes and code cleanup
This commit is contained in:
parent
2a0fb1f755
commit
9ac054305a
@ -62,11 +62,11 @@ static struct cnfparamdescr actpdescr[] = {
|
|||||||
{ "serverport", eCmdHdlrInt, 0 },
|
{ "serverport", eCmdHdlrInt, 0 },
|
||||||
{ "template", eCmdHdlrGetWord, 1 }
|
{ "template", eCmdHdlrGetWord, 1 }
|
||||||
};
|
};
|
||||||
static struct cnfparamblk actpblk =
|
static struct cnfparamblk actpblk = {
|
||||||
{ CNFPARAMBLK_VERSION,
|
CNFPARAMBLK_VERSION,
|
||||||
sizeof(actpdescr)/sizeof(struct cnfparamdescr),
|
sizeof(actpdescr)/sizeof(struct cnfparamdescr),
|
||||||
actpdescr
|
actpdescr
|
||||||
};
|
};
|
||||||
|
|
||||||
BEGINcreateInstance
|
BEGINcreateInstance
|
||||||
CODESTARTcreateInstance
|
CODESTARTcreateInstance
|
||||||
@ -127,13 +127,12 @@ rsRetVal writeHiredis(uchar *message, instanceData *pData)
|
|||||||
redisReply *reply;
|
redisReply *reply;
|
||||||
DEFiRet;
|
DEFiRet;
|
||||||
|
|
||||||
if(pData->conn == NULL) {
|
if(pData->conn == NULL)
|
||||||
CHKiRet(initHiredis(pData, 0));
|
CHKiRet(initHiredis(pData, 0));
|
||||||
}
|
|
||||||
|
|
||||||
reply = redisCommand(pData->conn, (char*)message);
|
reply = redisCommand(pData->conn, (char*)message);
|
||||||
if (!reply->integer) {
|
if (reply->type == REDIS_REPLY_ERROR) {
|
||||||
char errStr[1024];
|
char errStr = reply->str;
|
||||||
DBGPRINTF("omhiredis: redisCommand error: %s",
|
DBGPRINTF("omhiredis: redisCommand error: %s",
|
||||||
rs_strerror_r(errno, errStr, sizeof(errStr)));
|
rs_strerror_r(errno, errStr, sizeof(errStr)));
|
||||||
freeReplyObject(reply);
|
freeReplyObject(reply);
|
||||||
@ -142,16 +141,14 @@ rsRetVal writeHiredis(uchar *message, instanceData *pData)
|
|||||||
freeReplyObject(reply);
|
freeReplyObject(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
finalize_it:
|
finalize_it:
|
||||||
RETiRet;
|
RETiRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
BEGINtryResume
|
BEGINtryResume
|
||||||
CODESTARTtryResume
|
CODESTARTtryResume
|
||||||
if(pData->conn == NULL) {
|
if(pData->conn == NULL)
|
||||||
iRet = initHiredis(pData, 1);
|
iRet = initHiredis(pData, 1);
|
||||||
}
|
|
||||||
ENDtryResume
|
ENDtryResume
|
||||||
|
|
||||||
BEGINdoAction
|
BEGINdoAction
|
||||||
@ -172,9 +169,8 @@ BEGINnewActInst
|
|||||||
struct cnfparamvals *pvals;
|
struct cnfparamvals *pvals;
|
||||||
int i;
|
int i;
|
||||||
CODESTARTnewActInst
|
CODESTARTnewActInst
|
||||||
if((pvals = nvlstGetParams(lst, &actpblk, NULL)) == NULL) {
|
if((pvals = nvlstGetParams(lst, &actpblk, NULL)) == NULL)
|
||||||
ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS);
|
ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS);
|
||||||
}
|
|
||||||
|
|
||||||
CHKiRet(createInstance(&pData));
|
CHKiRet(createInstance(&pData));
|
||||||
setInstParamDefaults(pData);
|
setInstParamDefaults(pData);
|
||||||
@ -183,6 +179,7 @@ CODESTARTnewActInst
|
|||||||
for(i = 0 ; i < actpblk.nParams ; ++i) {
|
for(i = 0 ; i < actpblk.nParams ; ++i) {
|
||||||
if(!pvals[i].bUsed)
|
if(!pvals[i].bUsed)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(!strcmp(actpblk.descr[i].name, "server")) {
|
if(!strcmp(actpblk.descr[i].name, "server")) {
|
||||||
pData->server = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL);
|
pData->server = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL);
|
||||||
} else if(!strcmp(actpblk.descr[i].name, "serverport")) {
|
} else if(!strcmp(actpblk.descr[i].name, "serverport")) {
|
||||||
@ -213,11 +210,10 @@ CODESTARTparseSelectorAct
|
|||||||
|
|
||||||
/* tell the engine we only want one template string */
|
/* tell the engine we only want one template string */
|
||||||
CODE_STD_STRING_REQUESTparseSelectorAct(1)
|
CODE_STD_STRING_REQUESTparseSelectorAct(1)
|
||||||
if(!strncmp((char*) p, ":omhiredis:", sizeof(":omhiredis:") - 1)) {
|
if(!strncmp((char*) p, ":omhiredis:", sizeof(":omhiredis:") - 1))
|
||||||
errmsg.LogError(0, RS_RET_LEGA_ACT_NOT_SUPPORTED,
|
errmsg.LogError(0, RS_RET_LEGA_ACT_NOT_SUPPORTED,
|
||||||
"omhiredis supports only v6 config format, use: "
|
"omhiredis supports only v6 config format, use: "
|
||||||
"action(type=\"omhiredis\" server=...)");
|
"action(type=\"omhiredis\" server=...)");
|
||||||
}
|
|
||||||
ABORT_FINALIZE(RS_RET_CONFLINE_UNPROCESSED);
|
ABORT_FINALIZE(RS_RET_CONFLINE_UNPROCESSED);
|
||||||
CODE_STD_FINALIZERparseSelectorAct
|
CODE_STD_FINALIZERparseSelectorAct
|
||||||
ENDparseSelectorAct
|
ENDparseSelectorAct
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user