diff mbox series

ubus/lua: add fd sending to ubus requests

Message ID 20210827112210.34910-1-nicola.pancheri@netduma.com
State New
Headers show
Series ubus/lua: add fd sending to ubus requests | expand

Commit Message

nicola.pancheri@netduma.com Aug. 27, 2021, 11:22 a.m. UTC
From: Nicola Pancheri <nicola.pancheri@netduma.com>

Exposes the ubus file descriptor sharing interface to Lua.

Signed-off-by: Nicola Pancheri <nicola.pancheri@netduma.com>
---
 lua/ubus.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/lua/ubus.c b/lua/ubus.c
index e2bb081..8378a25 100644
--- a/lua/ubus.c
+++ b/lua/ubus.c
@@ -321,7 +321,8 @@  ubus_method_handler(struct ubus_context *ctx, struct ubus_object *obj,
 			lua_pushnil(state);
 		else
 			ubus_lua_parse_blob_array(state, blob_data(msg), blob_len(msg), true);
-		lua_call(state, 2, 1);
+		lua_pushnumber(state,req->req_fd);
+		lua_call(state, 3, 1);
 		if (lua_isnumber(state, -1))
 			rv = lua_tonumber(state, -1);
 	}
@@ -668,6 +669,12 @@  ubus_lua_call(lua_State *L)
 	const char *path = luaL_checkstring(L, 2);
 	const char *func = luaL_checkstring(L, 3);
 
+  int fd = -1;
+	if( lua_isnumber(L,5) ){
+		fd = lua_tointeger(L,5);
+		lua_pushvalue( L, 4 );
+	}
+
 	luaL_checktype(L, 4, LUA_TTABLE);
 	blob_buf_init(&c->buf, 0);
 
@@ -688,7 +695,7 @@  ubus_lua_call(lua_State *L)
 	}
 
 	top = lua_gettop(L);
-	rv = ubus_invoke(c->ctx, id, func, c->buf.head, ubus_lua_call_cb, L, c->timeout * 1000);
+	rv = ubus_invoke_fd(c->ctx, id, func, c->buf.head, ubus_lua_call_cb, L, c->timeout * 1000, fd);
 
 	if (rv != UBUS_STATUS_OK)
 	{