CLEANUP: lua: Merge log functions
All the code which emits error log have the same pattern. Its: Send log with syslog system, and if it is allowed, display error log on screen. This patch replace this pattern by a macro. This reduces the number of lines.
This commit is contained in:
parent
007ff4ce0f
commit
23bc375c59
111
src/hlua.c
111
src/hlua.c
|
@ -138,6 +138,13 @@ static int hlua_smp2lua(lua_State *L, struct sample *smp);
|
|||
static int hlua_smp2lua_str(lua_State *L, struct sample *smp);
|
||||
static int hlua_lua2smp(lua_State *L, int ud, struct sample *smp);
|
||||
|
||||
#define SEND_ERR(__be, __fmt, __args...) \
|
||||
do { \
|
||||
send_log(__be, LOG_ERR, __fmt, ## __args); \
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) \
|
||||
Alert(__fmt, ## __args); \
|
||||
} while (0)
|
||||
|
||||
/* Used to check an Lua function type in the stack. It creates and
|
||||
* returns a reference of the function. This function throws an
|
||||
* error if the rgument is not a "function".
|
||||
|
@ -3874,9 +3881,7 @@ static struct task *hlua_process_task(struct task *task)
|
|||
|
||||
/* finished with error. */
|
||||
case HLUA_E_ERRMSG:
|
||||
send_log(NULL, LOG_ERR, "Lua task: %s.\n", lua_tostring(hlua->T, -1));
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua task: %s.\n", lua_tostring(hlua->T, -1));
|
||||
SEND_ERR(NULL, "Lua task: %s.\n", lua_tostring(hlua->T, -1));
|
||||
hlua_ctx_destroy(hlua);
|
||||
task_delete(task);
|
||||
task_free(task);
|
||||
|
@ -3884,9 +3889,7 @@ static struct task *hlua_process_task(struct task *task)
|
|||
|
||||
case HLUA_E_ERR:
|
||||
default:
|
||||
send_log(NULL, LOG_ERR, "Lua task: unknown error.\n");
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua task: unknown error.\n");
|
||||
SEND_ERR(NULL, "Lua task: unknown error.\n");
|
||||
hlua_ctx_destroy(hlua);
|
||||
task_delete(task);
|
||||
task_free(task);
|
||||
|
@ -3974,9 +3977,7 @@ static int hlua_sample_conv_wrapper(const struct arg *arg_p, struct sample *smp,
|
|||
* Lua initialization cause 5% performances loss.
|
||||
*/
|
||||
if (!stream->hlua.T && !hlua_ctx_init(&stream->hlua, stream->task)) {
|
||||
send_log(stream->be, LOG_ERR, "Lua converter '%s': can't initialize Lua context.\n", fcn->name);
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua converter '%s': can't initialize Lua context.\n", fcn->name);
|
||||
SEND_ERR(stream->be, "Lua converter '%s': can't initialize Lua context.\n", fcn->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -3984,9 +3985,7 @@ static int hlua_sample_conv_wrapper(const struct arg *arg_p, struct sample *smp,
|
|||
if (!HLUA_IS_RUNNING(&stream->hlua)) {
|
||||
/* Check stack available size. */
|
||||
if (!lua_checkstack(stream->hlua.T, 1)) {
|
||||
send_log(stream->be, LOG_ERR, "Lua converter '%s': full stack.\n", fcn->name);
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua converter '%s': full stack.\n", fcn->name);
|
||||
SEND_ERR(stream->be, "Lua converter '%s': full stack.\n", fcn->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -3995,9 +3994,7 @@ static int hlua_sample_conv_wrapper(const struct arg *arg_p, struct sample *smp,
|
|||
|
||||
/* convert input sample and pust-it in the stack. */
|
||||
if (!lua_checkstack(stream->hlua.T, 1)) {
|
||||
send_log(stream->be, LOG_ERR, "Lua converter '%s': full stack.\n", fcn->name);
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua converter '%s': full stack.\n", fcn->name);
|
||||
SEND_ERR(stream->be, "Lua converter '%s': full stack.\n", fcn->name);
|
||||
return 0;
|
||||
}
|
||||
hlua_smp2lua(stream->hlua.T, smp);
|
||||
|
@ -4007,9 +4004,7 @@ static int hlua_sample_conv_wrapper(const struct arg *arg_p, struct sample *smp,
|
|||
if (arg_p) {
|
||||
for (; arg_p->type != ARGT_STOP; arg_p++) {
|
||||
if (!lua_checkstack(stream->hlua.T, 1)) {
|
||||
send_log(stream->be, LOG_ERR, "Lua converter '%s': full stack.\n", fcn->name);
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua converter '%s': full stack.\n", fcn->name);
|
||||
SEND_ERR(stream->be, "Lua converter '%s': full stack.\n", fcn->name);
|
||||
return 0;
|
||||
}
|
||||
hlua_arg2lua(stream->hlua.T, arg_p);
|
||||
|
@ -4035,25 +4030,20 @@ static int hlua_sample_conv_wrapper(const struct arg *arg_p, struct sample *smp,
|
|||
|
||||
/* yield. */
|
||||
case HLUA_E_AGAIN:
|
||||
send_log(stream->be, LOG_ERR, "Lua converter '%s': cannot use yielded functions.\n", fcn->name);
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua converter '%s': cannot use yielded functions.\n", fcn->name);
|
||||
SEND_ERR(stream->be, "Lua converter '%s': cannot use yielded functions.\n", fcn->name);
|
||||
return 0;
|
||||
|
||||
/* finished with error. */
|
||||
case HLUA_E_ERRMSG:
|
||||
/* Display log. */
|
||||
send_log(stream->be, LOG_ERR, "Lua converter '%s': %s.\n", fcn->name, lua_tostring(stream->hlua.T, -1));
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua converter '%s': %s.\n", fcn->name, lua_tostring(stream->hlua.T, -1));
|
||||
SEND_ERR(stream->be, "Lua converter '%s': %s.\n",
|
||||
fcn->name, lua_tostring(stream->hlua.T, -1));
|
||||
lua_pop(stream->hlua.T, 1);
|
||||
return 0;
|
||||
|
||||
case HLUA_E_ERR:
|
||||
/* Display log. */
|
||||
send_log(stream->be, LOG_ERR, "Lua converter '%s' returns an unknown error.\n", fcn->name);
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua converter '%s' returns an unknown error.\n", fcn->name);
|
||||
SEND_ERR(stream->be, "Lua converter '%s' returns an unknown error.\n", fcn->name);
|
||||
|
||||
default:
|
||||
return 0;
|
||||
|
@ -4076,9 +4066,7 @@ static int hlua_sample_fetch_wrapper(const struct arg *arg_p, struct sample *smp
|
|||
* Lua initialization cause 5% performances loss.
|
||||
*/
|
||||
if (!stream->hlua.T && !hlua_ctx_init(&stream->hlua, stream->task)) {
|
||||
send_log(stream->be, LOG_ERR, "Lua sample-fetch '%s': can't initialize Lua context.\n", fcn->name);
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua sample-fetch '%s': can't initialize Lua context.\n", fcn->name);
|
||||
SEND_ERR(stream->be, "Lua sample-fetch '%s': can't initialize Lua context.\n", fcn->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -4086,9 +4074,7 @@ static int hlua_sample_fetch_wrapper(const struct arg *arg_p, struct sample *smp
|
|||
if (!HLUA_IS_RUNNING(&stream->hlua)) {
|
||||
/* Check stack available size. */
|
||||
if (!lua_checkstack(stream->hlua.T, 2)) {
|
||||
send_log(smp->px, LOG_ERR, "Lua sample-fetch '%s': full stack.\n", fcn->name);
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua sample-fetch '%s': full stack.\n", fcn->name);
|
||||
SEND_ERR(smp->px, "Lua sample-fetch '%s': full stack.\n", fcn->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -4097,9 +4083,7 @@ static int hlua_sample_fetch_wrapper(const struct arg *arg_p, struct sample *smp
|
|||
|
||||
/* push arguments in the stack. */
|
||||
if (!hlua_txn_new(stream->hlua.T, stream, smp->px)) {
|
||||
send_log(smp->px, LOG_ERR, "Lua sample-fetch '%s': full stack.\n", fcn->name);
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua sample-fetch '%s': full stack.\n", fcn->name);
|
||||
SEND_ERR(smp->px, "Lua sample-fetch '%s': full stack.\n", fcn->name);
|
||||
return 0;
|
||||
}
|
||||
stream->hlua.nargs = 1;
|
||||
|
@ -4108,15 +4092,11 @@ static int hlua_sample_fetch_wrapper(const struct arg *arg_p, struct sample *smp
|
|||
for (; arg_p && arg_p->type != ARGT_STOP; arg_p++) {
|
||||
/* Check stack available size. */
|
||||
if (!lua_checkstack(stream->hlua.T, 1)) {
|
||||
send_log(smp->px, LOG_ERR, "Lua sample-fetch '%s': full stack.\n", fcn->name);
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua sample-fetch '%s': full stack.\n", fcn->name);
|
||||
SEND_ERR(smp->px, "Lua sample-fetch '%s': full stack.\n", fcn->name);
|
||||
return 0;
|
||||
}
|
||||
if (!lua_checkstack(stream->hlua.T, 1)) {
|
||||
send_log(smp->px, LOG_ERR, "Lua sample-fetch '%s': full stack.\n", fcn->name);
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua sample-fetch '%s': full stack.\n", fcn->name);
|
||||
SEND_ERR(smp->px, "Lua sample-fetch '%s': full stack.\n", fcn->name);
|
||||
return 0;
|
||||
}
|
||||
hlua_arg2lua(stream->hlua.T, arg_p);
|
||||
|
@ -4144,25 +4124,20 @@ static int hlua_sample_fetch_wrapper(const struct arg *arg_p, struct sample *smp
|
|||
|
||||
/* yield. */
|
||||
case HLUA_E_AGAIN:
|
||||
send_log(smp->px, LOG_ERR, "Lua sample-fetch '%s': cannot use yielded functions.\n", fcn->name);
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua sample-fetch '%s': cannot use yielded functions.\n", fcn->name);
|
||||
SEND_ERR(smp->px, "Lua sample-fetch '%s': cannot use yielded functions.\n", fcn->name);
|
||||
return 0;
|
||||
|
||||
/* finished with error. */
|
||||
case HLUA_E_ERRMSG:
|
||||
/* Display log. */
|
||||
send_log(smp->px, LOG_ERR, "Lua sample-fetch '%s': %s.\n", fcn->name, lua_tostring(stream->hlua.T, -1));
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua sample-fetch '%s': %s.\n", fcn->name, lua_tostring(stream->hlua.T, -1));
|
||||
SEND_ERR(smp->px, "Lua sample-fetch '%s': %s.\n",
|
||||
fcn->name, lua_tostring(stream->hlua.T, -1));
|
||||
lua_pop(stream->hlua.T, 1);
|
||||
return 0;
|
||||
|
||||
case HLUA_E_ERR:
|
||||
/* Display log. */
|
||||
send_log(smp->px, LOG_ERR, "Lua sample-fetch '%s' returns an unknown error.\n", fcn->name);
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua sample-fetch '%s': returns an unknown error.\n", fcn->name);
|
||||
SEND_ERR(smp->px, "Lua sample-fetch '%s' returns an unknown error.\n", fcn->name);
|
||||
|
||||
default:
|
||||
return 0;
|
||||
|
@ -4308,9 +4283,7 @@ static enum act_return hlua_action(struct act_rule *rule, struct proxy *px,
|
|||
case ACT_F_HTTP_REQ: analyzer = AN_REQ_HTTP_PROCESS_FE; break;
|
||||
case ACT_F_HTTP_RES: analyzer = AN_RES_HTTP_PROCESS_BE; break;
|
||||
default:
|
||||
send_log(px, LOG_ERR, "Lua: internal error while execute action.\n");
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua: internal error while execute action.\n");
|
||||
SEND_ERR(px, "Lua: internal error while execute action.\n");
|
||||
return ACT_RET_CONT;
|
||||
}
|
||||
|
||||
|
@ -4320,11 +4293,8 @@ static enum act_return hlua_action(struct act_rule *rule, struct proxy *px,
|
|||
* Lua initialization cause 5% performances loss.
|
||||
*/
|
||||
if (!s->hlua.T && !hlua_ctx_init(&s->hlua, s->task)) {
|
||||
send_log(px, LOG_ERR, "Lua action '%s': can't initialize Lua context.\n",
|
||||
SEND_ERR(px, "Lua action '%s': can't initialize Lua context.\n",
|
||||
rule->arg.hlua_rule->fcn.name);
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua action '%s': can't initialize Lua context.\n",
|
||||
rule->arg.hlua_rule->fcn.name);
|
||||
return ACT_RET_CONT;
|
||||
}
|
||||
|
||||
|
@ -4332,11 +4302,8 @@ static enum act_return hlua_action(struct act_rule *rule, struct proxy *px,
|
|||
if (!HLUA_IS_RUNNING(&s->hlua)) {
|
||||
/* Check stack available size. */
|
||||
if (!lua_checkstack(s->hlua.T, 1)) {
|
||||
send_log(px, LOG_ERR, "Lua function '%s': full stack.\n",
|
||||
SEND_ERR(px, "Lua function '%s': full stack.\n",
|
||||
rule->arg.hlua_rule->fcn.name);
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua function '%s': full stack.\n",
|
||||
rule->arg.hlua_rule->fcn.name);
|
||||
return ACT_RET_CONT;
|
||||
}
|
||||
|
||||
|
@ -4345,11 +4312,8 @@ static enum act_return hlua_action(struct act_rule *rule, struct proxy *px,
|
|||
|
||||
/* Create and and push object stream in the stack. */
|
||||
if (!hlua_txn_new(s->hlua.T, s, px)) {
|
||||
send_log(px, LOG_ERR, "Lua function '%s': full stack.\n",
|
||||
SEND_ERR(px, "Lua function '%s': full stack.\n",
|
||||
rule->arg.hlua_rule->fcn.name);
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua function '%s': full stack.\n",
|
||||
rule->arg.hlua_rule->fcn.name);
|
||||
return ACT_RET_CONT;
|
||||
}
|
||||
s->hlua.nargs = 1;
|
||||
|
@ -4357,11 +4321,8 @@ static enum act_return hlua_action(struct act_rule *rule, struct proxy *px,
|
|||
/* push keywords in the stack. */
|
||||
for (arg = rule->arg.hlua_rule->args; arg && *arg; arg++) {
|
||||
if (!lua_checkstack(s->hlua.T, 1)) {
|
||||
send_log(px, LOG_ERR, "Lua function '%s': full stack.\n",
|
||||
SEND_ERR(px, "Lua function '%s': full stack.\n",
|
||||
rule->arg.hlua_rule->fcn.name);
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua function '%s': full stack.\n",
|
||||
rule->arg.hlua_rule->fcn.name);
|
||||
return ACT_RET_CONT;
|
||||
}
|
||||
lua_pushstring(s->hlua.T, *arg);
|
||||
|
@ -4406,21 +4367,15 @@ static enum act_return hlua_action(struct act_rule *rule, struct proxy *px,
|
|||
/* finished with error. */
|
||||
case HLUA_E_ERRMSG:
|
||||
/* Display log. */
|
||||
send_log(px, LOG_ERR, "Lua function '%s': %s.\n",
|
||||
SEND_ERR(px, "Lua function '%s': %s.\n",
|
||||
rule->arg.hlua_rule->fcn.name, lua_tostring(s->hlua.T, -1));
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua function '%s': %s.\n",
|
||||
rule->arg.hlua_rule->fcn.name, lua_tostring(s->hlua.T, -1));
|
||||
lua_pop(s->hlua.T, 1);
|
||||
return ACT_RET_CONT;
|
||||
|
||||
case HLUA_E_ERR:
|
||||
/* Display log. */
|
||||
send_log(px, LOG_ERR, "Lua function '%s' return an unknown error.\n",
|
||||
SEND_ERR(px, "Lua function '%s' return an unknown error.\n",
|
||||
rule->arg.hlua_rule->fcn.name);
|
||||
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
|
||||
Alert("Lua function '%s' return an unknown error.\n",
|
||||
rule->arg.hlua_rule->fcn.name);
|
||||
|
||||
default:
|
||||
return ACT_RET_CONT;
|
||||
|
|
Loading…
Reference in New Issue