From patchwork Fri Nov 3 12:29:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 833830 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c09::23d; helo=mail-wm0-x23d.google.com; envelope-from=swupdate+bncbdd6bwv65qpbbkwd6hhqkgqevbgqmua@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="Xfgttc1+"; dkim-atps=neutral Received: from mail-wm0-x23d.google.com (mail-wm0-x23d.google.com [IPv6:2a00:1450:400c:c09::23d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yT1Xt1pD9z9s7f for ; Fri, 3 Nov 2017 23:31:41 +1100 (AEDT) Received: by mail-wm0-x23d.google.com with SMTP id r68sf246016wmr.4 for ; Fri, 03 Nov 2017 05:31:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1509712298; cv=pass; d=google.com; s=arc-20160816; b=KmtASjspph2VSgcs6N+4ho6P985hGDaREPtGykt8V2Vc8p01iUe8d6XkMrRx8LoLdm rIBXjOQS4vxXKUymyCPg7hZelfVX8KYVhItwk4azs03gNf5bieQ166PxiDm9YzQJGOAN faEE92m6o92lRl7HFc0gIQ04kzQDAsSFDrLPV8xQz++PeIfsHTJEzvDGngKXxjfQFACN /zUDVpu60wLnDEtuKEUCnUFDatVph7RVPMl2v7gK67vqaUccWcWhYr8Z6Y6XMxIaHdFt 1I3KBKuUEpyG2hFSQf8PIiqoDKg+EuwIjVIZl1Inz+LWES+2Q8YMTuJvxQBRd2P0WnAq wZCA== 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:message-id:date:subject:cc:to:from :arc-authentication-results:arc-message-signature:mime-version :sender:dkim-signature:arc-authentication-results; bh=O9HNUXgqxVff4uJ4PMZ6BsYCarkEsNH90c8/iQfipoo=; b=jKRdy+V0ZZ6EXhMPsl6FoeKQBTnNn6RfxhbednLgkQagEKaqVdMatHQlkpKDTj1Dae ybNBg6CsTHuUnnfen2zOoPGkSXX8KO8qjnHFfe4K6vm4POVrwNKPDJrhQxuyXmoSQnzR l35KHADCXhGUZxBq0L+NTGh2gzhizB9IPsZ9q2VakqSA2qnuTcRkJgtiJxrYoMKg5+o8 mBNYu/3AwoZG5Z/UKsRlzKYB5F+QC+vwu82g3Ecy4UhdJl7deRERvACOJ6sjnSiZAO4b oOp9aFM5BrKnQcBPUHH0PPMRgJs9amhxnqqFDc7jF2ifRlJbaNYzHpuc8B+wmZQ9/+s6 iEiQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=christian.storm@siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=O9HNUXgqxVff4uJ4PMZ6BsYCarkEsNH90c8/iQfipoo=; b=Xfgttc1+VBMH3+gcQQoiJasJuedw2FpWrdE4B2NG3WA3iJbsGP4WdVg2wgnub1FoKj 4jHgSPPHcQlcEJHb5pb586siMyoe6HFnp/Q+YOrmxeVG2OYGNV4+Px8s5P6q7w2Q7+FL 7ABvElVm2TwNW0Rw8wPvDjLZtThM8jW+7v8DCcpJYYtbP02mljFmm9pNBdtXT1PhWPzp SjNbf0VO6Go4YNMVx0AwDklFjiLgNhuuIMrL2PRrj4YgvwwQDBt5yzYJF8cHGBe64Ihh 0QutXi02qMWDd1IJod0qo9gkc72Fjv8qZFOEskyXo9pDNJ2Zt5Cm8EoVZESYKCrP4sA9 eO+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=O9HNUXgqxVff4uJ4PMZ6BsYCarkEsNH90c8/iQfipoo=; b=ZleOb7s/uABQruBW0t9YcT4abanNVTsCOrNwjBbrB2msCFkwbqOsApULw6mYzvPCaT KIXOz7QfzieXK90EkTyX1EEns9BJepeLMGiTOlD++UDJeLjKqlsKDNCIsPzDUKbCrwTo cbwx5xemTosTdDD/fUEkwhqac9Bvofm/zFmKME0ew6cQhIw2pHCDLRwtWC291a5ccUVb pOTnMavRJxqm3nLjeOoZPJVGhbEBcGJ/oPAyaqOOcWWxiV5UxBPA9umTB7GQnmT+NMzt wy+63M/zCzbRKcJSL69uNbZPkqSkrFKK5hcqreKMuEGeXTFEUHAc8DXuWtUq+2G8FJwo +8UQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AMCzsaU+6z2dmV2ctz2NoLCMPyxlS3PzOU2IqZ5VJs1UbczABhcRISDb /YL3BH7rg+9KoZ3sYvetMAI= X-Google-Smtp-Source: ABhQp+QHCYypOLJOTq5pxBujtEWRqLqPZv25NWyldJD1bfHRm0/3EzJ58fluGX7eqoUqNDppZPTtOQ== X-Received: by 10.28.199.10 with SMTP id x10mr56249wmf.6.1509712298862; Fri, 03 Nov 2017 05:31:38 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.223.163.22 with SMTP id c22ls1297545wrb.0.gmail; Fri, 03 Nov 2017 05:31:38 -0700 (PDT) X-Received: by 10.28.178.68 with SMTP id b65mr636949wmf.17.1509712298503; Fri, 03 Nov 2017 05:31:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509712298; cv=none; d=google.com; s=arc-20160816; b=Pp9mNSBT4P6WGXGQP/b6yF939r6nBmd2Nb5sSlSeMlWU7iftXgQFqa7sApT7D+2sdN C6640gwub2KUJunRnL7w2AHxmlu19wKV+AAbehJD9936Lx1SuziV6qnUBQrvezqgtnUF NFj+DSW9Mk93DAaT9D3MMmyCFCDyKepMnNQqTXjUzzvfMS/wcNvhZXeJymc7qN+y4tqD Kq4VKSQbXl6kLvagePD5vrN3mRF0XlWNyMI1vyqaGeb1ZgIKj1mDSdeEdd6H67Rrnr10 Psa3mJGnOhbTjoKaK4aNCbpcwiRlyx2v2ygJ4dze+aQnKXZ9w6KG2KM59okZPRoHvZnb h6Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=yNwK9kE2zk8PLYgWL/jdd6cld4Q524+QKEegNKTI7dQ=; b=ttIayB1KEqmKuaYWCG1DpUXwwfBBsQnjlGh9yIW2tjdCsiR+LPo9PCPZxOZtwkuMV5 n0lCnYBqEQl8bwl37NVXE1l1QGqc1KGaqqAqzuvMyLRBXgHjhVtXWQzYJBKkxJ13Ruwf 8kdCqxvlKhLe0cxWlQ+NBQ9vUBWd6t+8AvQsYomjFi8hTwuVQ01KNdMbsZunGtbvANAR GFaB+966oPGo0qYjJJiF3pl+hDavdJ2CW1GdPHXQU7JgUOv0UZcQCcYZS0z41TxDqQ9T 3sNJojeZv2C2yufYpz3RlE+EG5Vzgilnsup+7i7mYOctUxG+IsMEh4QlLUOR7OOWh0py G1+A== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=christian.storm@siemens.com Received: from david.siemens.de (david.siemens.de. [192.35.17.14]) by gmr-mx.google.com with ESMTPS id k11si161728wmi.1.2017.11.03.05.31.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Nov 2017 05:31:38 -0700 (PDT) Received-SPF: pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) client-ip=192.35.17.14; Received: from mail2.siemens.de (mail2.siemens.de [139.25.208.11]) by david.siemens.de (8.15.2/8.15.2) with ESMTPS id vA3CVcIm021911 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 3 Nov 2017 13:31:38 +0100 Received: from MD1KR9XC.ww002.siemens.net ([139.25.69.251]) by mail2.siemens.de (8.15.2/8.15.2) with ESMTP id vA3CVcFk030106; Fri, 3 Nov 2017 13:31:38 +0100 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm Subject: [swupdate] [PATCH 01/11] Lua: expose get_tmpdir() to Lua Date: Fri, 3 Nov 2017 13:29:59 +0100 Message-Id: <20171103123009.18705-1-christian.storm@siemens.com> X-Mailer: git-send-email 2.15.0 X-Original-Sender: christian.storm@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=christian.storm@siemens.com 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: , Expose get_tmpdir() to Lua as swupdate.tmpdir() function. Signed-off-by: Christian Storm --- corelib/lua_interface.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index 5c2a36e..a41629f 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -369,12 +369,21 @@ static int l_info(lua_State *L) { return 0; } +#ifdef CONFIG_HANDLER_IN_LUA +static int l_get_tmpdir(lua_State *L) +{ + lua_pushstring(L, get_tmpdir()); + return 1; +} +#endif + /** * @brief array with the function which are exported to Lua */ static const luaL_Reg l_swupdate[] = { #ifdef CONFIG_HANDLER_IN_LUA { "register_handler", l_register_handler }, + { "tmpdir", l_get_tmpdir }, #endif { "notify", l_notify }, { "error", l_error }, From patchwork Fri Nov 3 12:30:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 833839 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4010:c07::23e; helo=mail-lf0-x23e.google.com; envelope-from=swupdate+bncbdd6bwv65qpbbk6d6hhqkgqetjokzyy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="nP9kwTNq"; dkim-atps=neutral Received: from mail-lf0-x23e.google.com (mail-lf0-x23e.google.com [IPv6:2a00:1450:4010:c07::23e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yT1Xv1dRpz9sRW for ; Fri, 3 Nov 2017 23:31:42 +1100 (AEDT) Received: by mail-lf0-x23e.google.com with SMTP id s19sf765501lfi.19 for ; Fri, 03 Nov 2017 05:31:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1509712299; cv=pass; d=google.com; s=arc-20160816; b=gm3km3CasRQVBOomYVAWcPIKqEt5w5tc/mmOuxgmnkXW6vQhf20Ygv1NpaUiAxCLb6 dVZ6mgXwGFTXCeC2KnKMcG82PADFnvWqhqInhLTuu0FPM8TcOU3cFGU1jH73W10KMNmp F/rGzf8qvRzPtaYBKWRUO7v0OAL6J2KqUOJfHPQvStYo6KBI0jeuNiSHezSWbGI3uZtV zWS+Hz61SK1ylOwLlzkoRNVqlm2/DVi1UB5RYbxGoOg4Rf4haSpDQZL1IwbWsJJhpRb2 gXNhX0QiGtFqQ2UtATVNDq02VGmG2e8SGm/GR92JiLAvLpCR1I+R5AwrmgD3MGXUr+jT bLOA== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=9el05YjMQuM94EDut53Q/WUvr9K4K9u/lSUFiegLfTU=; b=1IberFWsa48gZc00xKmK/UM3PZs78y/EcMjuC9TLLXo37uZSovKYaGiulXjy7m3una dLwpSiB/IT1P2Sdwc52N2si2IYRNGKeKWg/v72Eav9rhMsS2NDnVe2Y80YOfnHB4dYT3 Lb5o/pERI18Fto46eNWGwAyazwS72eHBzBWjEEjIEsWgoEvwzSPEDP301VZs2nhlTFu0 Vt5thlYcPl4ZbIRIwpNmVgVKgHyX6uvUerQKGnjjKMNJFwf31UaXIuHW21X6WxscJTFE lBHsw9Vg927sCbWR+BUcCUQA3Lnjo7AmCEUQe0eKc/y3JfzaeuPSi44rKgrHk+iZNt3I oyTw== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=christian.storm@siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=9el05YjMQuM94EDut53Q/WUvr9K4K9u/lSUFiegLfTU=; b=nP9kwTNqWy9zcOKl6HzuE84BO4kyeNoXRS/yVadyvIcWzN+RN42EzGaRZO8a5XEgsA ejAVfmw4e0hxCUABgsxo6GHYxkbngYjwFwgiwkbwmSqDGkz+BNJchvv/CNP0+8Qnmmt2 dOAEegUDUW+hyI0EITMwuUU+G+oPo/KrgOvEpupQk3fm+6oOv6Omq27/PwkeJM5mYI8V k0zpn7J91ouN22AcdaBojnPuuKCVpls1+CLceI/FZmGV+/FPcct+JTgK6U3Bv9KG2kdg jRgSqqtp12izlsT7GO/x0LiLiolChINWPWjveVvB8U6fk1HSXThZk24lXP4Z+4SbwRhr KNZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=9el05YjMQuM94EDut53Q/WUvr9K4K9u/lSUFiegLfTU=; b=BLDqJTZgrTm3psT6GQmRTJ0Gx8OaJia0K9ZnrewdjXtcakU8HAhHCjc+gMo5DA+4nC AbI1QPFheFh9Jr0+Hqpequk3QDJ9n6tR2giX2xbkE6w8Fiq7lSvpwqj+eaQePMNjw22b CJ+mjQcuu5FgcI5mMfkOoXK2Iz66EwuGqvsywb3OGC94WAmZ67kcl+ydKqqf+wFem2kH KL9CubSbf5SSiMoOiNr3lM/DX7lPR5dsRnwTpzJxXDuI6pzbq58X/VJ8n6ITjqsZHmNG /efPkokARutkDZ7XaimAmnvyaHJrk0G5ya3rmA//TxgCYIy3l+J8IF0ePx0IXHNZa8Oi ZzlA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJaThX5URLdf+EVNSJOn82sdzGs6V5G5EgWDG1vaL5MU8ChoyyopW6zz WKL1nr4viSi0s3Levq5aX/M= X-Google-Smtp-Source: ABhQp+SpvGLj4SD6jDCMQH8qmNm7ekYEe7V1yRpYw2lhmMg0N4P8WcYS35GgzXNC/H7cksKrFTQ6zA== X-Received: by 10.25.150.13 with SMTP id y13mr17434lfd.7.1509712299888; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.46.4.11 with SMTP id 11ls911839lje.2.gmail; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) X-Received: by 10.46.86.156 with SMTP id k28mr267208lje.22.1509712299239; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509712298; cv=none; d=google.com; s=arc-20160816; b=cdpQPypMJytnPxGEdwbU8Be52whRHOzE6n+TOf23zyD5/J7fOnLelWJYG5uSC2Kzvd zkF+qFJQwYSFXVtYFs3VD9vR1AH3CJdHg6tdflPb+LIa857HrgEbQykQpfqADyvFybEf DympK+NENFcR+GWY2rh/aYdQ7TeIQ/R+t6L11L3OjlQ/5r04l3kk+p6dIrQ2UPkXBBUB IqtQg00CeEr3y/JOqpCHzfpA3fdVRxNrsYk9PmMw9+zQr3MpaHk2kxiqQVFmhcMFETLO HwBFEnABsu+yCdWh42Fpe6joKkS8JE59Le9hVZHEEiFez7Uz1cfQ5ib0ak8nHuN8F4hZ sOWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=5nJ+R38ssVaNgAcE7m0SDGe1WC4UethZwa47kVCLTwM=; b=XcUiFCtpTlaU4OiFPKUk1G/bu3aBUxorAXhd1P7u0lssNxXaJ+sed7l/ELcJ5m6KRS WgboSmYisGwFW21bhH5j7WCFI2fC0tvzcqdhR0b55iyDiEVBTTYIzFumyQKigznBPnNL EuaNxI/BJjXbYpugqOCoAEBiTn88B4SDR4TRYo1OYutNbo/lN9U2ebqvCw7tq6ozdLOe pD8w7/tiHzLqRqNnfT1jlFzSvFzWTvBGfGTp0h2p4VqECVUJDWy2GM4H+wFws0/Js3KR 6jsTSxOUl2D4+Q68ZoPmyJR3LD1BEIaPuaaITgmhahhgbcVsUq9IRNcNonMlEiCDed72 BhmQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=christian.storm@siemens.com Received: from goliath.siemens.de (goliath.siemens.de. [192.35.17.28]) by gmr-mx.google.com with ESMTPS id g190si396637lfg.4.2017.11.03.05.31.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Nov 2017 05:31:38 -0700 (PDT) Received-SPF: pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.28 as permitted sender) client-ip=192.35.17.28; Received: from mail2.siemens.de (mail2.siemens.de [139.25.208.11]) by goliath.siemens.de (8.15.2/8.15.2) with ESMTPS id vA3CVc7U015147 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 3 Nov 2017 13:31:38 +0100 Received: from MD1KR9XC.ww002.siemens.net ([139.25.69.251]) by mail2.siemens.de (8.15.2/8.15.2) with ESMTP id vA3CVcFl030106; Fri, 3 Nov 2017 13:31:38 +0100 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm Subject: [swupdate] [PATCH 02/11] Lua: hide but transport SWUpdate-internal attributes Date: Fri, 3 Nov 2017 13:30:00 +0100 Message-Id: <20171103123009.18705-2-christian.storm@siemens.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171103123009.18705-1-christian.storm@siemens.com> References: <20171103123009.18705-1-christian.storm@siemens.com> X-Original-Sender: christian.storm@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=christian.storm@siemens.com 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: , Some SWUpdate-internal img_type attributes should not be "officially" exposed to the Lua realm but they may be required when calling, e.g., copyfile() from within a Lua handler or when chaining handlers, i.e., calling a C handler from within a Lua handler. One such example is img_type's offset attribute designating the offset in the cpio file which is used by, e.g., copyfile(). "Hide" those SWUpdate-internal attributes in a metatable so that they're not "visible" in the Lua realm, e.g., by pairs() enumeration, but still can be transported from the C to the Lua realm and vice versa. Although these "hidden" attributes can be accessed directly from the Lua realm, the access pattern, e.g., image["_private"]["offset"], strongly hints not to mess with the image["_private"] table values from within the Lua realm. Signed-off-by: Christian Storm --- corelib/lua_interface.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index a41629f..8b8851e 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -267,6 +267,26 @@ static void lua_number_to_img(struct img_type *img, const char *key, static void image2table(lua_State* L, struct img_type *img) { if (L && img) { lua_newtable (L); + + /* + * Create a metatable to "hide" SWUpdate-internal attributes. + * These are not "visible", e.g., by pairs() enumeration but + * may be accessed directly, knowing the attribute paths. + * An example is img_type's offset designating the offset + * in the cpio file which is used by, e.g., copyfile(). + * While not visible in pairs() enumeration, it is directly + * accessible by image["_private"]["offset"]. + * This access pattern strongly hints not to mess with the + * image["_private"] table values from within the Lua realm. + */ + lua_newtable(L); + lua_pushvalue(L, -1); + lua_pushstring(L, "_private"); + lua_newtable(L); + lua_settable(L, -3); + lua_setfield(L, -2, "__index"); + lua_setmetatable(L, -2); + LUA_PUSH_IMG_STRING(img, "name", id.name); LUA_PUSH_IMG_STRING(img, "version", id.version); LUA_PUSH_IMG_STRING(img, "filename", fname); @@ -289,6 +309,10 @@ static void image2table(lua_State* L, struct img_type *img) { LUA_PUSH_IMG_NUMBER(img, "size", size); LUA_PUSH_IMG_NUMBER(img, "checksum", checksum); + lua_getfield(L, -1, "_private"); + LUA_PUSH_IMG_NUMBER(img, "offset", offset); + lua_pop(L, 1); + char *hashstring = alloca(2 * SHA256_HASH_LENGTH + 1); hash_to_ascii(img->sha256, hashstring); lua_pushstring(L, "sha256"); @@ -315,6 +339,11 @@ static void table2image(lua_State* L, struct img_type *img) { } lua_pop(L, 1); } + + lua_getfield(L, -1, "_private"); + lua_getfield(L, -1, "offset"); + img->offset = (off_t)luaL_checknumber(L, -1); + lua_pop(L,2); } } From patchwork Fri Nov 3 12:30:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 833838 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4010:c07::238; helo=mail-lf0-x238.google.com; envelope-from=swupdate+bncbdd6bwv65qpbbk6d6hhqkgqetjokzyy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="KSEx5yKe"; dkim-atps=neutral Received: from mail-lf0-x238.google.com (mail-lf0-x238.google.com [IPv6:2a00:1450:4010:c07::238]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yT1Xv1l0yz9sRg for ; Fri, 3 Nov 2017 23:31:42 +1100 (AEDT) Received: by mail-lf0-x238.google.com with SMTP id u5sf770412lfg.9 for ; Fri, 03 Nov 2017 05:31:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1509712300; cv=pass; d=google.com; s=arc-20160816; b=pgobqS4l4njVQoyRwVtfStClG9iUxZZX/hsTDV4U00w9P0BkPVhJNt0O+BxqzaxyhS KobcAH/X9tBacbusFt0HqtFTtrLOC5YeIRl0mpo9S07m5XGgeORIXmjeTwc4RzGAiasz 2Uu3tgyycSu3tgr45kjcUrmAg3mk4WSt/L19IST+n+rpjow/TdqVR7HQ8J034QSh1bXi OBXSD1VC3EnOJ6DFAqzGtFT9Cew3tH+cM4QnDKcBJspaHsq/tRbdt92IVSnSNhYy41Fy t42RCXlHMwwr2xL5sIDXqKgp0MT3e6QGUJi3FMR+diOGcd5+5zhfjTGegnfRN8ZHgtdb u6EA== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=43k17wO8IrnJOKVXL5JxZ42d8huy9zygB+0Dxh4sOXM=; b=Zjp4TTw1uGWx+VWdHX5j78rnRzdYtEQXpKVldtVhn3fh4dn6OAln2ObYqq2Y/IoNgd S5iSS2Uxddb1YdGMlWlzHiPzUb5jkLncsAdoFuAl4Qfa4k67ctTZbu+I1GgFaw9ZwCTc uG1zaXenCaXn5mhXU9IegLgguCL6xQuC5HJuIiGVny62VkXgMWfSmdOQZpz3qU9eci6e 8nZQIrNLAODoDtds2tgkyhkY8z5OZ4NiJ+iWYA9ozZXKB1XYxYkT6pnI+zrGZqjA4TAk eoQYkTcc19Mkltl8m9nRM603qs/eTzrKTSH9iqWaVnQX/O8jbJkNXqz2sUY58kxYBoGg F84A== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=christian.storm@siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=43k17wO8IrnJOKVXL5JxZ42d8huy9zygB+0Dxh4sOXM=; b=KSEx5yKeooSrv2xjdpR6gOYhCLCFqtUuh2oyH2qylRFcr62DEWsTIKwq0dpUXRtR9I 8gtb4SrJmk/8+XYwIHgiPkeglURV0zEVvMb6D7om88siPkxlBhohBpq3D14qwE2RitV0 9pf7xVJhyHxmfcPGr7hws+7tdm2+54hfZSRTQYiOcMtWs+Rt8OtPVWcI+iVUSSNjE4di PBMpddVtaeA1ZYODdcfh3nh5pOp+W43GyuvJvMuK+eMi0EmU/jX3Ljvpna3kQgVlI6IR RzQZC/zzsH19641rhKvlukKcxQVyNzmx/CFXkupMyGHC564SOgf8g0C5qucJcUnMODyT mYBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=43k17wO8IrnJOKVXL5JxZ42d8huy9zygB+0Dxh4sOXM=; b=KMl+nsDzgM+u7jqTHf5IdMI1sxNWeGN4rIECMgJXY0V7qRw+siiMzI3nEqyvv60TTI DWoCnC0d7bmVZl4KpUmIlzh7UWeP8tIeEewoGZCyU8I1N4L+T4rVw3trxbgNno0fX47B OkzUak2ANlO7WHdg4RDaMfuw4yBAeqlbRFvlItbwaOOex/4lmhBZAYkk153eSxCxeaJg b8JzVJQUlYg01mastFBOueWNTt730a/rcJa2xFTOXezPzGFtVIY84XIAuaYWWoP2NbWt IckxRrOMRw6rxx1ScB8jysky9swDNZCjW8bALuPZHc/kkHhdgtngvhYMnp0q4W0W6hXB 5jWA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AMCzsaWOHS2G/UPwhCJPYmirLjNzGGfz3uLlkm0ViQDDxwgc86yGHvmh 4PRkMD1b6N07/DieCkQzdIs= X-Google-Smtp-Source: ABhQp+SFbcH15KSPkFeGjEBNmA7RAgrMeBk/Hqqg6MyAShtNtn1Qk3wK67JvFcdo7QtUZx8aBVEcrQ== X-Received: by 10.46.91.6 with SMTP id p6mr20070ljb.12.1509712299982; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.46.25.80 with SMTP id p77ls911789lje.1.gmail; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) X-Received: by 10.25.31.13 with SMTP id f13mr203696lff.16.1509712299157; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509712299; cv=none; d=google.com; s=arc-20160816; b=X6MlJD+IYgx0ZfAvDStrz4hHH36oMvghXaHI+ZrWrWM3u/i+HR6mzgbNeyLV7tQJS+ 0kDVlzVNso8OP8NnAn+eAYGshrG5jNbmJP9Zo2YA8L01NrOZdytPXReCWX94c6yyULoZ EqtGlthd328roZYowfEnlRREdq8xL4LhaxqWXbz7JZL67A022vD+jVzB9Uxo4gd8eEXC /d3OX39xlxs0gJYc7P5qXJ0IRNVmSMrfZGbtn+yhHYnhTv7itPjc3YB38d8ooSuZq39f VkXeTTF8H1Pa5HR12wS4dHzUx2deSmO8gx6geGtqPwRwl94NtCKMfDDEhf9PkRG/vEvg j0Cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=w7wPOJFKmLQAtit9rv6R2LtYoMqSX0Qo6qd8WI2iR00=; b=YrrsGLKxGfdgaObn59ELVq+zgO2MC4voNmuP46rSz222oSWd0qw24N9M3nwzrtd40k hjaILzCCExqanI/n/Gt9thjpAVcYPvRcGoxnhR8Z/0DScdFb0Va43MRRUtgqOJEw3TL5 FIGeEN0+gdc9MgEIWkGNHHivhNudW0Q6hrFAJFNwIfxj0prWciv6HLFPx8YLPepAJ+Af FlMs1cc6xhCk4I08pxsjMIxsEPgzn+ueP1uJKeNAhZBnnI9afTaxoChssl8P/xkOdCD3 gTBYT3G197CZX6RJUpy4SvHIfQaG/qZGV5HYqUEMRKqoVj7OIr0rhfd5ysWuGxz+AN0P +ACQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=christian.storm@siemens.com Received: from david.siemens.de (david.siemens.de. [192.35.17.14]) by gmr-mx.google.com with ESMTPS id r17si467561ljb.2.2017.11.03.05.31.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Nov 2017 05:31:39 -0700 (PDT) Received-SPF: pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) client-ip=192.35.17.14; Received: from mail2.siemens.de (mail2.siemens.de [139.25.208.11]) by david.siemens.de (8.15.2/8.15.2) with ESMTPS id vA3CVcbb021919 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 3 Nov 2017 13:31:38 +0100 Received: from MD1KR9XC.ww002.siemens.net ([139.25.69.251]) by mail2.siemens.de (8.15.2/8.15.2) with ESMTP id vA3CVcFm030106; Fri, 3 Nov 2017 13:31:38 +0100 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm Subject: [swupdate] [PATCH 03/11] Lua: split image2table() functionality Date: Fri, 3 Nov 2017 13:30:01 +0100 Message-Id: <20171103123009.18705-3-christian.storm@siemens.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171103123009.18705-1-christian.storm@siemens.com> References: <20171103123009.18705-1-christian.storm@siemens.com> X-Original-Sender: christian.storm@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=christian.storm@siemens.com 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: , Refactor setting the Lua table's values from image2table() into update_table() and reduce image2table() to Lua table creation only, using update_table() to set values. update_table()'s functionality is required after having called, e.g., copyfile() from within a Lua handler to reflect copyfile()'s changes to img in the Lua realm. Signed-off-by: Christian Storm --- corelib/lua_interface.c | 52 +++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index 8b8851e..216e44a 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -264,28 +264,10 @@ static void lua_number_to_img(struct img_type *img, const char *key, } -static void image2table(lua_State* L, struct img_type *img) { +static void update_table(lua_State* L, struct img_type *img) +{ if (L && img) { - lua_newtable (L); - - /* - * Create a metatable to "hide" SWUpdate-internal attributes. - * These are not "visible", e.g., by pairs() enumeration but - * may be accessed directly, knowing the attribute paths. - * An example is img_type's offset designating the offset - * in the cpio file which is used by, e.g., copyfile(). - * While not visible in pairs() enumeration, it is directly - * accessible by image["_private"]["offset"]. - * This access pattern strongly hints not to mess with the - * image["_private"] table values from within the Lua realm. - */ - lua_newtable(L); - lua_pushvalue(L, -1); - lua_pushstring(L, "_private"); - lua_newtable(L); - lua_settable(L, -3); - lua_setfield(L, -2, "__index"); - lua_setmetatable(L, -2); + luaL_checktype(L, -1, LUA_TTABLE); LUA_PUSH_IMG_STRING(img, "name", id.name); LUA_PUSH_IMG_STRING(img, "version", id.version); @@ -321,6 +303,34 @@ static void image2table(lua_State* L, struct img_type *img) { } } +static void image2table(lua_State* L, struct img_type *img) +{ + if (L && img) { + lua_newtable (L); + + /* + * Create a metatable to "hide" SWUpdate-internal attributes. + * These are not "visible", e.g., by pairs() enumeration but + * may be accessed directly, knowing the attribute paths. + * An example is img_type's offset designating the offset + * in the cpio file which is used by, e.g., copyfile(). + * While not visible in pairs() enumeration, it is directly + * accessible by image["_private"]["offset"]. + * This access pattern strongly hints not to mess with the + * image["_private"] table values from within the Lua realm. + */ + lua_newtable(L); + lua_pushvalue(L, -1); + lua_pushstring(L, "_private"); + lua_newtable(L); + lua_settable(L, -3); + lua_setfield(L, -2, "__index"); + lua_setmetatable(L, -2); + + update_table(L, img); + } +} + static void table2image(lua_State* L, struct img_type *img) { if (L && img && (lua_type(L, -1) == LUA_TTABLE)) { lua_pushnil(L); From patchwork Fri Nov 3 12:30:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 833832 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c09::23d; helo=mail-wm0-x23d.google.com; envelope-from=swupdate+bncbdd6bwv65qpbbk6d6hhqkgqetjokzyy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="sVuwPncb"; dkim-atps=neutral Received: from mail-wm0-x23d.google.com (mail-wm0-x23d.google.com [IPv6:2a00:1450:400c:c09::23d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yT1Xt1vprz9sNV for ; Fri, 3 Nov 2017 23:31:41 +1100 (AEDT) Received: by mail-wm0-x23d.google.com with SMTP id 198sf254248wmg.6 for ; Fri, 03 Nov 2017 05:31:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1509712299; cv=pass; d=google.com; s=arc-20160816; b=kzq1RdRYHy52OciCNWlh8AOY6JCWfSZhn4fEkGHbWGUwdkM7xSLQ1lCKQlB+HWTlex StRD8/EAI7C81mnW8J24SoqNNdd1Iq4hwMlucEDb1hUwuByzzyf4zMvy6gn+NbW0iUUt mlJOCkN/AZ+TYmxl9Zw5vmFZVPC11ga/LlYbfjr7ytZVcn/RAgrEsG5bkoR1Me63uTEg 3hQHWVGfC2bU0oJ9rrEDZfc9ANxai2yXXWGHX2UKVUJTFqv24/9T/CPbZmqzRRiBij3q o/f5zzIDTWMwGR+uk38cIw4kuiY370ZVIiZxTvbE0yxjpTZWVroStxEBKaJrUweklLve S7FA== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=0bsPbjiYa+62MfOK5Z7AaIxJt4bEqKSuCfHxz2Z30LY=; b=hnfSUO7472X2pgqnDrOBz2rypZVEDoG3W431/3F2j5Qcu6NTVGUr2f6AnuI+bhUTOO KKzeRQKadNROueAePZmY+2+bcVf/xG94kUJKQcGtxDNgxBNJEzSFOSbxyZiy59W47biU 8jIS0DywAMBw+Fe+BVkwdyV9De1zkc9aqlUEtLKFbq+7KTmqANqaZfsV89uYf+Vmer8t 5/fvLHoDgL3j9QIhxbxgl4gX7N09m4lisMg8YF5LC/9ellw+qclanUcGycbirF65Za11 zF/vPtZw6IsauRojwW++McXABaUqqjZjKXtpJsUIo6tpf9X+pawBWrCupigebNIHwJ6o 8Eeg== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=christian.storm@siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=0bsPbjiYa+62MfOK5Z7AaIxJt4bEqKSuCfHxz2Z30LY=; b=sVuwPncbd+B04YGsK7dfCVlcSRY14IK4i36irye/tCQy37mexYvAEEtSdlhnv3tps8 83NUr/eROCCwrWVaP8s8K0yoT12eHpEzA8saRVpvcjoBjwzSkBt63m2kJ+lCSc3F4dMx +PjL1IXt//cRw3g4Byj6m+e/kqtEUDVul4nz3WsvW+8KcIU88/CTQLs7Qr3pv/i4SyIz rHmEa659bSFnRPQIl821ETZ4+B3qFMd0UeZfjYXuwKJgKVFk+g9/Y0WUIri/y1fKxUYX v8H40EYQYqY13LLY1hjCsg4MhxpKIK7Wv3axxrzt0T0xl6hEzJFcI1PoOU4TBCDlUokm OY3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=0bsPbjiYa+62MfOK5Z7AaIxJt4bEqKSuCfHxz2Z30LY=; b=POz35Dh7jxYgTMSb2+sjGm0wQ9E7GPeddr/M6bR0aT0HfoYImBxauwBhDRkP+K7QrZ FIvaDlxYQRzkq46XbF0uVAJMZcXAj2WPki47jR+rbcPwoxQF1Mb0gH7LofqIA9TPmyVb 61Jx0W4BVxJSyyHsfrwMS7fBcHRPfrLFd7b6Yi45jtsUoFWdMGez5GEj2WQNFz/zQwRm /qtAmHoS8ntSOjOQNHdX9J3A6Smpmu5ojt3gvL/iy6KGr+1RaiszBxXLGPtaaohVzc1h PSbHILE5bsJac0AiysJqyYbEJqe2jS+wj+7rqLKo+lc3MgWOKM/pEB4PEPDH4YZxK/cK MEuQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AMCzsaXnGbw4yfGtLEEOCh2LHUddzQjeHn5ZtGPx7+ICgi09ie2W71cj rJ3L5NvMizt/w9I5tJKaKt0= X-Google-Smtp-Source: ABhQp+Tr2wDw9n0/OA2XCtkb4W2MRih1kTQeaP1scN6wuaBN2gJTPTw/4WIIpflcG92KxOSbI1+ebA== X-Received: by 10.28.92.212 with SMTP id q203mr68708wmb.1.1509712299295; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.80.167.100 with SMTP id h91ls2864105edc.8.gmail; Fri, 03 Nov 2017 05:31:38 -0700 (PDT) X-Received: by 10.80.240.130 with SMTP id v2mr2138685edl.10.1509712298853; Fri, 03 Nov 2017 05:31:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509712298; cv=none; d=google.com; s=arc-20160816; b=GUDElrEFiQYj8ViMav2I8QYpvmiIgPJgX7oe1DwpBCCRtlNRWEqVcF1EzHfDYn6Jys +pAYXjtWwLnvSFHy3sgWB0vyXTGtnF4ub5azV4LAl9MqUlub5kzs8nDt+p/cxfRckFyR R5Zj+u16yeVvRlNhlX18Jaj/clwH9pHWJktBc52f/GHQxveoFmBMZQ0B62UfiYqN+cmw 1rqvJBZx9L8qKhL8+C/FTw/1JRnNXRt1ZYIwx7CGJoU1ZQR/V8tPto1xT4GM0XkV+5mf 0TLVB4aK79XtaTT/+Gdc73tLeynqoW9uWRLpqeSwe2KQeBNbWpNitGRvQrpF6tIhK7NY SAJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=odIwEYe4ljSiRcO6/PdW1bXJ/V5NpVZpUk/BxGdPO7I=; b=c/Tx4WWNuZRKEwhHzKh3RMY2M1M98WEpzGzF92JZEEcfORFvInboM4QgZEl93+6ZrS K4r+jju9QW+il/AvJMYj+QWvhKyIYADaWLq/J0i0ipeciuQY6eZlCGqnhGfh+YgUqtGk QwMV7Jz56pkpHHKzLzewjHKqgo3W/oxb0gZoTxv2LyAs2ILzfNHDLGvScTztuOfZeQWl fROB2U6OjVgUDedyP0aZNCH+FrVUR+Ukokcs6085XRStPrDE1dkFcq96GdB2cfdy6ikS wRV+0y7m7ETurfQNriEPYesmDK3A0UBedKDXsG1Pgvk+VAxHPRxKiZmKVzEYeSpg1WY/ E/Kw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=christian.storm@siemens.com Received: from goliath.siemens.de (goliath.siemens.de. [192.35.17.28]) by gmr-mx.google.com with ESMTPS id i6si510866eda.1.2017.11.03.05.31.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Nov 2017 05:31:38 -0700 (PDT) Received-SPF: pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.28 as permitted sender) client-ip=192.35.17.28; Received: from mail2.siemens.de (mail2.siemens.de [139.25.208.11]) by goliath.siemens.de (8.15.2/8.15.2) with ESMTPS id vA3CVcxb015153 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 3 Nov 2017 13:31:38 +0100 Received: from MD1KR9XC.ww002.siemens.net ([139.25.69.251]) by mail2.siemens.de (8.15.2/8.15.2) with ESMTP id vA3CVcFn030106; Fri, 3 Nov 2017 13:31:38 +0100 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm Subject: [swupdate] [PATCH 04/11] Lua: expose img_type's fdin file handle to Lua Date: Fri, 3 Nov 2017 13:30:02 +0100 Message-Id: <20171103123009.18705-4-christian.storm@siemens.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171103123009.18705-1-christian.storm@siemens.com> References: <20171103123009.18705-1-christian.storm@siemens.com> X-Original-Sender: christian.storm@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=christian.storm@siemens.com 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: , The SWUpdate-internal img_type's attribute fdin has to be exposed to the Lua realm in order to be able to call, e.g., copyfile() from within a Lua handler or when chaining handlers, i.e., calling C handlers from within a Lua handler. As it's an SWUpdate-internal attribute, put it into the "hidden" Lua table as image["_private"]["istream"]. Signed-off-by: Christian Storm --- corelib/lua_interface.c | 38 ++++++++++++++++++++++++++++++++++++++ include/lua_util.h | 9 +++++++++ 2 files changed, 47 insertions(+) diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index 216e44a..21c361f 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -303,6 +303,17 @@ static void update_table(lua_State* L, struct img_type *img) } } +#ifdef CONFIG_HANDLER_IN_LUA +#if LUA_VERSION_NUM > 501 +static int l_istream_fclose(lua_State *L) +{ + /* closing istream is not allowed, ignore it. */ + lua_pushboolean(L, true); + return 1; +} +#endif +#endif + static void image2table(lua_State* L, struct img_type *img) { if (L && img) { @@ -328,6 +339,23 @@ static void image2table(lua_State* L, struct img_type *img) lua_setmetatable(L, -2); update_table(L, img); + +#ifdef CONFIG_HANDLER_IN_LUA + lua_getfield(L, -1, "_private"); + lua_pushstring(L, "istream"); + luaL_Stream *lstream = (luaL_Stream *)lua_newuserdata(L, sizeof(luaL_Stream)); + luaL_getmetatable(L, LUA_FILEHANDLE); + lua_setmetatable(L, -2); +#if LUA_VERSION_NUM > 501 + lstream->closef = l_istream_fclose; +#endif + lstream->f = fdopen(img->fdin, "r"); + if (lstream->f == NULL) { + WARN("Cannot fdopen file descriptor %d: %s", img->fdin, strerror(errno)); + } + lua_settable(L, -3); + lua_pop(L, 1); +#endif } } @@ -353,6 +381,16 @@ static void table2image(lua_State* L, struct img_type *img) { lua_getfield(L, -1, "_private"); lua_getfield(L, -1, "offset"); img->offset = (off_t)luaL_checknumber(L, -1); +#ifdef CONFIG_HANDLER_IN_LUA + lua_pop(L, 1); + lua_getfield(L, -1, "istream"); + luaL_Stream *lstream = ((luaL_Stream *)luaL_checkudata(L, -1, LUA_FILEHANDLE)); + if (lstream->f == NULL) { + img->fdin = -1; + } else { + img->fdin = fileno(lstream->f); + } +#endif lua_pop(L,2); } } diff --git a/include/lua_util.h b/include/lua_util.h index 684eddf..03ef8d9 100644 --- a/include/lua_util.h +++ b/include/lua_util.h @@ -41,6 +41,15 @@ int lua_handlers_init(void); #define luaL_newlib(L, l) (lua_newtable((L)),luaL_setfuncs((L), (l), 0)) 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); + +/* + * See https://github.com/keplerproject/lua-compat-5.3/wiki/luaL_Stream + * on the reason for the absence of luaL_Stream's closef member and + * compatibility with LuaJIT / Lua 5.1. + */ +typedef struct luaL_Stream { + FILE *f; +} luaL_Stream; #endif #else From patchwork Fri Nov 3 12:30:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 833833 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c0c::23c; helo=mail-wr0-x23c.google.com; envelope-from=swupdate+bncbdd6bwv65qpbbk6d6hhqkgqetjokzyy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="CmvCbbe4"; dkim-atps=neutral Received: from mail-wr0-x23c.google.com (mail-wr0-x23c.google.com [IPv6:2a00:1450:400c:c0c::23c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yT1Xt4th3z9sPt for ; Fri, 3 Nov 2017 23:31:42 +1100 (AEDT) Received: by mail-wr0-x23c.google.com with SMTP id z55sf1536841wrz.2 for ; Fri, 03 Nov 2017 05:31:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1509712299; cv=pass; d=google.com; s=arc-20160816; b=0KlBVCXZJTMCO/C/S3GCqa7tMmw9xGstXD439hYtFAZ6HaSOcS34z3y//10JpbJDv0 Zvvg/Eh0B/Q7sz2cwWHqf6qdE4rf2cFS2l1IsuMWAIYRjshs07jKwBJSNtDuou4QciSz QnylWCwWDb5LvKaPSGk/nJ6QGZjD+z5i53E4WjG+1hFdHFD8a+Hf6B5X7JkfVMQhOgM0 7d4p2U1hzRJu5c/SMgyEOkS/L+b2SYIgA4rDH2z0M4cELkri6m+4BfXQGdWg/0t5R4BP dJaCShpM3hlagDnSMt+sQjrYaNdaFRTz/MNYUJFSOPx9vY3Yny05N3AvIeLs0ilIKI3s foAw== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=Dfn79COupgErv+6oi5WSeO0bb50IJ7MYlrV6TcxsiWk=; b=kADss0IS/5u1TwSclNp5AsiRGm01r2zmJU3n3xMq9rJHRLxRcs6h3KWzT4J3g0L4xJ +THuDVHNgzss8nOhrz8+hRAysroxC7jl4WUHHh0ATBoGeo/vzL28EjN94qURDHpmkIur EljuQK73Tam84xV9scoUo9u16/GBBQ5uXAxQlPCEAFbaS8pfhTSDUqgM0wVOwdiJlXTR f440Z5BaSTCn3DuugSRIjZpaVzSWwdoaITT2aDMM5T37YOgxCTcAr9rdUl5n7hDAAONY jaXBYdpcIdZD7eB1iE634kDAwIedwIDjVSb0hdDynnOsqtALM1im9PQ8F+r3/7NKiOP8 mliA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=christian.storm@siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=Dfn79COupgErv+6oi5WSeO0bb50IJ7MYlrV6TcxsiWk=; b=CmvCbbe4G4ButBlxUK/NJtViGLtnOH19KBgTyw1Wm6oEaEpBNxyRneTaB+llPFaNg6 Nf9Ozlpe/ccqzu2IY+ncNZjbRzUaYL3OOahhBDdbZlL2GBBFkdQvS8zbuqXN8MtbtN1a sKJ7xuxdItq5rahiQUjB50+KHEJcPrUNX4rFkiiAyiUtzyIdZw2lN5tpP24uSyOVnlST 2r6eZGMvz04IoCufHYXXuOuoDE5b79LmUZ1lFE8yZ0Vg3v9s/Axtg6O7uRqwvPtyK2YM BABNL9AkDcEHWntNXc8ko/Zyh4bqqfz/DArinNAJAMV8QWrZvcIqfvaSXnUexPUPGNlW fw1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=Dfn79COupgErv+6oi5WSeO0bb50IJ7MYlrV6TcxsiWk=; b=WJTpve8mLQvCliAAORG3YKbslE7VZD4WVk9TeZKHFxIQ9laRMyM0J6Yl3RQX842t4u bVjROFatergH4SVOtB/XkpxxSiMuQ7x1/hTrQIjq76LEN9rv2xUdA9P8bv4sFWByNbEB wwIIERs2lXjEr7Gc1CswdMp7OCCKu/LEBUj/o9jvc5vzc9JjcpVNJVp/0iaUToZ1mQVb uCQG7cxhyniAux4S3fpi6RChxIpmg8YX6kkYFfsCswaa3dooqMx4Zg3dq6OmR23Z5Oz3 OUM972dUAnDN9d8Kgt0ObDksK2QIsBjVXo9NH5yJ4xLZm2TCjdbNZRtGn+J6CPQCE/nv lteQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJaThX4HGzCpgHdOdTfGyfp0z5ywq3bp5EbJTsLKZg9/Cum3ujH4+XrM EdRqBS1XSUp/hNgjg+GtNVg= X-Google-Smtp-Source: ABhQp+TTqXg7gZwX0vsE0OQrssFKPMzifGqJaPNlEqQPy91NK0TCFZIm0g3RLNbo8gGNxLy3wKNNyw== X-Received: by 10.28.105.195 with SMTP id z64mr7191wmh.0.1509712299143; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.223.191.15 with SMTP id p15ls1287083wrh.11.gmail; Fri, 03 Nov 2017 05:31:38 -0700 (PDT) X-Received: by 10.28.190.24 with SMTP id o24mr724553wmf.12.1509712298781; Fri, 03 Nov 2017 05:31:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509712298; cv=none; d=google.com; s=arc-20160816; b=Hd8orXZzXzf2h/J9A7YDVYD14kyMd6hn0MCcHVeD21wiWfw65/TwHeukrTp/4d4Zih ci3A2cUCY/iJ0myFUg3e/cZhAUbBf3mzN5g+ffgaXw3X4GDiqTbRGxXbM/2Nkc8VptxJ qyzf4UoBMVi5UdQDScfXhY4INOTY3XtvxIeOZ2kGoe90qM3U9tUdVxfx7O+a0msy+bax UZMjZxQYETngLxpSrvH+SSkmPYxonV322PSefy45jQY66RIpG0Y6OSusLQcCL6F/9QTU nip0CjcSqVhyEvMn1NjM6tNreMzCW/gnpQ1CqIDNAIE3ebSjsrHhmRbFfxUgdJOxpp4Q k4UQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=SZ2Lr54e+0xjV1FD2Z9Ozu5KdIt6KmE42+0XcCUPUno=; b=CNvr1xIpg1p9S9G5fpCOvoxM2ZL57utb1CxZUvEiazH6exGhaRTtUcCX/zGZ9OMUGN 4tHyj9rjn8MkIrES/lMUKYdH+iukDdriGsoddYW55bBEODvjuuyiE2apRqWVqKyqfthb +dc2rGjix4YVjn8xI2KYI3eSTsviyp5Plp7EWi4YkRquyJrpya5XwutUwGP6hrVGmeZn lxMtSlMAkAvj2XhdEchKbh1MGr4v6PsqWA8fqYYOq1lOnuXQtOWpyzo4qlm0QWyz4Lzq UpHnrzxY9okGgnq683XS9+4hPFXub4MLzo0f2ePWsB3ZMu/0qVsgNTVpiadE5AhuT51F /utA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=christian.storm@siemens.com Received: from thoth.sbs.de (thoth.sbs.de. [192.35.17.2]) by gmr-mx.google.com with ESMTPS id i76si179683wmd.0.2017.11.03.05.31.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Nov 2017 05:31:38 -0700 (PDT) Received-SPF: pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.2 as permitted sender) client-ip=192.35.17.2; Received: from mail2.siemens.de (mail2.siemens.de [139.25.208.11]) by thoth.sbs.de (8.15.2/8.15.2) with ESMTPS id vA3CVcKP023692 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 3 Nov 2017 13:31:38 +0100 Received: from MD1KR9XC.ww002.siemens.net ([139.25.69.251]) by mail2.siemens.de (8.15.2/8.15.2) with ESMTP id vA3CVcFo030106; Fri, 3 Nov 2017 13:31:38 +0100 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm Subject: [swupdate] [PATCH 05/11] Lua: don't extract image prior to handler call Date: Fri, 3 Nov 2017 13:30:03 +0100 Message-Id: <20171103123009.18705-5-christian.storm@siemens.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171103123009.18705-1-christian.storm@siemens.com> References: <20171103123009.18705-1-christian.storm@siemens.com> X-Original-Sender: christian.storm@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=christian.storm@siemens.com 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: , In order to be able to call copyfile() from within a Lua handler or when chaining handlers, i.e., calling a C handler from within a Lua handler, the image shouldn't be extracted beforehand as this extraction, e.g., moves img_type's offset so that the Lua handler would have to seek back prior to calling, e.g., copyfile(). Instead of extracting prior to calling the Lua handler, rely on the Lua handler either to do or to instruct the image's extraction, e.g., via calling copyfile(). NOTE: This is a change in behavior and breaks current Lua handler deployments as they expect the image to be extracted. Signed-off-by: Christian Storm --- corelib/lua_interface.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index 21c361f..85a1d36 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -535,26 +535,11 @@ static int l_handler_wrapper(struct img_type *img, void *data) { int res = 0; lua_Number result; int l_func_ref; - int fdout; - const char* TMPDIR = get_tmpdir(); if (!gL || !img || !data) { return -1; } - /* - * if the image was not extracted, it loads - * images from a storage. Extract the file - * and copy it into TMPDIR - */ - if (!strlen(img->extract_file)) { - snprintf(img->extract_file, sizeof(img->extract_file), "%s%s", - TMPDIR, img->fname); - fdout = openfileoutput(img->extract_file); - res = extract_next_file(img->fdin, fdout, img->offset, 0, - img->is_encrypted, img->sha256); - } - l_func_ref = *((int*)data); /* get the callback function */ lua_rawgeti(gL, LUA_REGISTRYINDEX, l_func_ref ); From patchwork Fri Nov 3 12:30:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 833835 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c0c::23a; helo=mail-wr0-x23a.google.com; envelope-from=swupdate+bncbdd6bwv65qpbbk6d6hhqkgqetjokzyy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="c/yqwZ3m"; dkim-atps=neutral Received: from mail-wr0-x23a.google.com (mail-wr0-x23a.google.com [IPv6:2a00:1450:400c:c0c::23a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yT1Xt2V2dz9s7M for ; Fri, 3 Nov 2017 23:31:42 +1100 (AEDT) Received: by mail-wr0-x23a.google.com with SMTP id j15sf1515918wre.15 for ; Fri, 03 Nov 2017 05:31:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1509712299; cv=pass; d=google.com; s=arc-20160816; b=Ncex4YqJuy9pK6s6Bg7UzQj91YEPfPQPUW2mcwknTPDG1Gdw6PCAiXVriIO8LyKzhQ HjYfM4d1nLwpO2W6eU71St6Z5AO263TgN9CPInsiOSAGcj+o1kXlQydxQe1deuVkOTSm /1KPJda5pUYAQHvpQFmSiXfCS+gg9y5cXzqhUkQprjQumqIToauSrApW1sq2m2mnnJ0o WVgj+O0sl/yYcWn4yaROzhHUZv4BIxKGP34kKgnYrKajUKEwsw3T8/tVs4dtbcLODSvi qcW0Ws05b+VyRgyur7FCQzIXzexL+qAkbbtAsQbaDfyJsNDYmn1fOdzpoQ6o71rRpjtb poYw== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=SJuRH/K3XAwpycrRTRRGlBhCkj216zt+jUL60Z9nbcI=; b=XT0lky7X+5l+1ipVuLXwHAee+K9ZV6BsMV3Az8n2gbG/bAE9uZO7uWzRU7zsPMC+DV ncSbccMaL85hG079CBEDQXJlLVkHwesgg5MDl9gKArpQMavp979YvKLF6Oz/DHI6Q0C4 fcFTYAdxC2Uhp1d3sTvtE+Xs3132x6Q1egGL9miCxyKV1gAWtTQ3LJg2N+xqqy66Vxgu G1e3BGEnAq06Jy/oXZPvkaNoHIaz/Yy24Cn394CLZ1QEfYVBT1f/0NmdeBM6o7H0KMAo hXLq57HiVypWWuFWyiMrHk6HZwf243obbT1zLJPAFzyn4dkfbQiTzPe3+dc+nvs3lvhc UkLw== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=christian.storm@siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=SJuRH/K3XAwpycrRTRRGlBhCkj216zt+jUL60Z9nbcI=; b=c/yqwZ3mdUDE8BW5iHvOeH+2Bjbogci6vM/cSTFfDojNzPs8AjQkwNR13vL+sR8Nrn p7lZ3eez9M/Y0M+zWIz5AFJdecPk1mHAYcykHXTmTbPEYAgv2o6v2XCIrfUwlbJWLBHo eBCZdEmdEOVV4YQVZ+6sLh/gMozKUm2bbbSGpW0uVyiWEdbrmG4pM0XUPxhvo7FgfO39 R/pnA8xVOAHefykNawHpRnu8bZJxii6xW67qMpWr5h26r1ZnODqKZ8Rm5am3RedtT0Sn ES0fuB54O5+VaSpKuB96P9nmk3jqVyc9eY6EYcfmZtuPa/QpnTJ5lnM+WhG1GqgRKO0M WeeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=SJuRH/K3XAwpycrRTRRGlBhCkj216zt+jUL60Z9nbcI=; b=eSnNMI5tR9YuoZXLitVbmBUb0WFozJxPRUqAlbPykMzKq42WxdjXlcr0VPEWbGkdbu w+FEpRiOkEOxx6G0NnDaWcphPK1lDZSdDgEs0SpVaXY5/my4I+HDsDhEgCzogOeKiLcQ TNUYxT4VjTeFwq0kmsaZkrORPfRcNXQgW2PN6PK8rErXKmAKuPNx90XbRqenEFDwxWSl 5my9f1OHkldor5QkyaiGpgHG5WmUWDz9mOQKS1kEXrRQxB0xIJ78gWSacaM7vacv9DGy +qt0FpEpFrcs/EITh6201uhcVbmvlSYWUwNIttRAUrxGG8+03nvcTQK3+pgkQzOBCpsR rqeA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AMCzsaU9pvSQ3beur8bWoOWuev8og5lYz964mTpl3mZpJooLiTlPX1fm 5aiL3UJ7KaiiT1F0IfOn1QE= X-Google-Smtp-Source: ABhQp+S9FEFPWt9S2bSmTpAIqqYWMUsI1cpbO417/JVEGYJZtMVCcUNU3HiqILlMLR9/yEw9rZd3Og== X-Received: by 10.28.202.3 with SMTP id a3mr66861wmg.6.1509712299209; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.223.173.164 with SMTP id w33ls1400913wrc.5.gmail; Fri, 03 Nov 2017 05:31:38 -0700 (PDT) X-Received: by 10.28.141.149 with SMTP id p143mr719288wmd.13.1509712298925; Fri, 03 Nov 2017 05:31:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509712298; cv=none; d=google.com; s=arc-20160816; b=MIH3YD+dEs+nMneBUgQFiDt7AKmZGjlduEwKHj7B7LJGUrNabjP4Dau7Rk9xr/d3fz ayvMpPJawHqh1rxMQKUCIZj7d1DCP8oRnje7UtBzkl2rE/7GSdrmq1emO3DWEjt6t2Fr +5aX/cZ0b1BSeX9gK0NtgrANJojSrKVGkvO/tTx9YtDy9BJAOcWtcHVr4S2mLAOTG68G TlV6Pv7KMcQhoYIKv0dT/qD27dfsRwfAT23TwDwjQvvXJ9lEkI1wpkzWL5djq9Fx8Oek X7TMM7v3lwW2t/swa+S0zzij5ffykntbYuLy2qklCw1nYEzDYW7q96GIefPLacsAcbct 87Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=YfedPGVhvWbaJ5LDO9s8CVVP4/Q17NrqJANgGpps4hA=; b=HydaTZMdZvDjom03qogNLRTwFBAhrKAT3Az5eIXioGGGeK/kslxNnl2j4cfMYma/Tu qlBYjhgOrw3iwCLSj9b4QlCU8wRlfzsr7P6k+t9SqoQkEhuaZ8iF1lPwwSZD1i7vU0Ma ESTc7xy2Y+2xUlkzzYTxG345MMQ1E1LC6Rrt58RJiu8W8pw2w7LlwjYe5cHo0PEYskFZ 0fWR/JHnoxJbCHsnWsA/qC/WrJBZ6IBhYETXGPlK3z9W2u5zen4cuUl1D2fZz/tLDA2j JjdTHkLloDB0yvoVwpbryxNPFHxGDVTEb0Xzfpgf7Arw0XQQiid1Wy/tnZ79TwDqyS/k c51A== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=christian.storm@siemens.com Received: from goliath.siemens.de (goliath.siemens.de. [192.35.17.28]) by gmr-mx.google.com with ESMTPS id b123si198928wme.3.2017.11.03.05.31.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Nov 2017 05:31:38 -0700 (PDT) Received-SPF: pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.28 as permitted sender) client-ip=192.35.17.28; Received: from mail2.siemens.de (mail2.siemens.de [139.25.208.11]) by goliath.siemens.de (8.15.2/8.15.2) with ESMTPS id vA3CVcUB015169 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 3 Nov 2017 13:31:38 +0100 Received: from MD1KR9XC.ww002.siemens.net ([139.25.69.251]) by mail2.siemens.de (8.15.2/8.15.2) with ESMTP id vA3CVcFp030106; Fri, 3 Nov 2017 13:31:38 +0100 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm Subject: [swupdate] [PATCH 06/11] Lua: introduce method to chain-call C handlers Date: Fri, 3 Nov 2017 13:30:04 +0100 Message-Id: <20171103123009.18705-6-christian.storm@siemens.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171103123009.18705-1-christian.storm@siemens.com> References: <20171103123009.18705-1-christian.storm@siemens.com> X-Original-Sender: christian.storm@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=christian.storm@siemens.com 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: , As the artifact's data is not unconditionally extracted and img_type's fdin is available to Lua, a Lua handler may chain-call a C handler to process the artifact while having the ability to do work in Lua prior to and/or after having called the C handler. Available C handlers are exposed to Lua in the swupdate.handlers table (as keys). The new Lua function swupdate.call_handler() can then be used to chain-call a C handler by providing the C handler's name and the image parameter to it. Signed-off-by: Christian Storm --- core/handler.c | 15 +++++++++++++ corelib/lua_interface.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ include/handler.h | 1 + 3 files changed, 76 insertions(+) diff --git a/core/handler.c b/core/handler.c index 7e9f3ed..4793288 100644 --- a/core/handler.c +++ b/core/handler.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "swupdate.h" #include "handler.h" @@ -31,6 +32,7 @@ #define MAX_INSTALLER_HANDLER 64 struct installer_handler supported_types[MAX_INSTALLER_HANDLER]; static unsigned long nr_installers = 0; +static unsigned long handler_index = ULONG_MAX; int register_handler(const char *desc, handler installer, HANDLER_MASK mask, void *data) @@ -76,3 +78,16 @@ struct installer_handler *find_handler(struct img_type *img) return NULL; return &supported_types[i]; } + +struct installer_handler *get_next_handler(void) +{ + if (handler_index == ULONG_MAX) { + handler_index = 0; + } + if (handler_index >= nr_installers) { + handler_index = ULONG_MAX; + return NULL; + } + return &supported_types[handler_index++]; +} + diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index 85a1d36..9694480 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -53,6 +53,7 @@ extern const char EMBEDDED_LUA_SRC[]; #ifdef CONFIG_HANDLER_IN_LUA static int l_register_handler( lua_State *L ); +static int l_call_handler(lua_State *L); #endif void LUAstackDump(lua_State *L) @@ -460,6 +461,7 @@ static int l_get_tmpdir(lua_State *L) static const luaL_Reg l_swupdate[] = { #ifdef CONFIG_HANDLER_IN_LUA { "register_handler", l_register_handler }, + { "call_handler", l_call_handler }, { "tmpdir", l_get_tmpdir }, #endif { "notify", l_notify }, @@ -509,6 +511,15 @@ static int luaopen_swupdate(lua_State *L) { lua_push_enum(L, "PARTITION_HANDLER", PARTITION_HANDLER); lua_push_enum(L, "ANY_HANDLER", ANY_HANDLER); lua_settable(L, -3); + + lua_pushstring(L, "handler"); + lua_newtable (L); + struct installer_handler *hnd; + while ((hnd = get_next_handler()) != NULL) { + lua_pushinteger(L, 1); + lua_setfield(L, -2, hnd->desc); + } + lua_settable(L, -3); #endif return 1; @@ -596,6 +607,55 @@ static int l_register_handler( lua_State *L ) { } } +static int l_call_handler(lua_State *L) +{ + struct installer_handler *hnd; + struct img_type img = {}; + char *orighndtype = NULL; + char *msg = NULL; + int ret = 0; + + luaL_checktype(L, 1, LUA_TSTRING); + luaL_checktype(L, 2, LUA_TTABLE); + + table2image(L, &img); + if ((orighndtype = strndupa(img.type, sizeof(img.type))) == NULL) { + lua_pop(L, 2); + lua_pushnumber(L, 1); + lua_pushstring(L, "Error allocating memory"); + return 2; + } + strncpy(img.type, lua_tostring(L, 1), sizeof(img.type)); + + if ((hnd = find_handler(&img)) == NULL) { + if (asprintf(&msg, "Image type %s not supported!", img.type) == -1) { + msg = NULL; + } + ret = 1; + goto call_handler_exit; + } + if ((hnd->installer(&img, hnd->data)) != 0) { + if (asprintf(&msg, "Executing handler %s failed!", hnd->desc) == -1) { + msg = NULL; + } + ret = 1; + goto call_handler_exit; + } + +call_handler_exit: + strncpy(img.type, orighndtype, sizeof(img.type)); + update_table(L, &img); + lua_pop(L, 2); + lua_pushnumber(L, ret); + if (msg != NULL) { + lua_pushstring(L, msg); + free(msg); + } else { + lua_pushnil(L); + } + return 2; +} + int lua_handlers_init(void) { int ret = -1; diff --git a/include/handler.h b/include/handler.h index 04165c9..f2896ab 100644 --- a/include/handler.h +++ b/include/handler.h @@ -57,4 +57,5 @@ int register_handler(const char *desc, struct installer_handler *find_handler(struct img_type *img); void print_registered_handlers(void); +struct installer_handler *get_next_handler(void); #endif From patchwork Fri Nov 3 12:30:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 833831 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c09::238; helo=mail-wm0-x238.google.com; envelope-from=swupdate+bncbdd6bwv65qpbbk6d6hhqkgqetjokzyy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="EPrf1D32"; dkim-atps=neutral Received: from mail-wm0-x238.google.com (mail-wm0-x238.google.com [IPv6:2a00:1450:400c:c09::238]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yT1Xt1sl7z9s8J for ; Fri, 3 Nov 2017 23:31:42 +1100 (AEDT) Received: by mail-wm0-x238.google.com with SMTP id e8sf265074wmc.2 for ; Fri, 03 Nov 2017 05:31:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1509712299; cv=pass; d=google.com; s=arc-20160816; b=UGeCfG6k+rRh1vq945SzpXUie6WD73fgNyLzneyXzRxuT2MrfDihinSYp09rohjaqD dcDvOI6iYm1oh+AK1qqDM0w0ByWKAKgEDIQVfisW3zZWxfs2MHGqg+RifkPNkUglp+BG /+nryLol913hRu36ZUpCSLcAFDK8jJ8KRDoW5vKviHRyf4L6NllLSvGEF6gTEDs8imXe gQ72tfxC+P24LxDa4pl61GsPsGYOKU7cW6+k0U/rNIsgz3PvGxaLCZAn6Vcd1Rsq49KI T8cXlK+xCLKV7vU11qdc4EamiU9rYRkCuQ1wDq8NOb6lnr24MvMSow1l0m8OO2/qcPtU zv3w== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=yskq6u22yHTJ2vS3uooqtd6SxlvNXoJsbq/tiZBUBzI=; b=zA7gG3/1i/S+au975Ik/hJzcrM6age9II1BognCa6fVihdK6eqNl3BTBz2nA1n0hLu k/7conqhFltIqG2I/hNZtQxKw4yy3d9iX8xG/WuYKMhknk3BnHtoNdhpDGQ6PQ/I4psB 4aM5y0wzrcJVQ/Yhjd5/YSnW8+rdv+jBBerOjGVojNz0puo3x/kEN0tR0urej8ZEDuXC H0hvOewhywY/adzfbZuCJj2Mbu/00T8Iw/HV1hghPz8qnn2nFYxlmzWmQy2Gzr8LvDDm OagwGsFa+x9Pqs+1GB+8xvA/0BSZ82SrtCs34eUksRlAFLnonF2ZuHdNOosAJaOKnbuV 8WTA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=christian.storm@siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=yskq6u22yHTJ2vS3uooqtd6SxlvNXoJsbq/tiZBUBzI=; b=EPrf1D325bDYv5CakmqVigy0aQz6MNNF+SEADwlyY5WADTHt7YEdox1pDw5KgoofiG w9nXqlbP771ZZ4A5rQo8w8/bR/XPvMDl9+lcDqtFZHH2JHzAiLhiN/WEJMoNaSX9VSGn sB49BTStnM7gfDoa7UeHV6KjNvE0Cs7VB0sJzJSFF6hC15rI43USAmYMkzdrEP8jpwVL oNwh16nK2+tlXWmTrNwt/6fbbjWDT053dAdL0u0nQX/G4jDj5TScvRaRl09YgUwMfEbZ NtRyjhQGqICcjKUgIRKic7vrFiH15+Co1Ml86W/4AWkJ9C/tN4PaxVAM0DxwMN2RsyNl FJWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=yskq6u22yHTJ2vS3uooqtd6SxlvNXoJsbq/tiZBUBzI=; b=jdy57zB2Kk21qZwSqMv/ep+VMfp/aV3hu3RswKYPowvogozwE1OnZgxlO+Xh8YEZWh T8VdMVwY2Hn5UDOEwT9xVYg31NdcbkJSrwA2yCjYMQqHXn5CtjmEGYj9DlMREgslPZt3 DemSyzhfgEpyvnrRxeYAfQZCA2rl22APYr/un1KhpRMdIzQVcgDL7Vdf4JXPFhFjgNUk IsHDyLsPomdiIT3Dy9s+ID14co4cGdMRm9zQq6WM0L1B9zZswbt8G1ndx8e0rmvZagqV 4vTCgjqGtUILDKxExxK/zHJngkvxm4fw9hQ5G/Ir8wicUovV1ZhNXRuZCzZSV0U/sqgU j5Fg== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJaThX4n/GD2B+USu7Y3Jq9GwqFTmTM/bCE87A83sO6LBm2ckb8yQwmi eZiz5iwfEyEIpRjD6MwW5dg= X-Google-Smtp-Source: ABhQp+SYhCeI2YI9+p1VOVtwRB4mRQxRT0AQgnX9I440N5yeOO8MmzhPxVxIMEkP1ud1L6nL2EBuaw== X-Received: by 10.28.237.3 with SMTP id l3mr7558wmh.2.1509712299353; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.223.191.15 with SMTP id p15ls1287089wrh.11.gmail; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) X-Received: by 10.28.152.132 with SMTP id a126mr764923wme.0.1509712299095; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509712299; cv=none; d=google.com; s=arc-20160816; b=j09XsGtOOSLH9jRHT5pbuO7mi8rInAMi9M0v2aeaZvyxEz9QKqd/g+O8TNo5Zyv4lS ZDSjgkc2o3WzGXIAZzfxjF0i6KnnVBugVHWZgTEvdAceRbnQcnc1vDvXPg7GzFp0qqLl qmruG//XjKwku/krHMxZ2VSj4lIx6IDNJ99bltoAc6hQV/ObA9AIqyGDkXFXyQAoC6Lw tC4mp0ksDFOMiLMlzOTLHHz/65cgJUx8Js/5ruv6Zq/a+c2QNojNkEpsgH0sW6IXeFKj JtLK3XsfrGRu4++GJta+wRj6P9prWPVEHZQE+zocR9Uxya0F9X5UjNbiY7o1yqiH91RJ rZtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=AGy+ngLrZzb8bbaCwuKX9KbETpsh37U/6FvBLaHrCB8=; b=lKlzBqbO+jMhGqPYarbK3Vr7n/h49Xs4kgC0JQtxepN58xZbnt6SmN0N5rJwu/Tjou IW+g6/9671bQ8T85XyMkPwR+fEMPDHrsVf5EQR+hZrOt6hrsmBZ272VdGYs+DwgpIWI9 T9YI5Q2rHEk5+jS3wIJcpMJ9+Kb+8EhpC0lT1Tiqy5oxw8uSZg0A0GLhLRPW6prG0JNa /dVntZnhFgwX90sN+kr2j4BBGToGgYPqsQebSsIBziXdAMyblQlgK0bIHih1TOLHnT9d aelajiFPWiXSEw2RWyx4FaVst0m9AsMt33TxyXf3szXovfNnD0XvQULmyBqd7iualM9l udhQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=christian.storm@siemens.com Received: from david.siemens.de (david.siemens.de. [192.35.17.14]) by gmr-mx.google.com with ESMTPS id l9si374191wrf.4.2017.11.03.05.31.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Nov 2017 05:31:39 -0700 (PDT) Received-SPF: pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) client-ip=192.35.17.14; Received: from mail2.siemens.de (mail2.siemens.de [139.25.208.11]) by david.siemens.de (8.15.2/8.15.2) with ESMTPS id vA3CVcn0021924 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 3 Nov 2017 13:31:38 +0100 Received: from MD1KR9XC.ww002.siemens.net ([139.25.69.251]) by mail2.siemens.de (8.15.2/8.15.2) with ESMTP id vA3CVcFq030106; Fri, 3 Nov 2017 13:31:38 +0100 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm Subject: [swupdate] [PATCH 07/11] Lua: introduce image:copy2file() method Date: Fri, 3 Nov 2017 13:30:05 +0100 Message-Id: <20171103123009.18705-7-christian.storm@siemens.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171103123009.18705-1-christian.storm@siemens.com> References: <20171103123009.18705-1-christian.storm@siemens.com> X-Original-Sender: christian.storm@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=christian.storm@siemens.com 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: , Introduce the image:copy2file() method implementing the common use case of storing the artifact's data into a file. Signed-off-by: Christian Storm --- corelib/lua_interface.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index 9694480..a551cde 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -20,6 +20,7 @@ */ #include +#include #include #include #include "lua.h" @@ -55,6 +56,9 @@ extern const char EMBEDDED_LUA_SRC[]; static int l_register_handler( lua_State *L ); static int l_call_handler(lua_State *L); #endif +static void image2table(lua_State* L, struct img_type *img); +static void table2image(lua_State* L, struct img_type *img); +static void update_table(lua_State* L, struct img_type *img); void LUAstackDump(lua_State *L) { @@ -265,6 +269,60 @@ static void lua_number_to_img(struct img_type *img, const char *key, } +#ifdef CONFIG_HANDLER_IN_LUA +static int l_copy2file(lua_State *L) +{ + luaL_checktype(L, 1, LUA_TTABLE); + luaL_checktype(L, 2, LUA_TSTRING); + + int fdout = openfileoutput(lua_tostring(L, 2)); + lua_pop(L, 1); + if (fdout < 0) { + lua_pop(L, 1); + lua_pushinteger(L, -1); + lua_pushstring(L, strerror(errno)); + return 2; + } + + struct img_type img = {}; + uint32_t checksum = 0; + + table2image(L, &img); + int ret = copyfile(img.fdin, + &fdout, + img.size, + (unsigned long *)&img.offset, + img.seek, + 0, /* no skip */ + img.compressed, + &checksum, + img.sha256, + img.is_encrypted, + NULL); + update_table(L, &img); + lua_pop(L, 1); + + if (ret < 0) { + lua_pushinteger(L, -1); + lua_pushstring(L, strerror(errno)); + goto copyfile_exit; + } + if ((img.checksum != 0) && (checksum != img.checksum)) { + lua_pushinteger(L, -1); + lua_pushfstring(L, "Checksums WRONG! Computed 0x%d, should be 0x%d\n", + checksum, img.checksum); + goto copyfile_exit; + } + + lua_pushinteger(L, 0); + lua_pushnil(L); + +copyfile_exit: + close(fdout); + return 2; +} +#endif + static void update_table(lua_State* L, struct img_type *img) { if (L && img) { @@ -292,6 +350,12 @@ static void update_table(lua_State* L, struct img_type *img) LUA_PUSH_IMG_NUMBER(img, "size", size); LUA_PUSH_IMG_NUMBER(img, "checksum", checksum); +#ifdef CONFIG_HANDLER_IN_LUA + lua_pushstring(L, "copy2file"); + lua_pushcfunction(L, &l_copy2file); + lua_settable(L, -3); +#endif + lua_getfield(L, -1, "_private"); LUA_PUSH_IMG_NUMBER(img, "offset", offset); lua_pop(L, 1); From patchwork Fri Nov 3 12:30:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 833834 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c0c::23f; helo=mail-wr0-x23f.google.com; envelope-from=swupdate+bncbdd6bwv65qpbbk6d6hhqkgqetjokzyy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="AxFqEc8Q"; dkim-atps=neutral Received: from mail-wr0-x23f.google.com (mail-wr0-x23f.google.com [IPv6:2a00:1450:400c:c0c::23f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yT1Xt2bcLz9sNr for ; Fri, 3 Nov 2017 23:31:42 +1100 (AEDT) Received: by mail-wr0-x23f.google.com with SMTP id c21sf1501650wrg.16 for ; Fri, 03 Nov 2017 05:31:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1509712299; cv=pass; d=google.com; s=arc-20160816; b=tDmO/LaHfXC5CCWvohhldzkRsQ1ATv/S1xL1kIDDwp3UHhVksyWeKvyjAuC+pQkcUh SYTfLl64p5n01n8PTqKVjMnDT3KWUsZ5aVW2pwW9v2QPXNJSIvb+OfkzICHzCIfF0WKt 9T0mJfSZD+fd4pNyKSsHubbpns2h1JcHhATutCGEM8rHgucPmXftbHJjnPkC6Spne5pN fSi5pHFyiCi9Zz/CudL4F3MOltli4Xio+Twi8qahYVgIld5ZQPhN0XAj3HNpbB/WI1tB za9WZ6bpe48TmtuGl0dVSRf13Sea9rMfcNwBbYdAUo6n0qmfhSlJgmlbIf/aF4nNeaGL GE2g== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=iwHsZlJ7DPtehGTh1nFRxoL5zzKD+TuFp3OA7IpiLqU=; b=eCLlJJ77TPl4gm1QnA5b8OWbgNef1RaTVzw2lvgG54nXFRcou5cyIxBrRVR1EcFwp8 Ldj7QlTn5UTPA9A3EnmEKWVMQB/9jfdgiofoYQFRE4ftBOhW9WCRa/4Uwzb43Pjl/YAv W+v9HkIwZfQ9ODwOiVXxWCMDdlX8nEH6b7v8RnM+AENt+VXNNJMLKNC4hD4qRplv5ciO JzRz/5UtemTI0gtEm8toLksuv4nmbxQVBGgYIx6y8r0CoWx/utw+S8VNyeTrdTAFVt2n hvOgqLuJEnnoqa7Ebn9WMZumKFGnNwnIHz+zDRe1akZr9V+ON/dAopwbj+L9h9xOUC28 3TNQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=christian.storm@siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=iwHsZlJ7DPtehGTh1nFRxoL5zzKD+TuFp3OA7IpiLqU=; b=AxFqEc8QidLZ3eIIL2OxQbe35zn4mOcXrMObNa+VCU9oipg6tJEpOX6kDItc/VjgOg pnopLrB4dktSHmIZE6WT/8mJEBoU7hBtWji3a6ot8Apt9yR5CzhQhATYTG1wP/QjmtRi z2AgpYqN+gRniX37vWXMyZZ1BH3lj0OANabOnXp2L5GDvXTeVW+xI0F2V5pwn9KGRS1c McFdKY6hbOGixdwaKrAY/16YYH0SK/NC/u+LaFG4FKKLRPJQe0JOMReyMjkpEnsGyJ4v GXD3Qk0wd1bnPRFhzY8XaBjnlmXdLjoHWF6KY11IHVrQugxudilKXkFztmstown2lhmb 1IQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=iwHsZlJ7DPtehGTh1nFRxoL5zzKD+TuFp3OA7IpiLqU=; b=DT0H5oajv09yHT35B2UVhVeYb5Qs8GWh1kYJoGnt7OYNe6mckUx24vS8YTefTcpwaw 0NXkuCSNjYWjcaCrWfrRJsTfkrSrFdnAPjtQrvClPTgkVP/3MxfVrwQoCnjaL0Zrn2Hy Au4bEVeqzdubZ/WvCvYCgKAB2mdgESsk8flkNaugr5ccyQNWRfLL9VFvcOZ0JtlzQvJr YUurDkrNRRIGkhiSqBQsVKso8c/FXZnJ7qJ6kiXBwqjEU1cx0rBQ+bPakXx49Smz8dG6 r1cCm0Ni7RXyutkC4C2ZtrKbO1BSWRgOaMBVu10b2roQowdCsIv4lln3Up1d4Yl5+9oe hQ1g== Sender: swupdate@googlegroups.com X-Gm-Message-State: AMCzsaVgUvotBhZC7VGlEssDL8rC9rQDIksMPOflbpKGiLxRD3myYZdT 4UHub8zrm11UgWMI3NHdOQI= X-Google-Smtp-Source: ABhQp+R7Yuyo/Ckm32RtiYcz16ICawMFz5ygSlS2E8QYZcXUSVdCPqIhCM8eFYxNgslX7PI71H+WIg== X-Received: by 10.28.227.138 with SMTP id a132mr67494wmh.7.1509712299478; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.80.147.19 with SMTP id m19ls2870618eda.1.gmail; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) X-Received: by 10.80.222.130 with SMTP id c2mr2135327edl.8.1509712299062; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509712299; cv=none; d=google.com; s=arc-20160816; b=uog0CxKlbZsK803opTYXPDJs66cnrdGOkTPTM4w77AqdsVk4t6VvmYvHQyLl136YtQ z2UcFvuHVa69tDlzz+BlDFZYcriAaR7T96vG2JK7lig5UHUiHib8FM1bc1hPa1+z2RQ+ +gfUx7ZDLHbfDo5MT0wp6Jazmg4iEzDmupR2XS2F7AIX9/yRpgLHhXjzaZiFgsR+aSMz 4z5+265VadgGv8Sw+3KzmcwEuUIEwN7bnGeLO+KrCfT9uyi11E98OGM1VobDNX2iXf4Z baOKmixnZr6y/ZO/n+q97QbqYSPVsLl5zLx/shA39SIU20CkRvNkNQiSTrls6RnwE2UT 7DyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=aqk7b4FHL2/GrfEth5EIqDxF5NbM0Q4TDN3CdqhJ05Q=; b=EWOkst23KOQjJxX1hlv0xh+3wu9AcRF0NWEc2p31cNRGAJm/I3e5yFDha5r9UlI7oj TlsSVIUCKBi6+tXbxfURLPgA0LF8Wwd8Iv5/mkXMgC70bcQ9OcssI02jsvwh//+XEkkN 8fyFgf0Uo6A3053s3/ylLNHANmhMjrlp1Zt4s+Nb3tmjS59fu5ysjBYUYdlho6Ih9Ufi 7w/0FBiLFD4/vYjCv4wxBc0CUfXOVydM2zNF/hMhmeFXoS1y2t2POMpSefAUE9Vlw0K/ 35sXUJtcaMfmvjiJ3km8J6LqvU/ERiY5LDBOIQ0eXR1l2i0qMF4QeI3iaUlUBwFkQtE9 MsDg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=christian.storm@siemens.com Received: from thoth.sbs.de (thoth.sbs.de. [192.35.17.2]) by gmr-mx.google.com with ESMTPS id i6si510868eda.1.2017.11.03.05.31.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Nov 2017 05:31:38 -0700 (PDT) Received-SPF: pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.2 as permitted sender) client-ip=192.35.17.2; Received: from mail2.siemens.de (mail2.siemens.de [139.25.208.11]) by thoth.sbs.de (8.15.2/8.15.2) with ESMTPS id vA3CVccx023702 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 3 Nov 2017 13:31:38 +0100 Received: from MD1KR9XC.ww002.siemens.net ([139.25.69.251]) by mail2.siemens.de (8.15.2/8.15.2) with ESMTP id vA3CVcFr030106; Fri, 3 Nov 2017 13:31:38 +0100 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm Subject: [swupdate] [PATCH 08/11] Lua: introduce image:read() method Date: Fri, 3 Nov 2017 13:30:06 +0100 Message-Id: <20171103123009.18705-8-christian.storm@siemens.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171103123009.18705-1-christian.storm@siemens.com> References: <20171103123009.18705-1-christian.storm@siemens.com> X-Original-Sender: christian.storm@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=christian.storm@siemens.com 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: , For C handlers, there's core/cpio_util.c's copyfile() as a general method to extract data from the input stream and copy it to somewhere. image:read() is the analogous function exposed to Lua that reads from the input stream and calls the callback Lua function for every chunk read, passing this chunk as parameter. Signed-off-by: Christian Storm --- corelib/lua_compat.c | 39 ++++++++++++++++++++++++++ corelib/lua_interface.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ include/lua_util.h | 21 ++++++++++++++ 3 files changed, 133 insertions(+) diff --git a/corelib/lua_compat.c b/corelib/lua_compat.c index 6204e8d..317f353 100644 --- a/corelib/lua_compat.c +++ b/corelib/lua_compat.c @@ -25,6 +25,45 @@ * https://github.com/keplerproject/lua-compat-5.2 */ #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM == 501 +char *luaL_prepbuffsize(luaL_Buffer_52 *B, size_t s) +{ + if (B->capacity - B->nelems < s) { /* needs to grow */ + char* newptr = NULL; + size_t newcap = B->capacity * 2; + if (newcap - B->nelems < s) + newcap = B->nelems + s; + if (newcap < B->capacity) /* overflow */ + luaL_error(B->L2, "buffer too large"); + newptr = lua_newuserdata(B->L2, newcap); + memcpy(newptr, B->ptr, B->nelems); + if (B->ptr != B->b.buffer) + lua_replace(B->L2, -2); /* remove old buffer */ + B->ptr = newptr; + B->capacity = newcap; + } + return B->ptr+B->nelems; +} + +void luaL_buffinit(lua_State *L, luaL_Buffer_52 *B) +{ + /* make it crash if used via pointer to a 5.1-style luaL_Buffer */ + B->b.p = NULL; + B->b.L = NULL; + B->b.lvl = 0; + /* reuse the buffer from the 5.1-style luaL_Buffer though! */ + B->ptr = B->b.buffer; + B->capacity = LUAL_BUFFERSIZE; + B->nelems = 0; + B->L2 = L; +} + +void luaL_pushresult(luaL_Buffer_52 *B) +{ + lua_pushlstring(B->L2, B->ptr, B->nelems); + if (B->ptr != B->b.buffer) + lua_replace(B->L2, -2); /* remove userdata buffer */ +} + void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup) { luaL_checkstack(L, nup+1, "too many upvalues"); diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index a551cde..7bb58ec 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -321,6 +321,75 @@ copyfile_exit: close(fdout); return 2; } + +static int istream_read_callback(void *out, const void *buf, unsigned int len) +{ + lua_State* L = (lua_State*)out; + if (len > LUAL_BUFFERSIZE) { + ERROR("I/O buffer size is larger than Lua's buffer size %d", LUAL_BUFFERSIZE); + return -1; + } + + luaL_checktype(L, 2, LUA_TFUNCTION); + lua_pushvalue(L, 2); + + luaL_Buffer lbuffer; + luaL_buffinit(L, &lbuffer); + char *buffer = luaL_prepbuffsize(&lbuffer, len); + memcpy(buffer, buf, len); + luaL_addsize(&lbuffer, len); + luaL_pushresult(&lbuffer); + if (lua_pcall(L, 1, 0, 0) != LUA_OK) { + ERROR("Lua error in callback: %s", lua_tostring(L, -1)); + lua_pop(L, 1); + return -1; + } + return 0; +} + +static int l_istream_read(lua_State* L) +{ + luaL_checktype(L, 1, LUA_TTABLE); + luaL_checktype(L, 2, LUA_TFUNCTION); + + struct img_type img = {}; + uint32_t checksum = 0; + + lua_pushvalue(L, 1); + table2image(L, &img); + lua_pop(L, 1); + + int ret = copyfile(img.fdin, + L, + img.size, + (unsigned long *)&img.offset, + img.seek, + 0, /* no skip */ + img.compressed, + &checksum, + img.sha256, + img.is_encrypted, + istream_read_callback); + + lua_pop(L, 1); + update_table(L, &img); + lua_pop(L, 1); + + if (ret < 0) { + lua_pushinteger(L, -1); + lua_pushstring(L, strerror(errno)); + return 2; + } + if ((img.checksum != 0) && (checksum != img.checksum)) { + lua_pushinteger(L, -1); + lua_pushfstring(L, "Checksums WRONG! Computed 0x%d, should be 0x%d\n", + checksum, img.checksum); + return 2; + } + lua_pushinteger(L, 0); + lua_pushnil(L); + return 2; +} #endif static void update_table(lua_State* L, struct img_type *img) @@ -354,6 +423,10 @@ static void update_table(lua_State* L, struct img_type *img) lua_pushstring(L, "copy2file"); lua_pushcfunction(L, &l_copy2file); lua_settable(L, -3); + + lua_pushstring(L, "read"); + lua_pushcfunction(L, &l_istream_read); + lua_settable(L, -3); #endif lua_getfield(L, -1, "_private"); diff --git a/include/lua_util.h b/include/lua_util.h index 03ef8d9..5be8c8d 100644 --- a/include/lua_util.h +++ b/include/lua_util.h @@ -50,6 +50,27 @@ void luaL_requiref(lua_State *L, char const* modname, lua_CFunction openf, int g typedef struct luaL_Stream { FILE *f; } luaL_Stream; + +typedef struct luaL_Buffer_52 { + luaL_Buffer b; /* make incorrect code crash! */ + char *ptr; + size_t nelems; + size_t capacity; + lua_State *L2; +} luaL_Buffer_52; +#define luaL_Buffer luaL_Buffer_52 + +#define luaL_prepbuffsize luaL_prepbuffsize_52 +char *luaL_prepbuffsize(luaL_Buffer_52 *B, size_t s); + +#define luaL_buffinit luaL_buffinit_52 +void luaL_buffinit(lua_State *L, luaL_Buffer_52 *B); + +#undef luaL_addsize +#define luaL_addsize(B, s) ((B)->nelems += (s)) + +#define luaL_pushresult luaL_pushresult_52 +void luaL_pushresult(luaL_Buffer_52 *B); #endif #else From patchwork Fri Nov 3 12:30:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 833836 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c09::237; helo=mail-wm0-x237.google.com; envelope-from=swupdate+bncbdd6bwv65qpbbk6d6hhqkgqetjokzyy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="JmQSLqXS"; dkim-atps=neutral Received: from mail-wm0-x237.google.com (mail-wm0-x237.google.com [IPv6:2a00:1450:400c:c09::237]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yT1Xt4HrRz9sPk for ; Fri, 3 Nov 2017 23:31:42 +1100 (AEDT) Received: by mail-wm0-x237.google.com with SMTP id 198sf254261wmg.6 for ; Fri, 03 Nov 2017 05:31:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1509712299; cv=pass; d=google.com; s=arc-20160816; b=peatRYhjvkzE8zdGpBqsYPcQf1i1MG4czTEnJEkUCPSb8jY7Lz+GWiyzQCm4BIlTsD H+FR3tVBlrfsrhTyJWjFYmAmcXMV2wD7xuNZf61N6WljpHVYwZfQ/Jwd+BCDneCIzDak sAfT4Aht68tW9/zmendtSK18A0mF1KS0dWscxJ6+3MYVQwn+FdGqSWkLat1GA3BX9PVw MJ8y9SO4WOyx1BnA5nRzBP/cTz2srkFuONIdvnkTO72affyc59WEOuaioDkGw039d/SI GK/7YZO4qD+2zbv8jAUE700ZRAOv+TjnjeRMejc/Tf+Z0goiIhwdNcWdfmWyrH9/3CtW nI1g== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=htkyRIvmMNNvPIzNkrN6reP/35e5DlZIZ2h+X6+kbyk=; b=KAD33Lx+hXf5YnjjdjMTiwj+pVJ8OX1iJRN1aAKPDqj4RvOjTF5oXRQOiAk2SfJE9R E/PwYv9ykZUeHPUUNw/f6lBthUCl4qBnzK0KBkAvZHOvteuWSC7bHJZW2LcZU/A2pc0J fedZrcruBTJ8wUZ5iWnaLMgwyrW6m21TXSppGYa3IMOe/jdq1CaPzgmiBBiFSlrHc2YW B2kJnytaSVOmdxqFtSMehlov5kx8sJPyiQ/7BsPpd1ivcj6LfjBZqwl3gf04l98KspNp MEo0k4kRY6fOE09v6nUOY0cVKCuChG8AvVsVz1PmJtvH+4hL/XUC6/FTzqUaZXGigF4l gaWg== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=christian.storm@siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=htkyRIvmMNNvPIzNkrN6reP/35e5DlZIZ2h+X6+kbyk=; b=JmQSLqXSVx+fMS4pSqkzENxfu3hNEtNxv4eDXyGFDI0GAsAvj9rLNQF3FlO5+IC92p 5fW486eqp9x3j6gP+nHlj8nJvtbUh90cCrCctSoLC7svmFlpRaH9REryagYvv8T4wXSb ILZ1qtId6euCud2ko8nXtv8+DN0cpSCIKOMebgp4FawrOIthXX8CwDJkQJojzCLY4I7F bBbY6t6w31xQ/ktB0G6KlRnIfygN1U/oKbjnxIK0CwfAyVOZ09ah8CS+mq+Btzeo1rDE 3KbpFXBSwLOuTOhGV6RhmZUerN3Z4zQM1cJKbNgNmQN9FyGYJA0fVxDhb5WVT5zFWlWL bCyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=htkyRIvmMNNvPIzNkrN6reP/35e5DlZIZ2h+X6+kbyk=; b=UFCZhNsJ3tjTF0ypYAMzWB29IhRzRSPBsFkTJ1apy3uboRTdmjYIrbQ2dolsFik+TZ Ua4sBiVQEZb09zN6D3iLefkfeWQv3dSsVba2sRTZHeqbZbjwe9MuSdkr0VIKjoO0ArGv 5XCzuPwDB+JqNAellQkMu7+VvRXqoaW2FmmE97lFumik/bLewy6H5WAfOcX+JfseKJaY QhgdJPVjU33ytII33bOMSEb5IavjtUKl/mFevT4zxiutsg+Fxir98wFBvrohb5yZ7ang DcWDboYTqBaVaOuJK+Xoyx/Z3z5WFP+8riINPIfrYXtiPVfyVXxvkxneD3gJMI5Ss8Vi JdsQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJaThX5oebTfy9+cbZPAg4cDIOt/BH0bzwT60CbHkMJzzs+tZqOaucuQ MhOymXtoIpNFHpo0QD+coro= X-Google-Smtp-Source: ABhQp+TG67h6VpKytjWH+TilwicoCiszEg4z8ZHYQd3rQviBqh2TwVb4CXWIry66Wucrlc5QgPLKaQ== X-Received: by 10.28.237.3 with SMTP id l3mr7559wmh.2.1509712299639; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.80.170.121 with SMTP id p54ls2861321edc.7.gmail; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) X-Received: by 10.80.163.214 with SMTP id t22mr2119231edb.12.1509712299131; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509712299; cv=none; d=google.com; s=arc-20160816; b=ND5iD03+TP++hHLrcRmz44wLCMg17E8rL1GRfvkRpFRUOTVIKsjtwK5D8UN2yNuZBS ollQzSDHr1wbCH5VgyQ/jOdVywAmZ/44qPg58V0BvatFP/Tx2aLyticinVf5szFF7c/+ +WlETLHAEdOeMdeuHWOY51ybgPFH1A8z4/A7hEWtEGM/VbBb+AmFAjfHOE2I6bQz6wAG 7hE2fju7WagS6sNR68Dke28MjsB98O4zVRJ5nYwxoswEhPZwz4ek3FGeRzgEB4spWeJ8 14wdUElodfA8eexKSnVTGd2nYTmU0glJZD77Q6bK4sL3SaC0Dvu60ZgP2cT6tv+DT8y9 Iy3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=OKgnhzYyjBkks2OvSjrRMPJjb8QiE21+KNT2YaNHN6k=; b=oU9fF+ZPOzErMT3pzNovDv0guQzDp23nJpZqmmsFC/XOIAgFKtP8NU8z2J3fUjrJVc C9ogI8A8m/HO5PYkyFuhZZtaMR5eV+52u3h0ZPrBK5sXnB0ymH0wiYIpo+TKjO7cOiPl 38Vn1W/9SuFS0vwLZSHLzWwcYavSFmiY2gdj/pm7iU0hONNvPr1KXC6SdSIiKR0qTLqA 92rXosAQtwQHtINnvLUo/p6OpG9WOec1IsMfmYDteTgSmmRRSu0CtKcZWqw1BS0+7yRQ GypxsdZU/T5DGqtTxlqPlxPNEKC62RGieg7GHDLEdAolTw2DE723nK0AgyGGn6kM9W1F wnoA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=christian.storm@siemens.com Received: from thoth.sbs.de (thoth.sbs.de. [192.35.17.2]) by gmr-mx.google.com with ESMTPS id i6si510869eda.1.2017.11.03.05.31.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Nov 2017 05:31:39 -0700 (PDT) Received-SPF: pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.2 as permitted sender) client-ip=192.35.17.2; Received: from mail2.siemens.de (mail2.siemens.de [139.25.208.11]) by thoth.sbs.de (8.15.2/8.15.2) with ESMTPS id vA3CVcZS023713 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 3 Nov 2017 13:31:38 +0100 Received: from MD1KR9XC.ww002.siemens.net ([139.25.69.251]) by mail2.siemens.de (8.15.2/8.15.2) with ESMTP id vA3CVcFs030106; Fri, 3 Nov 2017 13:31:38 +0100 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm Subject: [swupdate] [PATCH 09/11] Lua: distinguish handler and embedded script Lua VMs Date: Fri, 3 Nov 2017 13:30:07 +0100 Message-Id: <20171103123009.18705-9-christian.storm@siemens.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171103123009.18705-1-christian.storm@siemens.com> References: <20171103123009.18705-1-christian.storm@siemens.com> X-Original-Sender: christian.storm@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=christian.storm@siemens.com 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: , The Lua VM being created/called from the parser for embedded scripts needs not to have registered functions and attributes that are of interest to handler Lua VMs only. Hence, do register and set handler-specific functions and attributes only if the Lua VM is used as handler. Signed-off-by: Christian Storm --- corelib/lua_interface.c | 130 ++++++++++++++++++++++++++++++------------------ 1 file changed, 82 insertions(+), 48 deletions(-) diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index 7bb58ec..951ec80 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -30,6 +30,9 @@ #include "util.h" #include "handler.h" +#define LUA_TYPE_PEMBSCR 1 +#define LUA_TYPE_HANDLER 2 + #if defined(CONFIG_EMBEDDED_LUA_HANDLER) extern const char EMBEDDED_LUA_SRC[]; #endif @@ -60,6 +63,16 @@ static void image2table(lua_State* L, struct img_type *img); static void table2image(lua_State* L, struct img_type *img); static void update_table(lua_State* L, struct img_type *img); +#ifdef CONFIG_HANDLER_IN_LUA +static bool is_type(lua_State *L, uintptr_t type) +{ + lua_getglobal(L, "SWUPDATE_LUA_TYPE"); + bool ret = lua_touserdata(L, -1) == (void*)type ? true : false; + lua_pop(L, 1); + return ret; +} +#endif + void LUAstackDump(lua_State *L) { int top = lua_gettop(L); @@ -420,13 +433,15 @@ static void update_table(lua_State* L, struct img_type *img) LUA_PUSH_IMG_NUMBER(img, "checksum", checksum); #ifdef CONFIG_HANDLER_IN_LUA - lua_pushstring(L, "copy2file"); - lua_pushcfunction(L, &l_copy2file); - lua_settable(L, -3); - - lua_pushstring(L, "read"); - lua_pushcfunction(L, &l_istream_read); - lua_settable(L, -3); + if (is_type(L, LUA_TYPE_HANDLER)) { + lua_pushstring(L, "copy2file"); + lua_pushcfunction(L, &l_copy2file); + lua_settable(L, -3); + + lua_pushstring(L, "read"); + lua_pushcfunction(L, &l_istream_read); + lua_settable(L, -3); + } #endif lua_getfield(L, -1, "_private"); @@ -479,20 +494,22 @@ static void image2table(lua_State* L, struct img_type *img) update_table(L, img); #ifdef CONFIG_HANDLER_IN_LUA - lua_getfield(L, -1, "_private"); - lua_pushstring(L, "istream"); - luaL_Stream *lstream = (luaL_Stream *)lua_newuserdata(L, sizeof(luaL_Stream)); - luaL_getmetatable(L, LUA_FILEHANDLE); - lua_setmetatable(L, -2); + if (is_type(L, LUA_TYPE_HANDLER)) { + lua_getfield(L, -1, "_private"); + lua_pushstring(L, "istream"); + luaL_Stream *lstream = (luaL_Stream *)lua_newuserdata(L, sizeof(luaL_Stream)); + luaL_getmetatable(L, LUA_FILEHANDLE); + lua_setmetatable(L, -2); #if LUA_VERSION_NUM > 501 - lstream->closef = l_istream_fclose; + lstream->closef = l_istream_fclose; #endif - lstream->f = fdopen(img->fdin, "r"); - if (lstream->f == NULL) { - WARN("Cannot fdopen file descriptor %d: %s", img->fdin, strerror(errno)); + lstream->f = fdopen(img->fdin, "r"); + if (lstream->f == NULL) { + WARN("Cannot fdopen file descriptor %d: %s", img->fdin, strerror(errno)); + } + lua_settable(L, -3); + lua_pop(L, 1); } - lua_settable(L, -3); - lua_pop(L, 1); #endif } } @@ -520,13 +537,15 @@ static void table2image(lua_State* L, struct img_type *img) { lua_getfield(L, -1, "offset"); img->offset = (off_t)luaL_checknumber(L, -1); #ifdef CONFIG_HANDLER_IN_LUA - lua_pop(L, 1); - lua_getfield(L, -1, "istream"); - luaL_Stream *lstream = ((luaL_Stream *)luaL_checkudata(L, -1, LUA_FILEHANDLE)); - if (lstream->f == NULL) { - img->fdin = -1; - } else { - img->fdin = fileno(lstream->f); + if (is_type(L, LUA_TYPE_HANDLER)) { + lua_pop(L, 1); + lua_getfield(L, -1, "istream"); + luaL_Stream *lstream = ((luaL_Stream *)luaL_checkudata(L, -1, LUA_FILEHANDLE)); + if (lstream->f == NULL) { + img->fdin = -1; + } else { + img->fdin = fileno(lstream->f); + } } #endif lua_pop(L,2); @@ -596,11 +615,6 @@ static int l_get_tmpdir(lua_State *L) * @brief array with the function which are exported to Lua */ static const luaL_Reg l_swupdate[] = { -#ifdef CONFIG_HANDLER_IN_LUA - { "register_handler", l_register_handler }, - { "call_handler", l_call_handler }, - { "tmpdir", l_get_tmpdir }, -#endif { "notify", l_notify }, { "error", l_error }, { "trace", l_trace }, @@ -608,6 +622,15 @@ static const luaL_Reg l_swupdate[] = { { NULL, NULL } }; +#ifdef CONFIG_HANDLER_IN_LUA +static const luaL_Reg l_swupdate_handler[] = { + { "register_handler", l_register_handler }, + { "call_handler", l_call_handler }, + { "tmpdir", l_get_tmpdir }, + { NULL, NULL } +}; +#endif + static void lua_push_enum(lua_State *L, const char *name, int value) { lua_pushstring(L, name); @@ -621,7 +644,8 @@ static void lua_push_enum(lua_State *L, const char *name, int value) * @param [in] the Lua Stack * @return 1 (nr. of results on stack, the 'swupdate' module table) */ -static int luaopen_swupdate(lua_State *L) { +static int luaopen_swupdate(lua_State *L) +{ luaL_newlib (L, l_swupdate); /* export the recovery status enum */ @@ -638,25 +662,30 @@ static int luaopen_swupdate(lua_State *L) { lua_settable(L, -3); #ifdef CONFIG_HANDLER_IN_LUA - /* export the handler mask enum */ - lua_pushstring(L, "HANDLER_MASK"); - lua_newtable (L); - lua_push_enum(L, "IMAGE_HANDLER", IMAGE_HANDLER); - lua_push_enum(L, "FILE_HANDLER", FILE_HANDLER); - lua_push_enum(L, "SCRIPT_HANDLER", SCRIPT_HANDLER); - lua_push_enum(L, "BOOTLOADER_HANDLER", BOOTLOADER_HANDLER); - lua_push_enum(L, "PARTITION_HANDLER", PARTITION_HANDLER); - lua_push_enum(L, "ANY_HANDLER", ANY_HANDLER); - lua_settable(L, -3); + if (is_type(L, LUA_TYPE_HANDLER)) { + /* register handler-specific functions to swupdate module table. */ + luaL_setfuncs(L, l_swupdate_handler, 0); - lua_pushstring(L, "handler"); - lua_newtable (L); - struct installer_handler *hnd; - while ((hnd = get_next_handler()) != NULL) { - lua_pushinteger(L, 1); - lua_setfield(L, -2, hnd->desc); + /* export the handler mask enum */ + lua_pushstring(L, "HANDLER_MASK"); + lua_newtable (L); + lua_push_enum(L, "IMAGE_HANDLER", IMAGE_HANDLER); + lua_push_enum(L, "FILE_HANDLER", FILE_HANDLER); + lua_push_enum(L, "SCRIPT_HANDLER", SCRIPT_HANDLER); + lua_push_enum(L, "BOOTLOADER_HANDLER", BOOTLOADER_HANDLER); + lua_push_enum(L, "PARTITION_HANDLER", PARTITION_HANDLER); + lua_push_enum(L, "ANY_HANDLER", ANY_HANDLER); + lua_settable(L, -3); + + lua_pushstring(L, "handler"); + lua_newtable (L); + struct installer_handler *hnd; + while ((hnd = get_next_handler()) != NULL) { + lua_pushinteger(L, 1); + lua_setfield(L, -2, hnd->desc); + } + lua_settable(L, -3); } - lua_settable(L, -3); #endif return 1; @@ -799,6 +828,9 @@ int lua_handlers_init(void) gL = luaL_newstate(); if (gL) { + /* prime gL as LUA_TYPE_HANDLER */ + lua_pushlightuserdata(gL, (void*)LUA_TYPE_HANDLER); + lua_setglobal(gL, "SWUPDATE_LUA_TYPE"); /* load standard libraries */ luaL_openlibs(gL); luaL_requiref( gL, "swupdate", luaopen_swupdate, 1 ); @@ -840,6 +872,8 @@ lua_State *lua_parser_init(const char *buf) if (!L) return NULL; + lua_pushlightuserdata(L, (void*)LUA_TYPE_PEMBSCR); + lua_setglobal(L, "SWUPDATE_LUA_TYPE"); /* prime L as LUA_TYPE_PEMBSCR */ luaL_openlibs(L); /* opens the standard libraries */ luaL_requiref(L, "swupdate", luaopen_swupdate, 1 ); lua_pop(L, 1); /* remove unused copy left on stack */ From patchwork Fri Nov 3 12:30:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 833829 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c09::23d; helo=mail-wm0-x23d.google.com; envelope-from=swupdate+bncbdd6bwv65qpbbk6d6hhqkgqetjokzyy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="M8skMXMr"; dkim-atps=neutral Received: from mail-wm0-x23d.google.com (mail-wm0-x23d.google.com [IPv6:2a00:1450:400c:c09::23d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yT1Xt1qdKz9s83 for ; Fri, 3 Nov 2017 23:31:41 +1100 (AEDT) Received: by mail-wm0-x23d.google.com with SMTP id y83sf250202wmc.8 for ; Fri, 03 Nov 2017 05:31:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1509712299; cv=pass; d=google.com; s=arc-20160816; b=MG5FMUW40FQtdhPzwXjsTDHOQQAzc1v+X6WlylP/Rbz/NrI4Y+ylGwGe9S4+roWBFv UQBRNGx3d/yl0YpXF0LNdn9iyRk+j9DVY4o6zpjQW2EDhG0FFE1wz1o0deKO0in2m6Km FzamOoihxMTdRTDCrXlPtYIGJTUHbS+ypqROcF9JaB69TZcR7xguAR5RYdiUVv9jQmmp gGuSFnHaudPQudr9ONrsW34Nt9ykxyHgWEPfs60YduuqCHKg5G8bCO32YYw8uzrk+pUM RxwC/2Ho9e+AjkHkFBnjdAS0Fh8YvJdLfH2Dmw88s1PoxIZUFI0Nv0qV2OeMDCmtTD4w 66cw== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=iuXEVyZTRKYg0Wy9ElSE8KFI+ZHXG5Nt5PM5UdodqUQ=; b=kfQ6/Li4rUgMZuFzTLPgkVIn556Rbr01NkO5V/zAeGpviN7OXR023arjy0nUNSnP1I ewvh/qoE75w9IsMnuNdY5wIj76iztPB9lh5FuPZseKsU39M2560O8BT27k+lqpA+GI+W vNbprrau6/itn/56jQ0A3NUICgkT3uVMGkG3FZzS/wqY4boP21d0bycrk5bmDjHfA5RY AEJMuUg4gpHD4m0WGXXKK4jkbYqJJYipncxltNF5crBqxx3UUeIE7Wys/GgvafBynElZ oC6j8Ia7uHMzRLQnnRN7fNrobkz5flSPQ0xlmaIWLXyKGLeQf/8l2GChr8rT/CMjfgN5 eufQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=christian.storm@siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=iuXEVyZTRKYg0Wy9ElSE8KFI+ZHXG5Nt5PM5UdodqUQ=; b=M8skMXMrYOl7hw3lOn3RUAzSBxfte6QVwq7ouk8kqX0FKKM6BDXAHft8Wb/Ncuo7Lo VgFKtJW0AsRXSlYRRHV3PGo4cgZkuoHpsyXMQcTqttnwWiWwzho9YjNAvqhMx0pDH61c cHwlbKGZwCAi3O4YGKxeMDt035Sa3u+aeFhU/iSxxzo/WsPcUNENPmmsdVA8RT0h7SyY lB5UlxoRkR3Oz+lB8qD45Jax++TuI716FDREozvJMuvXGkUbdoR/1u1KmwtF0hcQ1hCl rxMccmAm5E808kw8184gUzrH5AsYRmFNTgmFTqeBRdL66CzYw83pcV3p05OqDsUthbsB LZtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=iuXEVyZTRKYg0Wy9ElSE8KFI+ZHXG5Nt5PM5UdodqUQ=; b=gs1pWDDikatnC1jDZ5RGDxfJFNoAbNhMK5HBHrQA6dO/jCKHNZPH0Z6wno6F+JXYPN bTnbAZKZR8ELH/aJpY7BGo2JRPN5gbvsENuUXlpNOnSXjEo1lKHyAyd5ZfXsPhHWN3xP kGzgIS3EzDfg5T7k/Qynk2WM4xRkT5PkqlsA0hLiAjMcMXvM0SRwrlV1SNq5sZ0AzpHw mjwQUOXMPC98ub5+1778ybpg/lntkN7ckWwV1arEqHgh98eVzBnaVDjk7p853cAmNTQJ fhC+ouJaqc0LRrtv3shKGnMvBL7HWY8As92lv5u8Z79QVSQ6WsKa1heO+2AkaXy3djON 09fA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AMCzsaVpSZSLztxOOfICa59ZMNKxyl0sJV6y30TLwEYiz1B97eRTSI1i TMOan65+PkJx7dj/NpLfQVI= X-Google-Smtp-Source: ABhQp+Sv3Ous6+ls2blG942HPWmOYQNwXVKrkDnltzWG59PAcQZeEW15Qj1w2BLGev891HHaeZpYjA== X-Received: by 10.28.92.212 with SMTP id q203mr68710wmb.1.1509712299584; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.28.87.82 with SMTP id l79ls940393wmb.4.gmail; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) X-Received: by 10.28.174.146 with SMTP id x140mr707423wme.14.1509712299179; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509712299; cv=none; d=google.com; s=arc-20160816; b=j5/+6atmVL/IgM2ZUuP2pk2TewDMY49vLljtkccUbxAekb1lo4IKFyeeNtDvFcgr8i dx9O4RUFFC9uc4KRcu1H0W2I74wi9Asdk/L43B5+sAkM5zJFxWq10DBBnLd1Z38Qh8NJ YwNYd9TH8CNaKogApfsYlPJsPkcF/deHbaCOfZ0Cd3ptrunV+6nNpzPReAIKjD6FEknG bNlo1WIpbVNuBkWNanIqiotpvVhv4KuFncpJ4/kX3tuhY9CwONVVTGK9fJoYM3m0aYgr 0XnjusrUcwtAJuN9Xt8MdK4z7KVS9Vj+gVATzSZTnJHPVQeHpp1FUtxqmPbF2YO/uUV+ S+iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=26ilL9PY7lWQdNa3qlISio2Tj3/9/O4Lkz3ebWGHQB4=; b=KR/A6SiqeujqNkshMyrvmwBb+JrIsmCnQGGtNOUGIER7ksNtqEBlK7H6Xkuz5O1mHz FwlDkHZS4QoaXFcSP3UpFD1FLjO0YzDzd4hOkGjk0YBaPtXj66+dIajaj9KvcWjxmngN QooGGApd/6TUTSi70NHaiBJh/nncdZrQ87JyD4hOonI/rV7Q7gaLJgwPCXWvnRzUXkzw u4vMV/e1ymxALw7akGIkScliF2WqzXdMNBHMs5eQU/IieEOA/NFPclVPWTFSeqcblK2C QRat7y+8jP2CpCn4SMbRBnMV+Pn6qq8YdMeOajSyLMYtqpzxjn+BL6TkIdzrNhOi6esW TBJA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=christian.storm@siemens.com Received: from goliath.siemens.de (goliath.siemens.de. [192.35.17.28]) by gmr-mx.google.com with ESMTPS id i76si179686wmd.0.2017.11.03.05.31.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Nov 2017 05:31:39 -0700 (PDT) Received-SPF: pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.28 as permitted sender) client-ip=192.35.17.28; Received: from mail2.siemens.de (mail2.siemens.de [139.25.208.11]) by goliath.siemens.de (8.15.2/8.15.2) with ESMTPS id vA3CVcV6015193 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 3 Nov 2017 13:31:38 +0100 Received: from MD1KR9XC.ww002.siemens.net ([139.25.69.251]) by mail2.siemens.de (8.15.2/8.15.2) with ESMTP id vA3CVcFt030106; Fri, 3 Nov 2017 13:31:38 +0100 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm Subject: [swupdate] [PATCH 10/11] Lua: update example Lua handler Date: Fri, 3 Nov 2017 13:30:08 +0100 Message-Id: <20171103123009.18705-10-christian.storm@siemens.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171103123009.18705-1-christian.storm@siemens.com> References: <20171103123009.18705-1-christian.storm@siemens.com> X-Original-Sender: christian.storm@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=christian.storm@siemens.com 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: , Update the example Lua handler to showcase the new Lua handlers' features. Signed-off-by: Christian Storm --- handlers/lua/fpga.lua | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/handlers/lua/fpga.lua b/handlers/lua/fpga.lua index f5a1e55..164b3f4 100644 --- a/handlers/lua/fpga.lua +++ b/handlers/lua/fpga.lua @@ -1,8 +1,8 @@ require ("swupdate") fpga_handler = function(image) - print("Install FPGA Software ") - swupdate.notify(swupdate.RECOVERY_STATUS.IDLE,0,"register lua handle") + print("Install FPGA Software ") + swupdate.notify(swupdate.RECOVERY_STATUS.IDLE, 0, "register Lua handler") print ("hello world!") print ("RECOVERY_STATUS.IDLE: ".. swupdate.RECOVERY_STATUS.IDLE) print ("RECOVERY_STATUS.START: ".. swupdate.RECOVERY_STATUS.START) @@ -10,13 +10,17 @@ fpga_handler = function(image) print ("RECOVERY_STATUS.SUCCESS: ".. swupdate.RECOVERY_STATUS.SUCCESS) print ("RECOVERY_STATUS.FAILURE: ".. swupdate.RECOVERY_STATUS.FAILURE) + for k,l in pairs(image) do + print("image[" .. tostring(k) .. "] = " .. tostring(l)) + swupdate.notify(swupdate.RECOVERY_STATUS.RUN, 0, "image[" .. tostring(k) .. "] = " .. tostring(l)) + end - for k,l in pairs(image) do - print("image[" .. tostring(k) .. "] = " .. tostring(l) ) - swupdate.notify(swupdate.RECOVERY_STATUS.RUN,0,"image[" .. tostring(k) .. "] = " .. tostring(l)) - end - - return 0 + err, msg = image:read(function(data) print(data) end) + if err ~= 0 then + swupdate.error(string.format("Error reading image: %s", msg)) + return 1 + end + return 0 end -swupdate.register_handler("fpga",fpga_handler) +swupdate.register_handler("fpga", fpga_handler, swupdate.HANDLER_MASK.IMAGE_HANDLER) From patchwork Fri Nov 3 12:30:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 833837 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c0c::238; helo=mail-wr0-x238.google.com; envelope-from=swupdate+bncbdd6bwv65qpbbk6d6hhqkgqetjokzyy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="rEaDyXJl"; dkim-atps=neutral Received: from mail-wr0-x238.google.com (mail-wr0-x238.google.com [IPv6:2a00:1450:400c:c0c::238]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yT1Xt4MY3z9sPs for ; Fri, 3 Nov 2017 23:31:42 +1100 (AEDT) Received: by mail-wr0-x238.google.com with SMTP id f27sf1523703wra.9 for ; Fri, 03 Nov 2017 05:31:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1509712299; cv=pass; d=google.com; s=arc-20160816; b=a1/Kq55ooulxquGEDdMpkGM3YUWoPU882/BCEvTJKz6TBboxocmvpFA1xRqjlkXmBu oUWdXpfuKIcJd7GAdRDI9bN35R5zhuj9qkfFAEaELs9rqjz5+if6eE2pkJf7yxVMNkZi oEAqlxU1WSGkuwt3vvMNKHKKLZxT4mNRkJdkmzF0hU1Xgxcyj0W5XAJRR7aZpB4RsbcV U+A46UwrIFR2q9Bj4hyeFGvF3gd4/hnFcKza84Cp+lDjVEQQFdB0HQ009EaIU7oGOlxz B8xWIxNYMeDG93n+IEnkbbNvcV9hS3tgUTeC+LBUSif4rnhryRU+zqRf7muC7vLb/hO5 mIaw== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=DxcVwy/BMDmfaDMHiSKt0/kKSNg1LlR6szcwkMKc14o=; b=FOcQRfjE5FJpytzVF3aIHWLYYDrS6Un7CuZhE8eprhswrNG+T+rEslqPE9yhD3BDab YymgwDnrz/U70RPZU47jcmub4E+s49radsRxDsCrzfR3hmteZ3VUlQZTY0QF+plRSo0P vBQa8Umv0UPlZpIgQWZI89RJdAiqwlSAOMGp6oNFRrWMkgy8gEPHOlxeLk/gaxoFBzqd bHsRRvL97SDA36yJWLXZqIe1psZPYtel00cYbtkhLlQxaNxuLxPcMLP1LghorpbIMCdO SKFJHGikDMsbOnyHVNRLRObyiiMb+S3RnprYTzGda4E7mJ92uBuceEdxu8QvXn/E9u7L ZWjA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=christian.storm@siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=DxcVwy/BMDmfaDMHiSKt0/kKSNg1LlR6szcwkMKc14o=; b=rEaDyXJl6vfuQdPaAe05hPBIiUaweAN3S+aurE+vUQa/leQyu8vqJunJof1lDkMgkK DR22ydkWrdJ6D1p9rJe4fvGHIVa6I8pNUjqt3MB4MEzhuDznP5FYwTap+/42LTER/1m7 SvfcMx7EKwSyDyj+Obj45di9nwlQw4Q7haDkG6Kg+hXIz5rpld71eBwzv7LcfTkqnbqI PObmZwIQbY8ZJeAUnbjLuO7FLDzMqAtk5M1WLdv85zWrxR8P4Pm6dh1ev4Bd+KR3rewf V6tP3f0BAqjTPBj8p64aDNWRSVZ96pnGDHvNqm8YkvOaTKwvgUDFvYBU1+aI/lI+uawd deBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=DxcVwy/BMDmfaDMHiSKt0/kKSNg1LlR6szcwkMKc14o=; b=GNDDaY3Z4kmv+IkI18p8ea2gq1DRw0wRc0FBS8zXhOHnN6SNfytESEYKfie10wxWnd IXcuN4INFM1RTV/mo2Ru7pkziIhnWrOEPJ4stbMf9MifvR283jSN+vQbyOkVDTnJBi6j t0p1KMKAHbmb4I8qpHAKGTksGEAxaOPrxnR2qqmQWnWbguAo20x/k+9Ny3M1ZFqWkWsS y4mRGLy3pAo+8bUFOT1aKxVqLu6KogiG2XsgWfLCf4qTtrTS1+1TrsXviAWLgBNvCGi6 ZGr8hjqRa8XQHLRZ/ImqG/b3Vkbo6efbyHokaBdfRsaUcZtP9+QHgVVAlX/riKyfGwsQ Ag/g== Sender: swupdate@googlegroups.com X-Gm-Message-State: AMCzsaUchSnrdBzFRboeG++jzUJ0kC0B/znXxZaOfVouxPybsdw4z2Ns g4cQiPrxNyBLqkNOgvxWyaE= X-Google-Smtp-Source: ABhQp+SiJEk1QR4IIsoHwUeao2jf25isKH/GT62LOyvgoWq+/MafujJ07eUsp0V+EyY/dRCzy2FV/Q== X-Received: by 10.28.136.149 with SMTP id k143mr70896wmd.3.1509712299722; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.80.244.25 with SMTP id r25ls2872718edm.2.gmail; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) X-Received: by 10.80.206.3 with SMTP id y3mr2134772edi.11.1509712299294; Fri, 03 Nov 2017 05:31:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509712299; cv=none; d=google.com; s=arc-20160816; b=0sCZNmh9N+WyO8DKGERd+FSzmnp+BormwfSQk9XtIBQ3B/5Ti9hEoReWG8shipGR+W EDlZl5NEXKDDRgc1e/whLRy03gXr5jSZanCngerrymYxUS/FOZmnTsXrwA6unVcwfdsT FFR0uEe221Wkzhg/MDI6c7gPb+W+BQZrskBVpMZN37j9nO83EFTHNxNZb0HSqk6cr0/N 7EAe5df8IRMS3Vi6+COea2Ho6vdQpblWKFpKFdy6dzQp2YLvOf+ZAslUio+Pdob7/Xx0 dojR6PZEhcqjR41d6ckeXJ+OQ+Jsm2VpPDTb2xQK+a2PigyFm0j2q01o1PLEBjzO1Zb2 UfJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Ul6+qk5CEmIqBYwT+Ml7q3N9HtaYxi4BNEYPJPveTTE=; b=i/rRgTEaGf7bAqJTEzAiv8ziVFl4OoSMDTs4WN+IdllcsEdOsJdQMwyDY5ZeLt3ZIT /MdzxT6KFaiSBSVAw+pkHqfWmJoYSeWAKAa7diMobH9zHa9qKQ5TFDh8AA00d4Iw5Wg6 isIvfYgnJgc4EdsK0rg60e5Y2lWNfTUwZV4g6aKbUiPwe91TpdKnvzrhNNAb8hjY2eq6 qpvSh0zf4ustSRcC0gVJPKmGV/9T/2A2aNT7HLf5jVnTWKIaA4P5xj05z2gU42SCq+uN Rtscr6qCygFhZcMvJVxEQcLgApIrVmGm/Hvp3z5QOThVfSliqcq2UFyRLeUqzeRR6p8C CkiA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=christian.storm@siemens.com Received: from thoth.sbs.de (thoth.sbs.de. [192.35.17.2]) by gmr-mx.google.com with ESMTPS id i6si510871eda.1.2017.11.03.05.31.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Nov 2017 05:31:39 -0700 (PDT) Received-SPF: pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.2 as permitted sender) client-ip=192.35.17.2; Received: from mail2.siemens.de (mail2.siemens.de [139.25.208.11]) by thoth.sbs.de (8.15.2/8.15.2) with ESMTPS id vA3CVctY023726 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 3 Nov 2017 13:31:38 +0100 Received: from MD1KR9XC.ww002.siemens.net ([139.25.69.251]) by mail2.siemens.de (8.15.2/8.15.2) with ESMTP id vA3CVcFu030106; Fri, 3 Nov 2017 13:31:38 +0100 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm Subject: [swupdate] [PATCH 11/11] Lua: document Lua handlers Date: Fri, 3 Nov 2017 13:30:09 +0100 Message-Id: <20171103123009.18705-11-christian.storm@siemens.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171103123009.18705-1-christian.storm@siemens.com> References: <20171103123009.18705-1-christian.storm@siemens.com> X-Original-Sender: christian.storm@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=christian.storm@siemens.com 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: , Document how to extend SWUpdate with Lua handlers and elaborate on their new features. Signed-off-by: Christian Storm --- doc/source/handlers.rst | 144 +++++++++++++++++++++++++++++++++++++++--- doc/source/sw-description.rst | 2 + 2 files changed, 136 insertions(+), 10 deletions(-) diff --git a/doc/source/handlers.rst b/doc/source/handlers.rst index 51e087f..5536e0f 100644 --- a/doc/source/handlers.rst +++ b/doc/source/handlers.rst @@ -123,16 +123,140 @@ and create the volumes. This can be easy done with a preinstall script. Building with meta-SWUpdate, the original mtd-utils are available and can be called by a Lua script. -Extend SWUpdate with handlers in Lua ------------------------------------- - -In an experimental phase, it is possible to add handlers -that are not linked to SWUpdate but that are loaded by -the Lua interpreter. The handlers must be copied into the -root filesystem and are loaded only at the startup. -These handlers cannot be integrated into the image to be installed. -Even if this can be theoretical possible, arise a lot of -security questions, because it changes SWUpdate's behavior. +Lua Handlers +------------ + +In addition to the handlers written in C, it is possible to extend +SWUpdate with handlers written in Lua that get loaded at SWUpdate +startup. The Lua handler source code file may either be embedded +into the SWUpdate binary via the ``CONFIG_EMBEDDED_LUA_HANDLER`` +config option or has to be installed on the target system in Lua's +search path as ``swupdate_handlers.lua`` so that it can be loaded +by the embedded Lua interpreter at run-time. + +In analogy to C handlers, the prototype for a Lua handler is + +:: + + function lua_handler(image) + ... + end + +where ``image`` is a Lua table (with attributes according to +:ref:`sw-description's attribute reference `) +that describes a single artifact to be processed by the handler. + +Note that dashes in the attributes' names are replaced with +underscores for the Lua domain to make them idiomatic, e.g., +``installed-directly`` becomes ``installed_directly`` in the +Lua domain. + +To register a Lua handler, the ``swupdate`` module provides the +``swupdate.register_handler()`` method that takes the handler's +name, the Lua handler function to be registered under that name, +and, optionally, the types of artifacts for which the handler may +be called. If the latter is not given, the Lua handler is registered +for all types of artifacts. The following call registers the +above function ``lua_handler`` as *my_handler* which may be +called for images: + +:: + + swupdate.register_handler("my_handler", lua_handler, swupdate.HANDLER_MASK.IMAGE_HANDLER) + + +A Lua handler may call C handlers ("chaining") via the +``swupdate.call_handler()`` method. The callable and registered +C handlers are available (as keys) in the table +``swupdate.handler``. The following Lua code is an example of +a simple handler chain-calling the ``rawfile`` C handler: + +:: + + function lua_handler(image) + if not swupdate.handler["rawfile"] then + swupdate.error("rawfile handler not available") + return 1 + end + image.path = "/tmp/destination.path" + local err, msg = swupdate.call_handler("rawfile", image) + if err ~= 0 then + swupdate.error(string.format("Error chaining handlers: %s", msg)) + return 1 + end + return 0 + end + +Note that when chaining handlers and calling a C handler for +a different type of artifact than the Lua handler is registered +for, the ``image`` table's values must satisfy the called +C handler's expectations: Consider the above Lua handler being +registered for "images" (``swupdate.HANDLER_MASK.IMAGE_HANDLER``) +via the ``swupdate.register_handler()`` call shown above. As per the +:ref:`sw-description's attribute reference `, +the "images" artifact type doesn't have the ``path`` attribute +but the "file" artifact type does. So, for calling the ``rawfile`` +handler, ``image.path`` has to be set prior to chain-calling the +``rawfile`` handler, as done in the example above. Usually, however, +no such adaptation is necessary if the Lua handler is registered for +handling the type of artifact that ``image`` represents. + +In addition to calling C handlers, the ``image`` table passed as +parameter to a Lua handler has a ``image:copy2file()`` method that +implements the common use case of writing the input stream's data +to a file, which is passed as this method's argument. On success, +``image:copy2file()`` returns ``0`` or ``-1`` plus an error +message on failure. The following Lua code is an example of +a simple handler calling ``image:copy2file()``: + +:: + + function lua_handler(image) + local err, msg = image:copy2file("/tmp/destination.path") + if err ~= 0 then + swupdate.error(string.format("Error calling copy2file: %s", msg)) + return 1 + end + return 0 + end + +Beyond using ``image:copy2file()`` or chain-calling C handlers, +the ``image`` table passed as parameter to a Lua handler has +a ``image:read()`` method that reads from the input +stream and calls the Lua callback function ```` for +every chunk read, passing this chunk as parameter. On success, +``0`` is returned by ``image:read()``. On error, ``-1`` plus an +error message is returned. The following Lua code is an example +of a simple handler printing the artifact's content: + +:: + + function lua_handler(image) + err, msg = image:read(function(data) print(data) end) + if err ~= 0 then + swupdate.error(string.format("Error reading image: %s", msg)) + return 1 + end + return 0 + end + +Using the ``image:read()`` method, an artifact's contents may be +(post-)processed in and leveraging the power of Lua without relying +on preexisting C handlers for the purpose intended. + + +Just as C handlers, a Lua handler must consume the artifact +described in its ``image`` parameter so that SWUpdate can +continue with the next artifact in the stream after the Lua handler +returns. Chaining handlers, calling ``image:copy2file()``, or using +``image:read()`` satisfies this requirement. + + +Note that although the dynamic nature of Lua handlers would +technically allow to embed them into a to be processed ``.swu`` +image, this is not implemented as it carries some security +implications since the behavior of SWUpdate is changed +dynamically. Remote handlers --------------- diff --git a/doc/source/sw-description.rst b/doc/source/sw-description.rst index d8fd2f7..01b2e3e 100644 --- a/doc/source/sw-description.rst +++ b/doc/source/sw-description.rst @@ -789,6 +789,8 @@ Example: The example sets a version for the installed image. Generally, this is detected at runtime reading from the target. +.. _sw-description-attribute-reference: + Attribute reference -------------------