From patchwork Tue Jan 1 23:44:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Heimpold X-Patchwork-Id: 1019854 X-Patchwork-Delegate: blogic@openwrt.org 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=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=heimpold.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="fDwzsDsO"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=heimpold.de header.i=@heimpold.de header.b="oA5gQyMS"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::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 43TrQt10sVz9rxp for ; Wed, 2 Jan 2019 10:45:42 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject: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=qL6GlXF4h7peM8jUF8CHqxwwvrTMenz8vBfv44u+Jsk=; b=fDwzsDsOPE2UwW xQ1EGrm/K0KqOYU2huFUqVhuidhluOOM0phxLOyHb6sok/+AhUyFN5wlEk9Hg4NqwC5Sfpvw5xGNP 4m1p/FT9Jd2S0mNVnRIJNR/y1+PzZrGkYYvnygae5tEFHvsy7nZ471MrYPDUOsv7Tf9biuo1uOoiO wdVS90GDjtbMh9GJBNih+FR0iB+imRRCYE7Etzp2KFU54CLJoY9Phdd60Ng7IhDKGT/1f1M/6XdyG 6032BmfC+mCRgiINPyfBO2nwwDH/84tnANu3klPhtDV6Zh3msZkhxqpOw1WUMshZf9tIQzz7t6Kbe jW1PAtKN4n5qblE8x5FA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1geTj7-0004V7-Dy; Tue, 01 Jan 2019 23:45:37 +0000 Received: from mo6-p00-ob.smtp.rzone.de ([2a01:238:20a:202:5300::10]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1geTig-00030W-Ep for openwrt-devel@lists.openwrt.org; Tue, 01 Jan 2019 23:45:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1546386303; s=strato-dkim-0002; d=heimpold.de; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=i7kwSUd8d9y8+vIkYA4yo96Dweue8dCGSbe/zNX82S0=; b=oA5gQyMSFq8wc50cHVyLk5u40EbeMMJVtfuuqPqJJq4D67CM+mkZFKFtyUC7vi+dOG p0MDdSXYLovjca0EXsANwSgKLI5rVdJRBVDH6gHS4AiEHSRXwSR+EVFtP8oVYQ/APEf3 Syo1TAm7bKbPAKGBzJm2LAbyGdFYgbe8OOpThRFwEu5cKxSQrgDFS+T4RFZFJplLa5zq xTp0LD2SaZrKDLDQMNhewMhp51vF305qgwMNmyFyZQG6PWH94PJnn5XTDyty7XuhbQBd 3O/C29YIGE/JVcAAR606SU8mYCG/1LU9OkpMf9zafpoxsP11qUYJa5PAyYBRyfSn1id8 NZFQ== X-RZG-AUTH: ":O2kGeEG7b/pS1EW8QnKjhhg/vO4pzqdNytq77N6ZKUSN7PfdWTGbO3oK8Gj1rLTl4HJ2UQ==" X-RZG-CLASS-ID: mo00 Received: from tonne.mhei.heimpold.itr by smtp.strato.de (RZmta 44.9 DYNA|AUTH) with ESMTPSA id y05b79v01Nj3HZn (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Wed, 2 Jan 2019 00:45:03 +0100 (CET) Received: from kerker.mhei.heimpold.itr (kerker.mhei.heimpold.itr [192.168.8.1]) by tonne.mhei.heimpold.itr (Postfix) with ESMTP id 8389E1C7A9B; Wed, 2 Jan 2019 00:45:02 +0100 (CET) From: Michael Heimpold To: openwrt-devel@lists.openwrt.org Date: Wed, 2 Jan 2019 00:44:54 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190101_154510_923764_3FAF3662 X-CRM114-Status: UNSURE ( 9.84 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.9 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a01:238:20a:202:5300:0:0:10 listed in] [list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain Subject: [OpenWrt-Devel] [PATCH 2/7] procd: guard fork_worker calls X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Heimpold MIME-Version: 1.0 Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Usually respawn(), askfirst(), askconsole() and rcrespawn() are run only one time to start a worker child for the given inittab entry. In case we want to allow calling these functions several times, we need to ensure that we do not start multiple workers at the same time for the same inittab item. For this, we can re-use the remembered pid of the worker child, however, we need to reset this pid to allow a new instance in case the previous child exited. Signed-off-by: Michael Heimpold --- inittab.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/inittab.c b/inittab.c index c9e6c13..b8552e9 100644 --- a/inittab.c +++ b/inittab.c @@ -120,14 +120,17 @@ static void child_exit(struct uloop_process *proc, int ret) { struct init_action *a = container_of(proc, struct init_action, proc); - DEBUG(4, "pid:%d\n", proc->pid); - uloop_timeout_set(&a->tout, a->respawn); + DEBUG(4, "pid:%d, exitcode:%d\n", proc->pid, ret); + proc->pid = 0; + + uloop_timeout_set(&a->tout, a->respawn); } static void respawn(struct uloop_timeout *tout) { struct init_action *a = container_of(tout, struct init_action, tout); - fork_worker(a); + if (!a->proc.pid) + fork_worker(a); } static void rcdone(struct runqueue *q) @@ -163,7 +166,8 @@ static void askfirst(struct init_action *a) a->respawn = 500; a->proc.cb = child_exit; - fork_worker(a); + if (!a->proc.pid) + fork_worker(a); } static void askconsole(struct init_action *a) @@ -197,7 +201,8 @@ static void askconsole(struct init_action *a) a->respawn = 500; a->proc.cb = child_exit; - fork_worker(a); + if (!a->proc.pid) + fork_worker(a); } static void rcrespawn(struct init_action *a) @@ -206,7 +211,8 @@ static void rcrespawn(struct init_action *a) a->respawn = 500; a->proc.cb = child_exit; - fork_worker(a); + if (!a->proc.pid) + fork_worker(a); } static struct init_handler handlers[] = {