From patchwork Wed Feb 21 08:22:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1901897 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20230601 header.b=p+gMmw0D; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::13e; helo=mail-lf1-x13e.google.com; envelope-from=swupdate+bncbaabbq7f22xamgqe35sp7hi@googlegroups.com; receiver=patchwork.ozlabs.org) Received: from mail-lf1-x13e.google.com (mail-lf1-x13e.google.com [IPv6:2a00:1450:4864:20::13e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tfq5N0HpXz23l3 for ; Wed, 21 Feb 2024 19:22:31 +1100 (AEDT) Received: by mail-lf1-x13e.google.com with SMTP id 2adb3069b0e04-512b43132f4sf276074e87.0 for ; Wed, 21 Feb 2024 00:22:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708503748; cv=pass; d=google.com; s=arc-20160816; b=fNGDZQ03Hh28NjEAY7QixYKiGAooFda30uGzo5vYkXGoZYAcIdByfAxUVdvpmIdSSd h+qVvTosm2Y59oQV0XK3yGZx7vDZtWA+Q8VmKP7HaJltxzqYH37qDSS0jSFD5QJI0zaC 3bjV0lnJXK+0bKshmGjTGQPM0CLD4emvoGHpbXVkQ/azqTS/a1XBXGBkZm322E0ysS0y bUj5xhtV1wyB0G6SVddHGLiF6mtIyGhfNxlWItLv4bj+tzoUaHgOKztIRlVxPW9q9ruV IPEk/LVIWLgqmJH4NWRqQ+jEvY8WnBn2nam8EIhlDqnG0D6AjKpcHbravmD65chNtw8h f9Uw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:ui-outboundreport:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=JELIIk9py8YRPDnooMi4aEIW/8ydpXhk/HgkllUfYkM=; fh=bORm+4fD+KHtOwqzYRgr7W1ms/QwBSkBWb9OYZ6AsYE=; b=Y4UOWZWxJiyj7x1nqBBYlLsoaUIt/BHaWSnraBRHhQCpZsgalJrJIwC2vBJB6OHc+c rjeveusxePKRQ8x3pF6QCT4E4tCiwS6KHy2DDK78f8KTH3yEf/c06Sjqkm47Q4xluwgE 7wyuunPyZ19APhWORNtHFZJtIqUgnCKlSxiNFPG2GIGFCnxcSqNqwbCiC6xaWA5u7vH2 HDURvEWNz9i7xfIZTk5mNX/ht9NogVBfS/Iua2h7KdkXoiL0akzqnrs4nrwp5KWrOZCh cWbZ3ryx/wmzHjTWAIF0ftQWC76spFmRee8Tp8nHo/9q9nQNc8fYmHR8BCmLJAwwS2Bv XIKg==; darn=patchwork.ozlabs.org ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@swupdate.org header.s=s1-ionos header.b=ogMjpp6E; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.126.133 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1708503748; x=1709108548; darn=patchwork.ozlabs.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:ui-outboundreport:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:sender:from:to:cc :subject:date:message-id:reply-to; bh=JELIIk9py8YRPDnooMi4aEIW/8ydpXhk/HgkllUfYkM=; b=p+gMmw0DGnGszrBBjIJxTPADE0M4dOB6ahLv+6uB2A9rSWPQHPmifoVVZ3hxVZaA7K I+EfSO/xcGz80YqNa6FJCCMNydWyiM44dvkHh2LcoZYG5zfMWPHfWM5LUPUg7HUER6Pu p3uJ/DBtzu4kTuOyZHig1j+bhgC866bXEPrpeZRYQpTt5SdzOkTGXDX0543u0fHi9D/D +bsQ7ivDm9JGFsKxDpiCssrEQQHs7W516xPM7oGbqnw/hkt8o5ruWWAIIITJbv3PjwPr dOICQ2Hc7fExpHXmh87HYvxdY9ziNGbr/quI6pJJ0RW7V5KNuTR+yYQEUzzc9yTQF/dI 0tVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708503748; x=1709108548; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender :ui-outboundreport:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:x-beenthere:x-gm-message-state:sender:from :to:cc:subject:date:message-id:reply-to; bh=JELIIk9py8YRPDnooMi4aEIW/8ydpXhk/HgkllUfYkM=; b=OKG3mPnouhpqrppSGRxWFnUFmETPUTyyDzgokbeDNqgF6hRt6cF49gY4QsJzymptC6 hRkeADv2xHXN8OlJZSvjajhHjCCuNQkQGrKU2mz7Hr5mrHYbk0NEsr3dd/sZTSE9dS9B aweojQ/UeiQRIZh2dqkd5gByU6LWmu84AVsnjd4pXIQhJft0cKrp5v7msFNkKhGqG+pD ILwCw7M3w3LjNUvI/uxOBxCnGwQdyeS0j8aoIfby/gjqLk/xK8kKXhD27HIpJUOdi/Wm CXuA5Y84eUSQunsmx2h9+7jhpfgVEw0xpnAGviJ0so0lPehagi6FShjERPJytKrWsPyS 5yXg== Sender: swupdate@googlegroups.com X-Forwarded-Encrypted: i=2; AJvYcCXG8UpmkGl5MBwzZTT36K6DeW5lxVKcSnKPvELxm9SwcZnyhsZtSP5QefH7S3YmqE0qibWZ2MvmyJqbE7RpFXV/AMZrC4oHri2+xkQQdA== X-Gm-Message-State: AOJu0YywQZZC8By6Q5zxfoiLqP8eZMFEvKoT4nOP+VPGa4Y0V8yweDK2 cLOLJjN1pVT6gOTX6xj9MQvDjT+96JGXbdF+crIxIvNymUGRaTmE X-Google-Smtp-Source: AGHT+IFs4N5mvV4ikH8SWARmliekVwt1fi5jvwVo9/IwMeXN5V7G+roYPjxexIAZ5vDJUKGBj0Fh/g== X-Received: by 2002:a05:6512:714:b0:512:9e56:7fda with SMTP id b20-20020a056512071400b005129e567fdamr6386888lfs.3.1708503747571; Wed, 21 Feb 2024 00:22:27 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:6512:39ca:b0:512:d048:cb15 with SMTP id k10-20020a05651239ca00b00512d048cb15ls289663lfu.1.-pod-prod-09-eu; Wed, 21 Feb 2024 00:22:25 -0800 (PST) X-Received: by 2002:a2e:8290:0:b0:2d2:1fed:a679 with SMTP id y16-20020a2e8290000000b002d21feda679mr8258302ljg.7.1708503745574; Wed, 21 Feb 2024 00:22:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708503745; cv=none; d=google.com; s=arc-20160816; b=AUbfRSWNeVCtuEpJ2vN0wJeOKWoTsXHjMUTrVgzRY4ZH1J3QHo7nfD8oGWa1qkecrt 3+m26CA1VWBniW5eKf7BshgAmHWcY2hikHsWY18gsPiQ24MOHDggshzdp7PwveinXeD3 J12LdUV9VmYz0yLh8kl6k04PG4088+CkX/ZAR50zV/QMCwVqBBKVq4w/hYpH66BuNeOn hpkpiOxULVlEgVMo7W1vU/qNl+2NEe6tc6C4tjJkOa1Ut28cNWd8hVPtt5qbCfNY+b7M RUHsWIxy8wnRxt+7bGH/TcVjuTI7sAQDu9YFojJKvbljw0Ga17vIeTRhvIrJpQukDTsm CTSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=UsAdfwbrOq4kyjhaDAf5rK145I614uBkDEjeEyBNjts=; fh=TiEWcqMcKpHk5s7uErzpntoONrNfOXwKpI5P8bIlggk=; b=SYXIw5aKuHlVJKyxVRElLQABLwFsgZ6YWVEzcGv5tWHWhIJneM6OjAEtZK6yZZwUPP Xvec/Ht0Lss7dbL/7+k/6p4tM33BLOPehalpu+czJbUm51RezNhpwmHPcfsFRr5izSK9 dlqEYGiB60L5OH0pSZc6RirmWMkmquuKV9V3QaPAXAfyVODl8+tAs6xvLPSoY93xp8J3 lE6lq7TBZueWpiHKxmkutghDgOzaQViJ0xLHovmZnkyNMv0YPnFwUZsGNd8TafAdKV4W hh3CZrK0UMx6TO6mlRZQ2R0vEQnvVqUOdJa0hu+G3EBhAoOlGRj/ujMHPN2wmdh6KTVm vTnw==; dara=google.com ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@swupdate.org header.s=s1-ionos header.b=ogMjpp6E; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.126.133 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org Received: from mout.kundenserver.de (mout.kundenserver.de. [212.227.126.133]) by gmr-mx.google.com with ESMTPS id b24-20020a2e8958000000b002d230e90c7fsi405092ljk.5.2024.02.21.00.22.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 00:22:25 -0800 (PST) Received-SPF: pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.126.133 as permitted sender) client-ip=212.227.126.133; X-UI-Sender-Class: 55c96926-9e95-11ee-ae09-1f7a4046a0f6 Received: from paperino.fritz.box ([88.217.136.221]) by mrelayeu.kundenserver.de (mreue011 [213.165.67.97]) with ESMTPSA (Nemesis) id 1MDQRy-1rkvLi3NOI-00AYNA; Wed, 21 Feb 2024 09:22:24 +0100 From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 08/13] Introduce postfailure scripts Date: Wed, 21 Feb 2024 09:22:16 +0100 Message-Id: <20240221082221.11997-9-stefano.babic@swupdate.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240221082221.11997-1-stefano.babic@swupdate.org> References: <20240221082221.11997-1-stefano.babic@swupdate.org> MIME-Version: 1.0 X-Provags-ID: V03:K1:I8IqnRZV76MCWEf5dyH+T3SVem5wh8DLwYzdETjYqxZmpliTjZF YqWXVOdj/4zgi/9UhP2C6cp4ODWXkyySVM9SJLjyJd/pVzPPRlPVPV8x8AjhSaHnqOWy3HZ tLkeNLD2P0DMuWIt7h72pLP6ScHggXD1FEd2NKsNRx1LVx7OjsFk09r0tiH51JgxBv5Mn6a D3LqfmjTTencOJyxWXomQ== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:C+xm8TVMBfA=;SMTZpT6DQ5Luwjey0iCUIEeln58 WR2WEFXMhComfdZEiCPs0MvXNIs9oUfykS4wnXyZL+cKXM5GtpC1drNZm6gxqxFWvglAwVj/9 Sc/PSX3PNO+BqglSLpwnJNRRbNBwQm77cRvWvfydR3RnQor69zJwQkh9BOOY921XWRF/B+KCn iAeepnlGuTaPjUWgSRwnnG776sbJ5WZJ0R872T/ym9nC4mBXIjXff25tMMZ7tyTYbpZ6CBpX8 M2e9ETdF5/8UM/SJKmewBT59FYJMnwnVBjCQAj2uqMP15lOGrVOAI/fMehnnWc/1wWK+4dVxu SmpiICrIBDiV/MSeYtn8EEpJ97ywTO9UBcT+8vUYnPYLe/vpN+8YtOTeNlHe0ngHz/Z4nYjd1 0XA9r2n02Fu0kE3aCI+08idRMn53Afx09rkb6zs0huHYgnkqcXsSn9pbCBIGDZyFMOGlbSoAD rafos7gVu14XL5TcvXsogi57a+/k3VL8OPaRlvPq6O5RT8gJCYQVcYurRrTuUm/EuKNpWQGgl Iob9NTKrsSD7Tbt/p//YMWjdDa1ra/WxglW/R0C5+7Yfv3B/Rc/OfPKOt1pHyyalyPA6s7ud5 je2Jj3JDp4nEjWCjthg/QR1TGDmRjAl7HRZtoyUMMmQgABEXwtZ/nC39br4ab+zB4CjHJeWKJ gtpTR0Kw7pbqD8IP+oQzr2KCvhSLqpWWlyzpIykpmeW54uLWbw24YmuHgL8c1RCksHv/5wVfW FHge+Ks0p7KY62yo6QxUZj9wbvYWqj+kBac1mALau8fHErB7o+mr4o= X-Original-Sender: stefano.babic@swupdate.org X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@swupdate.org header.s=s1-ionos header.b=ogMjpp6E; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 212.227.126.133 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , These scripts run afet ran update fails. They can be used to restore the system to a previous state before the Update was initiated. All scripts will be executed, as it makes no sense to stop if one of them fails, because the update state is already FAILURE. Signed-off-by: Stefano Babic --- core/stream_interface.c | 13 +++++++++++++ doc/source/sw-description.rst | 20 +++++++++++++++++--- handlers/lua_scripthandler.c | 13 +++++++++++-- handlers/shell_scripthandler.c | 3 +++ 4 files changed, 44 insertions(+), 5 deletions(-) -- 2.34.1 diff --git a/core/stream_interface.c b/core/stream_interface.c index b9bce6d7..5ebaca68 100644 --- a/core/stream_interface.c +++ b/core/stream_interface.c @@ -674,6 +674,19 @@ void *network_initializer(void *data) update_transaction_state(software, STATE_FAILED); notify(FAILURE, RECOVERY_ERROR, ERRORLEVEL, "Installation failed !"); inst.last_install = FAILURE; + + /* + * Try to run all POSTFAILURE scripts, + * their result does not change the state that remains FAILURE + * Goal is to restore to the state before update was started + * if this is needed. This is a best case attempt, ERRORs + * are just logged. + */ + if (!software->parms.dry_run) { + if (run_prepost_scripts(&software->scripts, POSTFAILURE)) { + WARN("execute POST FAILURE scripts return error, ignoring.."); + } + } } else { /* * Clear the recovery variable to indicate to bootloader diff --git a/doc/source/sw-description.rst b/doc/source/sw-description.rst index b0363359..d4cb8971 100644 --- a/doc/source/sw-description.rst +++ b/doc/source/sw-description.rst @@ -759,7 +759,9 @@ with an error if the result is <> 0. They are copied into a temporary directory before execution and their name must be unique inside the same cpio archive. -If no type is given, SWUpdate default to "lua". +If no type is given, SWUpdate default to "lua". Please note that running a shell script +opens a set of different security issues, check also chapter "Best practise". + Lua ... @@ -790,12 +792,24 @@ called before installing the images. function postinst() + SWUpdate scans for all scripts and check for a postinst function. It is called after installing the images. +:: + + function postfailure() + +Only in case an update fails, SWUpdate scans for all scripts and check +for a postfailure function. This could be useful in case it is necessary +to restore a previous state, for example, in case the application was +stop, it should run again. + shellscript ........... +SWUpdate will run the binary shell "/bin/sh" to execute the script. + :: scripts: ( @@ -805,9 +819,9 @@ shellscript } ); -Shell scripts are called via system command. +Shell scripts are called by forking the process and running the shell as /bin/sh. SWUpdate scans for all scripts and calls them before and after installing -the images. SWUpdate passes 'preinst' or 'postinst' as first argument to +the images. SWUpdate passes 'preinst', 'postinst' or 'postfailure' as first argument to the script. If the data attribute is defined, its value is passed as the last argument(s) to the script. diff --git a/handlers/lua_scripthandler.c b/handlers/lua_scripthandler.c index 213099de..08479ef4 100644 --- a/handlers/lua_scripthandler.c +++ b/handlers/lua_scripthandler.c @@ -54,10 +54,19 @@ static int start_lua_script(struct img_type *img, void *data) switch (script_data->scriptfn) { case PREINSTALL: - fnname="preinst"; + fnname = dict_get_value(&img->properties, "preinstall"); + if (!fnname) + fnname="preinst"; break; case POSTINSTALL: - fnname="postinst"; + fnname = dict_get_value(&img->properties, "postinstall"); + if (!fnname) + fnname="postinst"; + break; + case POSTFAILURE: + fnname = dict_get_value(&img->properties, "postfailure"); + if (!fnname) + fnname="postfailure"; break; default: /* no error, simply no call */ diff --git a/handlers/shell_scripthandler.c b/handlers/shell_scripthandler.c index a85e8bb9..5602b98b 100644 --- a/handlers/shell_scripthandler.c +++ b/handlers/shell_scripthandler.c @@ -63,6 +63,9 @@ static int start_shell_script(struct img_type *img, void *data) case POSTINSTALL: fnname="postinst"; break; + case POSTFAILURE: + fnname="failure"; + break; default: /* no error, simply no call */ return 0;