From patchwork Sat Mar 9 15:11:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1909983 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20230601 header.b=Ow/V7VOS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::23b; helo=mail-lj1-x23b.google.com; envelope-from=swupdate+bncbaabbr7ywgxqmgqesp3tvji@googlegroups.com; receiver=patchwork.ozlabs.org) Received: from mail-lj1-x23b.google.com (mail-lj1-x23b.google.com [IPv6:2a00:1450:4864:20::23b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TsRNF2JWMz23qq for ; Sun, 10 Mar 2024 02:12:12 +1100 (AEDT) Received: by mail-lj1-x23b.google.com with SMTP id 38308e7fff4ca-2d2e4ea0f63sf12523301fa.2 for ; Sat, 09 Mar 2024 07:12:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709997128; cv=pass; d=google.com; s=arc-20160816; b=uVLdS8z6+RVRALY0PWGz8Y90N/lTMu+TnrWKqSc5ZIY50ZxUrpX/NspeEQLSvzuLs5 N7M2XAHl/d7cmitUadn8Iro0GApmprf4T8EMZqeIHjl6VcMei6qc2Cspxv5NwqDflpIO Bl+2ROhRWgiwMrFkIeWljNWVXu8ji8MDuvMlFxWDD+t4zbdrI8pp1GY/V7ZNhN60ouA8 CpNXZLO6OzDxt/QtTa4IasfaCSj67s2oQp1cYC5BK3WGblZ8bhrQdgCN52MgCnInWdi0 tYF8tGwVUMSeqHW2KX0uwngh2UV5rDW9RV5/ubtK7j8+xbiiV/WTpbL3OGxwR2+zlYXo RP0A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:ui-outboundreport:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=oa74gS+kaTrRcgxajCdrgPVX2pgB/KAJyJSZI9rj5Ec=; fh=IOwOWn7rcuUODfxx3ROVYN1ea3hpiW1hWs4eajbSq30=; b=m76Ta6FQXUAsolBqoFYSGzBtLECyTLDbwdsHCdtDAGmneqTd6DYH3JYYtmREoeieNw yhRN21OAawY97MV8oe1Hh2Yc7wr2tqk4Ab43mjMFAvA8kqVWXO9biEE2Bfp4rTNHtlYz v5P+mkQNVdP/l3oNWquIn0soh2OhbANoWKma5ztnDn53XmvpaS/k3t3w2C0UbW8rCcnZ +X3NYGTqTwPmmGPkrLql3XdSEmdSSm62pTpQj9ZZtN7qQ/Us14qPsggeld34a3Onz5xn hswyVtJIxKsusuUR8De/tKVaBSM/VrhTShcB3aKspzJjCpAHj4tj7hsuKEAMGJTKmxPh QO4w==; darn=patchwork.ozlabs.org ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@swupdate.org header.s=s1-ionos header.b=TeoDqkdK; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.17.24 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1709997128; x=1710601928; darn=patchwork.ozlabs.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:ui-outboundreport:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:sender:from:to:cc :subject:date:message-id:reply-to; bh=oa74gS+kaTrRcgxajCdrgPVX2pgB/KAJyJSZI9rj5Ec=; b=Ow/V7VOShMY22goMuBJprKhmZbi3LJbwXix6qQXQ+U1vrF+YgcHb20bMgaPLvxAqC2 uRi+yg7y/Fbhg6RzmBx5/d/DKaaRK+OVJWeDq0IzDLp6/tAWRJuIrbn28Y6vl1D/kmzE D/DWcBgXPJD4hPaIpsjN5TVaE9Jolx+Ru/QT7wn0UrCbWi17o7IxLOdnVkK7lXBd8A5V ZJbSLSexS3OMJP1SKd98tdUK8/MfQFvtF72lc2zyY6+FNEAbNlIAz62g6zyP3imvalya 7NrTTsUWPwczpIME61n0/VvctqDeQuYr50tirhzb5WWfconGKVPCmPxH5wco+G74vkLs U/2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709997128; x=1710601928; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender :ui-outboundreport:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:x-beenthere:x-gm-message-state:sender:from :to:cc:subject:date:message-id:reply-to; bh=oa74gS+kaTrRcgxajCdrgPVX2pgB/KAJyJSZI9rj5Ec=; b=J31CSS0deFz4QLKgpHY3y2gLkIjXSrn7NsHs5g7XOdIE3NDEUEg45EQBUYkP0EZGLU 8QbcDY4vY0LJO1FX3+IakIrMl6S2wwmeFDmEDGLRlUnCYLu4nJAxup632nFq1cpxixyF +snnVcdV4noDt8Fe875Dnv+iqjQAQvtp4NFXWtPt/mFC9+8Zw6yTAEI/f6rozQJqC3Fy lxzYOn+oObKQ8tVrVXAmJQb2kzB0hCly47LAk1hXwwZXkSi9H5a5o21Te6vFYA7nwfAu WdQlHL83DM7p0meEXTz3nI88UqZYvvtKrjksw9+5H9dbtZuGJN/8VMP5A3yUHOA9SdN8 ASWg== Sender: swupdate@googlegroups.com X-Forwarded-Encrypted: i=2; AJvYcCUCHltc2Xohb+1Lud7lWVHuRW9zmeQNX+GHGJZvY/j2zC/s+nVu0AQeRASjj0MdzstdKChT7hetpIZ0YjqTbU2RTbyJ88Tr2Z3T/23jWg== X-Gm-Message-State: AOJu0YyhtgmV50we6aVfiC8dj/GpDHLoWfpn/j2XFhLybm4Zh0QYWWp+ OUrYrQHJ3oTp9LWVZ7MUvwFnE5BeW1WZL5SndYoWWTOOPiOVw6TN X-Google-Smtp-Source: AGHT+IETFavSN8fwwbEAPM3y82ESzl10zGoVyW0JwCqAxO9Y3X4YVMYnl1jJuOnnfF4o+DabPT/IHQ== X-Received: by 2002:a2e:9252:0:b0:2d3:93dd:c54b with SMTP id v18-20020a2e9252000000b002d393ddc54bmr1243966ljg.25.1709997127768; Sat, 09 Mar 2024 07:12:07 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:651c:b23:b0:2d2:7b2e:c2c1 with SMTP id b35-20020a05651c0b2300b002d27b2ec2c1ls240404ljr.0.-pod-prod-05-eu; Sat, 09 Mar 2024 07:12:05 -0800 (PST) X-Received: by 2002:a2e:9ace:0:b0:2d3:f830:54ec with SMTP id p14-20020a2e9ace000000b002d3f83054ecmr1289117ljj.43.1709997125551; Sat, 09 Mar 2024 07:12:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709997125; cv=none; d=google.com; s=arc-20160816; b=PW4oaE1h3kjfnHLoqNErv+EbcXEZQJWC5ZtJfKQ0VOTQOGXhqPMUW75xOF79UUrKMO gjn5gdgJPGVlWN4sMeieg7ImF2dl7T9oCj+W43pwXLWy4LVljIDilRFIwDm2NUsJqHZe J1GrdsuDW9j7QAx9rfJhptv5Zml7TRcSAyEoy7pq310VW4ku3uzwjn2/hOHzyED8t7gd 2bAsZUzL1AEoR4/t3bx8k2ZeMvUc2x0iVH/nwOKm3nXduywUx4FD/Ozjdr6pJDrFYNWr SrFuYqmnhlOiU88VG8GHmcrTh1ICnO0q365cRZpdk/kIHk0lvYD6PRiZFVd2YoaHDzvq xIrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=NN9eiMzV2eo+7TIdOLozwALuD0LO4m5/o8ZNPdBRDd0=; fh=TiEWcqMcKpHk5s7uErzpntoONrNfOXwKpI5P8bIlggk=; b=VrmTG61GoFFD0HAgpI+GzTwHxyPuqdg1XBTYzhSS8mECElHnbHISprjvcfYtzQGMmX CMTdaoEY9l3dwPDohysjZioYnjQzsD6GYtAm/cB9xXzyJeMarq895IJLVkpfIZDjmMUV FjRq/JI6y9RnfBm+I+83ENyDNXS1dAnXvT97ZzKgUbULoOIoncgDLr8wDBSy+tZS5YF/ w+J2hH1uJQGw/rG0x5inoYK84rP3QsnL1PJLqG4q0ohMV7EGy0UIOQYg93q/CCozEXUp pyGdJvpmGK69i2OAQ6IFKRvDo8zlFeeSnN9YjrC8pV1zYGMrNmtI+CWJmoAfOiK4Khyq L1rw==; dara=google.com ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@swupdate.org header.s=s1-ionos header.b=TeoDqkdK; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.17.24 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org Received: from mout.kundenserver.de (mout.kundenserver.de. [212.227.17.24]) by gmr-mx.google.com with ESMTPS id q5-20020a2e2a05000000b002d2da2ffee4si113738ljq.2.2024.03.09.07.12.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Mar 2024 07:12:05 -0800 (PST) Received-SPF: pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.17.24 as permitted sender) client-ip=212.227.17.24; X-UI-Sender-Class: 55c96926-9e95-11ee-ae09-1f7a4046a0f6 Received: from paperino.fritz.box ([88.217.136.221]) by mrelayeu.kundenserver.de (mreue109 [213.165.67.113]) with ESMTPSA (Nemesis) id 1M9Frd-1rn4yJ31D5-006M86; Sat, 09 Mar 2024 16:12:04 +0100 From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 1/5] lua: add wrapper for handlers Date: Sat, 9 Mar 2024 16:11:55 +0100 Message-Id: <20240309151159.8426-2-stefano.babic@swupdate.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240309151159.8426-1-stefano.babic@swupdate.org> References: <20240309151159.8426-1-stefano.babic@swupdate.org> MIME-Version: 1.0 X-Provags-ID: V03:K1:XiJWEMp+naVQttKTHz5RdRIbxkDfwPuG5sx0HlwgkfwNOPvHVtL O1m3Z1qZ+DdwSJGakx6kIy1O+iSJhfA//cD8BtO9ZuRYuNnKuzvHnMRFFPnR1UT+gmD97VT ZQzwSxO4X4NXGsp6rD6OUlAPjjWFcJlxVyCKu7uVxjRf2wJHR/hhM7Z1HHf69j3M1K0LqGn LnRYKRLldApk09ZFcP1Xw== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:eoc1Flb4ask=;hY+ihVe0nkw5wL+PUVYBvXGkSfS t5vhNC81g9kBXEy4tZqaRG7UAoVp8qk1q0B6pmz+tdU8fKntMDTsPnujbvnahwY7ekoZIAory xxcCwQGE7/MdyR4NJ09FezNC+Ri+U56G8gomo/sV29M2cbgH6NdLMn/eBtqav9Z6iC1bO1uj9 cKEL+iKQMhXATyioh4/UlpJUBuYVJEg9HBVaFuQbSvdetrmP14lJNmS6xI8y3Swga5hZzc/27 38fHXdjCsNZlaurtLo5df5xt+76dGj1aZ9+b33c9PH/OdhFfP4PpIPkXW7FEQ1KxCwUpcdPqi l0fxErZ/cQrVnQv8vYrQOzaRP8abUcoTOhj6kRuqW9BD2l5Toc195lh+mfYhHxeQP4egWmOQM LupCM8Uv4yoyXb9IkiqAS9d0uJF0BTTVcm2psvzylC1B3tRescS7pAb9trCqyisXAEBBrVgYb cwZ4KVJbFd6ynznYw5ZijmMrsBvWLf9unjVOExt633rDbCUXX49V3qMBr0ZIxmocix6+gGinI l72exKpXhMp4qSSRcY49WoZWklnvqKskA0SriYb4Ig6pNuR/0zVwIG+2AuXF/ovaTzkZpMpo3 DfzYNDy+13KQzmZVXmV8Q4Y4aAKpiObX8jvn9K6U3xm3TjEXqfoFn6UdsKqIj/lxkRB48xZnN y0MYW5FJxNkj9Ff20q4Iw25dNCvjvDsdT105ZQOhuoj4aSZgz4X3X3gT1P+lV2dMX9Bc3V9pA iPfs/8m4TlGuO0pb2det7jxHJHKrszaxSB5PdVPksSdHHGjJwaOKHI= X-Original-Sender: stefano.babic@swupdate.org X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@swupdate.org header.s=s1-ionos header.b=TeoDqkdK; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.17.24 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Add a way to call a custom Lua function that can be used by handlers to check some results. The function receives a string as parameter, and if multiple paramters are required they must be combined into a string. The function returns a swupdate_status result, for example: return swupdate.swupdate.RECOVERY_STATUS.RUN Signed-off-by: Stefano Babic --- corelib/lua_interface.c | 36 ++++++++++++++++++++++++++++++++++++ include/lua_util.h | 17 +++++++++++++++++ 2 files changed, 53 insertions(+) -- 2.34.1 diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index d785cdb5..fbdb7d05 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -1597,3 +1597,39 @@ int lua_parser_fn(lua_State *L, const char *fcn, struct img_type *img) return ret; } + +int lua_handler_fn(lua_State *L, const char *fcn, const char *parms) +{ + int ret = -1; + + lua_getglobal(L, fcn); + if(!lua_isfunction(L, lua_gettop(L))) { + lua_pop(L, 1); + TRACE("Script : no %s in script, exiting", fcn); + return -1; + } + TRACE("Prepared to run %s", fcn); + + /* + * passing arguments + */ + lua_pushstring(L, parms); + + ret = lua_pcall(L, 1, 1, 0); + if (ret || !lua_isinteger(L, -1)) { + LUAstackDump(L); + ERROR("ERROR Calling Lua %s", fcn); + return -1; + } + + if (loglevel >= DEBUGLEVEL) + LUAstackDump(L); + + ret = lua_tointeger(L, -1); + + lua_pop(L, 1); /* clear stack */ + + TRACE("Script returns %d", ret); + + return ret; +} diff --git a/include/lua_util.h b/include/lua_util.h index bf8d2b0e..67c5c47a 100644 --- a/include/lua_util.h +++ b/include/lua_util.h @@ -24,6 +24,7 @@ int run_lua_script(lua_State *L, const char *script, bool load, const char *func lua_State *lua_init(struct dict *bootenv); int lua_load_buffer(lua_State *L, const char *buf); int lua_parser_fn(lua_State *L, const char *fcn, struct img_type *img); +int lua_handler_fn(lua_State *L, const char *fcn, const char *parms); int lua_handlers_init(void); int lua_notify_trace(lua_State *L); @@ -37,11 +38,24 @@ int lua_get_swupdate_version(lua_State *L); #define lua_exit(L) lua_close((lua_State *)L) +#if !defined(lua_isinteger) +static inline int lua_isinteger (lua_State *L, int index) { + if (lua_type(L, index) == LUA_TNUMBER) { + lua_Number n = lua_tonumber(L, index); + lua_Integer i = lua_tointeger(L, index); + if (i == n) + return 1; + } + return 0; +} +#endif + #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM == 501 #define LUA_OK 0 #if !defined(luaL_newlib) #define luaL_newlib(L, l) (lua_newtable((L)),luaL_setfuncs((L), (l), 0)) #endif + void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup); void luaL_requiref(lua_State *L, char const* modname, lua_CFunction openf, int glb); @@ -92,5 +106,8 @@ static inline int lua_load_buffer(lua_State __attribute__ ((__unused__)) *L, static inline int lua_parser_fn(lua_State __attribute__ ((__unused__)) *L, const char __attribute__ ((__unused__)) *fcn, struct img_type __attribute__ ((__unused__)) *img) { return -1; } +static inline int lua_handler_fn(lua_State __attribute__ ((__unused__)) *L, + const char __attribute__ ((__unused__)) *fcn, + const char __attribute__ ((__unused__)) *parms) { return -1; } static inline int lua_handlers_init(void) { return 0; } #endif