collectd: fix lua callback registration
authorFlorian Eckert <redacted>
Tue, 19 Feb 2019 09:25:58 +0000 (10:25 +0100)
committerFlorian Eckert <redacted>
Thu, 25 Apr 2019 09:13:52 +0000 (11:13 +0200)
If you want to register more than one lua plugin, you cannot start the
collectd.

You get always the error message:

"The read function "lua/(null)" is already registered. Check for
duplicates in your configuration!"

This is not what I expect and what the documenation says.
With this change it is now possible to registrate more then one lua
Script.

See https://github.com/collectd/collectd/pull/2379

Signed-off-by: Florian Eckert <redacted>
utils/collectd/patches/930-fix-lua-callback-registration.patch [new file with mode: 0644]

diff --git a/utils/collectd/patches/930-fix-lua-callback-registration.patch b/utils/collectd/patches/930-fix-lua-callback-registration.patch
new file mode 100644 (file)
index 0000000..bffe656
--- /dev/null
@@ -0,0 +1,42 @@
+--- a/src/lua.c
++++ b/src/lua.c
+@@ -281,9 +281,6 @@ static int lua_cb_register_read(lua_Stat
+   luaL_checktype(L, 1, LUA_TFUNCTION);
+-  char function_name[DATA_MAX_NAME_LEN];
+-  snprintf(function_name, sizeof(function_name), "lua/%s", lua_tostring(L, 1));
+-
+   int callback_id = clua_store_callback(L, 1);
+   if (callback_id < 0)
+     return luaL_error(L, "%s", "Storing callback function failed");
+@@ -298,6 +295,9 @@ static int lua_cb_register_read(lua_Stat
+   if (cb == NULL)
+     return luaL_error(L, "%s", "calloc failed");
++  char function_name[DATA_MAX_NAME_LEN];
++  snprintf(function_name, sizeof(function_name), "lua/%p", thread);
++
+   cb->lua_state = thread;
+   cb->callback_id = callback_id;
+   cb->lua_function_name = strdup(function_name);
+@@ -325,9 +325,6 @@ static int lua_cb_register_write(lua_Sta
+   luaL_checktype(L, 1, LUA_TFUNCTION);
+-  char function_name[DATA_MAX_NAME_LEN] = "";
+-  snprintf(function_name, sizeof(function_name), "lua/%s", lua_tostring(L, 1));
+-
+   int callback_id = clua_store_callback(L, 1);
+   if (callback_id < 0)
+     return luaL_error(L, "%s", "Storing callback function failed");
+@@ -342,6 +339,9 @@ static int lua_cb_register_write(lua_Sta
+   if (cb == NULL)
+     return luaL_error(L, "%s", "calloc failed");
++  char function_name[DATA_MAX_NAME_LEN] = "";
++  snprintf(function_name, sizeof(function_name), "lua/%p", thread);
++
+   cb->lua_state = thread;
+   cb->callback_id = callback_id;
+   cb->lua_function_name = strdup(function_name);
git clone https://git.99rst.org/PROJECT