Skip to content

Commit

Permalink
lua: fix duplicate logs to syslog
Browse files Browse the repository at this point in the history
(cherry picked from commit 949422a)
  • Loading branch information
rvlad-patrascu committed Jun 22, 2023
1 parent f11b076 commit a4ae802
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 41 deletions.
4 changes: 0 additions & 4 deletions modules/lua/doc/lua_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,6 @@ modparam("lua", "luafilename", "/etc/opensips/opensips.lua")
</itemizedlist>
</para>
</section>
<section>
<title>lua_user_debug (int)</title>
<para>Disable by default</para>
</section>
</section>
<section id="exported_functions" xreflabel="exported_functions">
<title>Exported Functions</title>
Expand Down
7 changes: 0 additions & 7 deletions modules/lua/doc/lua_api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@
</itemizedlist>
</para>
</section>
<section>
<title>setUserDebug</title>
<para>
Enable or disable the xlog feature.
Disabled, the xlog function has no effect.
</para>
</section>
<section>
<title>WarnMissingFreeFixup</title>
<para>
Expand Down
1 change: 1 addition & 0 deletions modules/lua/siplua.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ static cmd_export_t cmds[] = {
*/
static param_export_t params[] = {
{ "luafilename", STR_PARAM, &luafilename},
/* deprecated param, will have no effect */
{ "lua_user_debug", INT_PARAM, &lua_user_debug},
{ "lua_allocator", STR_PARAM, &lua_allocator},
{ "lua_auto_reload", INT_PARAM, &lua_auto_reload},
Expand Down
1 change: 0 additions & 1 deletion modules/lua/siplua.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#ifndef SIPLUA_H_
# define SIPLUA_H_

extern int lua_user_debug;
extern int lua_auto_reload;

extern struct sl_binds slb;
Expand Down
21 changes: 2 additions & 19 deletions modules/lua/sipluafunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,18 @@ void siplua_log(int lev, const char *format, ...)
{
va_list ap;
char *ret;
int priority;
int rc;

if (!format)
return;
if (!(is_printable(lev) | lua_user_debug))
return;

va_start(ap, format);
rc = vasprintf(&ret, format, ap);
va_end(ap);
if (rc < 0)
return;
LM_GEN1(lev, "siplua: %s", ret);
if (lua_user_debug)
{
switch (lev)
{
case L_ALERT: priority = LOG_ALERT; break;
case L_CRIT: priority = LOG_CRIT; break;
case L_ERR: priority = LOG_ERR; break;
case L_WARN: priority = LOG_WARNING; break;
case L_NOTICE: priority = LOG_NOTICE; break;
case L_INFO: priority = LOG_INFO; break;
case L_DBG: priority = LOG_DEBUG; break;
default: /* should not happen, no execution path permits it */
priority = LOG_ERR;
}
syslog(LOG_USER | priority, "siplua: %s", ret);
}

free(ret);
}

Expand Down
10 changes: 0 additions & 10 deletions modules/lua/sipstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,6 @@ static int l_sipstate_notice(lua_State *L)
return 0;
}

static int l_sipstate_setUserDebug(lua_State *L)
{
int n;

n = luaL_checkinteger(L, 1);
lua_user_debug = n;
return 0;
}

static int l_sipstate_getpid(lua_State *L)
{
int pid;
Expand Down Expand Up @@ -303,7 +294,6 @@ static const struct luaL_Reg siplua_state_mylib [] =
{"xdbg", l_sipstate_xdbg},
{"print", l_sipstate_print},
{"notice", l_sipstate_notice},
{"setUserDebug", l_sipstate_setUserDebug},
{"getpid", l_sipstate_getpid},
{"getmem", l_sipstate_getmem},
{"getmeminfo", l_sipstate_getpkginfo},
Expand Down

0 comments on commit a4ae802

Please sign in to comment.