From patchwork Sat May 13 19:56:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Schiffer X-Patchwork-Id: 762071 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wQHjB4zCQz9s9Y for ; Sun, 14 May 2017 05:58:54 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="mbcVJA3O"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=pv5kngEeN2UukhCEpZgiBpI5DWawyd9UVQhHju5UbyY=; b=mbcVJA3ONwY7I8McGdoPc8uoNM obL21tHMMkszhHm4iT79Qye4xDxEUZu6xrL8Ld+Dy1PZKniVdMyT4y+24DJSdUpbHOJwFaijPrSlX vUxoljkYEzn5tX3jH7RrRcvpEKSOPnPmrV8YZIzTE3OkAjOO2nchjUOTm/ICNVPbdQTU3RfaJT7D/ 8JIwdxPtWEI1UXKDzX5+mHv6mDTD3YA4R4QbUmOoMIg0cCjeJ+91aLFR/ivuCJ9v5ksbkYiOuSeLh +MQ3zQkg2lJE2GnXjazVpAM5mz2wayDb1hU1sRxCLWdEIsWS6iLLdTCP6VvvaNcWwMpspi9WkOybn 8ueI1vtQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d9dBi-0005iF-8d; Sat, 13 May 2017 19:58:50 +0000 Received: from chaos.universe-factory.net ([2a02:2918:505:100::22]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d9dAd-0003rg-F1 for lede-dev@lists.infradead.org; Sat, 13 May 2017 19:57:52 +0000 Received: from localhost.localdomain (unknown [IPv6:fd1b:c28a:2fd6::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by chaos.universe-factory.net (Postfix) with ESMTPSA id AE711186C9C for ; Sat, 13 May 2017 21:56:57 +0200 (CEST) From: Matthias Schiffer To: lede-dev@lists.infradead.org Date: Sat, 13 May 2017 21:56:43 +0200 Message-Id: X-Mailer: git-send-email 2.13.0 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170513_125744_746581_DF76517E X-CRM114-Status: UNSURE ( 7.50 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Subject: [LEDE-DEV] [PATCH v2 13/19] base-files: add support for staged sysupgrades from failsafe mode X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Signed-off-by: Matthias Schiffer --- .../base-files/files/lib/preinit/40_run_failsafe_hook | 6 +++++- .../base-files/files/lib/preinit/99_10_failsafe_login | 11 +++++++---- package/base-files/files/sbin/sysupgrade | 18 +++++++++++++----- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/package/base-files/files/lib/preinit/40_run_failsafe_hook b/package/base-files/files/lib/preinit/40_run_failsafe_hook index 7301f77349..533b0a9771 100644 --- a/package/base-files/files/lib/preinit/40_run_failsafe_hook +++ b/package/base-files/files/lib/preinit/40_run_failsafe_hook @@ -5,8 +5,12 @@ run_failsafe_hook() { [ "$pi_preinit_no_failsafe" = "y" ] && return if [ "$FAILSAFE" = "true" ]; then + lock /tmp/.failsafe boot_run_hook failsafe - lock -w /tmp/.failsafe + while [ ! -e /tmp/sysupgrade ]; do + lock -w /tmp/.failsafe + done + exit fi } diff --git a/package/base-files/files/lib/preinit/99_10_failsafe_login b/package/base-files/files/lib/preinit/99_10_failsafe_login index 3147cdc5a6..728c63b2e8 100644 --- a/package/base-files/files/lib/preinit/99_10_failsafe_login +++ b/package/base-files/files/lib/preinit/99_10_failsafe_login @@ -8,10 +8,13 @@ failsafe_netlogin () { } failsafe_shell() { - lock /tmp/.failsafe - ash --login - echo "Please reboot system when done with failsafe network logins" - while true; do sleep 1; done + local console="$(sed -e 's/ /\n/g' /proc/cmdline | grep '^console=' | head -1 | sed -e 's/^console=//' -e 's/,.*//')" + [ -n "$console" ] || console=console + [ -c "/dev/$console" ] || return 0 + while true; do + ash --login <"/dev/$console" >"/dev/$console" 2>"/dev/$console" + sleep 1 + done & } boot_hook_add failsafe failsafe_netlogin diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade index 200a0e520b..809e789f9f 100755 --- a/package/base-files/files/sbin/sysupgrade +++ b/package/base-files/files/sbin/sysupgrade @@ -251,8 +251,16 @@ run_hooks "" $sysupgrade_pre_upgrade install_bin /sbin/upgraded v "Commencing upgrade. All shell sessions will be closed now." -ubus call system sysupgrade "{ - \"prefix\": \"$RAM_ROOT\", - \"path\": $(json_string "$IMAGE"), - \"command\": \". /lib/functions.sh; include /lib/upgrade; do_upgrade_stage2\" -}" + +COMMAND='. /lib/functions.sh; include /lib/upgrade; do_upgrade_stage2' + +if [ -n "$FAILSAFE" ]; then + printf '%s\x00%s\x00%s' "$RAM_ROOT" "$IMAGE" "$COMMAND" >/tmp/sysupgrade + lock -u /tmp/.failsafe +else + ubus call system sysupgrade "{ + \"prefix\": $(json_string "$RAM_ROOT"), + \"path\": $(json_string "$IMAGE"), + \"command\": $(json_string "$COMMAND") + }" +fi