From patchwork Thu Oct 19 13:02:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kristian Evensen X-Patchwork-Id: 828057 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=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="KQORLy8O"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="j4/W9Ejy"; dkim-atps=neutral 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 3yHpyJ0Fbkz9t42 for ; Fri, 20 Oct 2017 00:03:20 +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: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=cT9JE8mAf402I4ihfR+rIvCAfrrbAKWNo1XZkO4BzD8=; b=KQORLy8Oacrvub KiybH9craIvkysALNs3HhxBB0Er8FHkI43AZZyl2cOEfwRbuw267ShL9Xb5b525FI0Y6zuSiXQpaA G9/buBc7/4G5xztKUm8SzBvz2FkTPK/cStJUcd4eMW0AglsnO9brEEmpdCalPPi7JkLg/24UBwaA1 40ZHH5zTy2+dVrCOaT+M27Adb4KEU6WDooG1AzZToZS61lb5boj+Yzf3Ag16rd12IsR0uxnEMfR96 mvViMuGEFKtBLptMeh6LNViO8b159XDgdVFwo68cpSIFN2sMEnv5NQbxrAKkfT5CdekjFC//wZvjG K1S2GesFozPeOzRDJmvQ==; 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 1e5ATk-0001Sj-Io; Thu, 19 Oct 2017 13:03:16 +0000 Received: from mail-lf0-x243.google.com ([2a00:1450:4010:c07::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e5ATD-0000p4-UX for lede-dev@lists.infradead.org; Thu, 19 Oct 2017 13:02:54 +0000 Received: by mail-lf0-x243.google.com with SMTP id n69so9527376lfn.2 for ; Thu, 19 Oct 2017 06:02:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=gYnKhk+SbJ/PofHf3hCLCzJb4r27AMPwEYA67o64Mes=; b=j4/W9EjyVmXhRdKdhFxkn7FIHui1xb4KCVn4uB4VURhoU/lSDZatYX3d5YS4K+bhm2 y0mdhLkcJ2U4db2f+Hk4EjryCqFvyiOsb1UjBhIux1CiLQvA+epHfDYdMU3zJSmBzlI1 kP0z3ZBATpkQCN51y7ANblRq2RFllqh9vqi4V1/A/t9DaI4BRdSTiHAuuzk6wxWQTZjl hrN5iFBaNa4+gB7INb0Is5JsVawg7q/hpoVyU1vjt4mEcxZ6pQHI7O4lcxr+6U+/9imn Z+Np4Btd+b29YSQV5gxjTRx/1EemERlul9jxf/OSNnsUJx1ZIyNokbSBu7DlpgYutbOC hCLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=gYnKhk+SbJ/PofHf3hCLCzJb4r27AMPwEYA67o64Mes=; b=ppRCbVnSWdcYLxXRIaGpY8xtK131YlsiUE/LbPJHs96td22BcrZKhTzmyR/lAMNQFb y6Q6AfjeO7KbCJUsJEWLeJxhm0BeNeNW/eoSx9ePHSWx+rhKQN5gZ/krUeKCmQuTltBs nLHyuvVDRoUBrxM/cD6pV5zgNGHOYPmLkS6u2CRUI8t0P4SsyoCHW8nmvCsCcdYzlshQ arll77EQAkOmjNp5O66/GSH36pyv8RcYQQGez/DliJyY0PvcxEDc4fZ9Zg25ogWXjelr cDwiQoYG+tkACl7aEUdGgnkEHoS0PoXIs3hJApmtKyLaULqefeo+q9wrMQUonGtpaDn5 nQLQ== X-Gm-Message-State: AMCzsaVm4Cq1868vKBSlkBw8NuLmG76dAoUlCB0Yo8XappZuY/16nQlP gkv6qYjFRRS3N8b9csAFYuJoxs+P X-Google-Smtp-Source: ABhQp+ReLS3uopQkssKQ+IjsJpLStDfENo8QI95qtnYhHeJTbueGCBTCfbPmz35JBI7OtX4dgO5NJQ== X-Received: by 10.46.83.73 with SMTP id t9mr748832ljd.68.1508418140967; Thu, 19 Oct 2017 06:02:20 -0700 (PDT) Received: from localhost.localdomain ([91.90.161.66]) by smtp.gmail.com with ESMTPSA id y13sm1319285ljd.62.2017.10.19.06.02.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Oct 2017 06:02:20 -0700 (PDT) From: Kristian Evensen To: lede-dev@lists.infradead.org Date: Thu, 19 Oct 2017 15:02:15 +0200 Message-Id: <20171019130215.31354-1-kristian.evensen@gmail.com> X-Mailer: git-send-email 2.11.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171019_060244_719774_5B69BB87 X-CRM114-Status: GOOD ( 12.60 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (kristian.evensen[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -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: [LEDE-DEV] [PATCH] procd: Restore respawn on SIGTERM timeout 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: , Cc: Kristian Evensen MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org When SIGTERM times out, procd sends SIGKILL and then restarts the process once SIGCHLD has been received. This all works fine, with one exception - respawn is not restored when instance_start() is called from instance_exit(). The reason is that respawn is always set to false in instance_stop(), and the same service_instance struct is used for the instance_start()-call. The consequence is that if the process is killed/crashes again, it will not respawn. Solve this issue by adding a variable used to store the original value of respawn in instance_stop(), and then restore the original respawn-value in instance_exit(). Signed-off-by: Kristian Evensen --- service/instance.c | 6 ++++-- service/instance.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/service/instance.c b/service/instance.c index b7cb523..76c74ed 100644 --- a/service/instance.c +++ b/service/instance.c @@ -532,9 +532,10 @@ instance_exit(struct uloop_process *p, int ret) if (in->halt) { instance_removepid(in); - if (in->restart) + if (in->restart) { + in->respawn = in->respawn_org; instance_start(in); - else { + } else { struct service *s = in->srv; avl_delete(&s->instances.avl, &in->node.avl); @@ -567,6 +568,7 @@ instance_stop(struct service_instance *in, bool halt) if (!in->proc.pending) return; in->halt = halt; + in->respawn_org = in->respawn; in->restart = in->respawn = false; kill(in->proc.pid, SIGTERM); uloop_timeout_set(&in->timeout, in->term_timeout * 1000); diff --git a/service/instance.h b/service/instance.h index bdd14de..a0ac302 100644 --- a/service/instance.h +++ b/service/instance.h @@ -48,6 +48,7 @@ struct service_instance { bool halt; bool restart; bool respawn; + bool respawn_org; int respawn_count; int reload_signal; struct timespec start;