From patchwork Tue Jan 21 08:35:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1226309 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=true.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20170209 header.b=MG2XpFEb; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48221m3zYRz9sR0 for ; Tue, 21 Jan 2020 19:36:12 +1100 (AEDT) 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:Message-Id:Date:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=h1+Fb1gNjzy4ABOCUqScxrnR0IzapbjhCwAMB76EJ+I=; b=MG2XpFEbHUqqCt 8ZSvVwnzCDnvgaHXp/TRsL9A2JIpDLMQ7OlObcmAiKUkt5dNJvfOdkyxO4HOg42+HXsgn7WWNjxuG Uq5/RqjDbxk1LDLADns6mWybW+6Zz1lWrCZEdZdAnGiH1VBEGUohrSdmEYeAC6CAjglbN8vs4sONf AcNixdkWe+EOcPIV4ESVVtFvkVvvrapW9GuChUZfO+Wn2IcN4EFop5qi8CIU7VIZhfZI6fUZKiQUY M89mZig71+JEALPPL6sJ3odjcwM6afmihKFCWldXa7low+vw3fsOmejgnvrFeCyRwFSft2vuAY+LY GG89GqHYh8aH5GMH5WVA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1itp16-0006iB-64; Tue, 21 Jan 2020 08:36:08 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1itp0y-0006hH-Ha for openwrt-devel@lists.openwrt.org; Tue, 21 Jan 2020 08:36:06 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id 7D1C04CB0; Tue, 21 Jan 2020 09:35:58 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 713bc491; Tue, 21 Jan 2020 09:35:48 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Tue, 21 Jan 2020 09:35:08 +0100 Message-Id: <20200121083509.24067-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200121_003600_733623_BD0392C9 X-CRM114-Status: UNSURE ( 9.38 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [178.217.244.18 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH procd 1/2] instance: provide error feedback if ujail binary is missing X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Petr_=C5=A0tetiar?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Otherwise it's quite hard to track such issues. While at it, be DRY and use UJAIL_BIN_PATH constant for ujail binary. Signed-off-by: Petr Štetiar --- service/instance.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/service/instance.c b/service/instance.c index 14da86247c70..e5615d5c2f02 100644 --- a/service/instance.c +++ b/service/instance.c @@ -36,6 +36,7 @@ #include "service.h" #include "instance.h" +#define UJAIL_BIN_PATH "/sbin/ujail" enum { INSTANCE_ATTR_COMMAND, @@ -205,7 +206,7 @@ jail_run(struct service_instance *in, char **argv) struct jail *jail = &in->jail; int argc = 0; - argv[argc++] = "/sbin/ujail"; + argv[argc++] = UJAIL_BIN_PATH; if (jail->name) { argv[argc++] = "-n"; @@ -795,9 +796,13 @@ instance_jail_parse(struct service_instance *in, struct blob_attr *attr) struct blob_attr *tb[__JAIL_ATTR_MAX]; struct jail *jail = &in->jail; struct stat s; + int r; - if (stat("/sbin/ujail", &s)) + r = stat(UJAIL_BIN_PATH, &s); + if (r < 0) { + ERROR("unable to find %s: %m (%d)\n", UJAIL_BIN_PATH, r); return 0; + } blobmsg_parse(jail_attr, __JAIL_ATTR_MAX, tb, blobmsg_data(attr), blobmsg_data_len(attr)); From patchwork Tue Jan 21 08:35:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1226311 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=true.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20170209 header.b=akIyyBDC; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4822231CmYz9s29 for ; Tue, 21 Jan 2020 19:36:27 +1100 (AEDT) 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=l872MqZJgncfFHG7fQgplqZr2wWt6rd6FZdjRw/CtWk=; b=akIyyBDChctdaC VsdGFBHiQ1QsSCWrFzf2PW9DwfqEIepqV84y4gMkLT4EC5OyOuHw//u1TF/1G778RErykyvwUFI/r msIdNzMb6GW5xx8SR9liMc7HPwJYQdAZqgD1wc+V9drD/awAGjD6tqmsVkSfQTb+xBgkJ0Ih+PG12 FzzXjA3rBX4oV6c+XyCrF5P3ej4MOjlBCF5HT+rlc0PeauuV7eIcEmlezL0Rum9t744PSea7IYnG+ mdiZSxPtM/YLlJ58EI+70ChjeNhB2UUUsvFmKAPnlhWL7tKpQGJHUFXGZ6xxVJPVpgXTajHl/TSJ2 tgAvVIiW0aQ3/ENvXRWQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1itp1G-0006tD-J1; Tue, 21 Jan 2020 08:36:18 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1itp0y-0006hJ-Hb for openwrt-devel@lists.openwrt.org; Tue, 21 Jan 2020 08:36:06 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id A56024CB1; Tue, 21 Jan 2020 09:35:58 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 3b8e76d9; Tue, 21 Jan 2020 09:35:48 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Tue, 21 Jan 2020 09:35:09 +0100 Message-Id: <20200121083509.24067-2-ynezz@true.cz> In-Reply-To: <20200121083509.24067-1-ynezz@true.cz> References: <20200121083509.24067-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200121_003600_736431_9C89A108 X-CRM114-Status: GOOD ( 11.93 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [178.217.244.18 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH procd 2/2] state: fix reboot causing shutdown inside LXC container X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Petr_=C5=A0tetiar?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Executing `reboot` command in OpenWrt system runing inside LXC container results in a shutdown of the container instead of rebooting the container. This appears to have been caused by commit 832369078d81 ("state: fix shutdown when running in a container (FS#2425)"), which exits the pid einz instead of the reboot(). While at it, refactor the halting code into separate function to shorten the switch/case block and make it clearer, decrease the indentation level by reversing the container if condition, replace magic 0 with EXIT_SUCCESS constant in exit() and make it wait 1s for reboot message delivery in both container/host cases as well. Ref: FS#2666 Cc: Paul Spooren Fixes: 832369078d81 ("state: fix shutdown when running in a container (FS#2425)") Tested-by: Baptiste Jonglez Signed-off-by: Petr Štetiar --- state.c | 52 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/state.c b/state.c index 4737d0121ad0..e117ea302f93 100644 --- a/state.c +++ b/state.c @@ -94,6 +94,34 @@ static void set_console(void) set_stdio(tty); } +static void perform_halt() +{ + if (reboot_event == RB_POWER_OFF) + LOG("- power down -\n"); + else + LOG("- reboot -\n"); + + /* Allow time for last message to reach serial console, etc */ + sleep(1); + + if (is_container()) { + reboot(reboot_event); + exit(EXIT_SUCCESS); + return; + } + + /* We have to fork here, since the kernel calls do_exit(EXIT_SUCCESS) + * in linux/kernel/sys.c, which can cause the machine to panic when + * the init process exits... */ + if (!vfork()) { /* child */ + reboot(reboot_event); + _exit(EXIT_SUCCESS); + } + + while (1) + sleep(1); +} + static void state_enter(void) { char ubus_cmd[] = "/sbin/ubusd"; @@ -153,29 +181,9 @@ static void state_enter(void) sync(); sleep(1); #ifndef DISABLE_INIT - if (reboot_event == RB_POWER_OFF) - LOG("- power down -\n"); - else - LOG("- reboot -\n"); - - if (!is_container()) { - /* Allow time for last message to reach serial console, etc */ - sleep(1); - - /* We have to fork here, since the kernel calls do_exit(EXIT_SUCCESS) - * in linux/kernel/sys.c, which can cause the machine to panic when - * the init process exits... */ - if (!vfork( )) { /* child */ - reboot(reboot_event); - _exit(EXIT_SUCCESS); - } - - while (1) - sleep(1); - } else - exit(0); + perform_halt(); #else - exit(0); + exit(EXIT_SUCCESS); #endif break;