From patchwork Fri Apr 27 14:32:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Horak X-Patchwork-Id: 905770 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=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ibawizard.net Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="IcStcdU6"; 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 40XbyJ0KX2z9ryr for ; Sat, 28 Apr 2018 00:33:12 +1000 (AEST) 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: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:In-Reply-To:References: List-Owner; bh=DPm4DyUecbfCi1+RZGzuCq/a/fTP8qzrtNO5umdtm/k=; b=IcStcdU6c9EVEh 16De6eWoHlOdISLde+lVzC43o0dAXYVywSgcieNqq4HmoDXgk9ehzfZVX6+YJ4EM9Dfe8UoNnYBxU TgwV+MtWl7ElfYlnFQVig7r1Y+ds0dFeqlvxRU24oxuIvZzktRgK4T1iOrAN+Exi8MsBHo36Axppv kR24vUIJzCooCJKXKj4rK2VqpM/Kc7YtkezrUb/eBj2+pVftWgjp5fTh8pehTUc4L/FDBz53D1If5 3z1JDZCm0PshVGTPUihI4rArvaEqaz9YfxujLLoZZsQ77xiLXPEOvCGEVeTQri9BfTOQ5ONO7Vnx5 RjsGEBd1LM5n6m11cBfw==; 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 1fC4Qs-0002N4-5T; Fri, 27 Apr 2018 14:33:06 +0000 Received: from ibawizard.net ([82.208.49.253] helo=mengele.ibawizard.net) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fC4Qd-00028i-RH for lede-dev@lists.infradead.org; Fri, 27 Apr 2018 14:32:54 +0000 Received: by mengele.ibawizard.net (Postfix, from userid 1001) id ECD741D36073; Fri, 27 Apr 2018 16:32:33 +0200 (CEST) From: Jakub Horak To: lede-dev@lists.infradead.org Date: Fri, 27 Apr 2018 16:32:33 +0200 Message-Id: <1524839553-14226-1-git-send-email-thement@ibawizard.net> X-Mailer: git-send-email 1.7.2.5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180427_073252_101284_4F681390 X-CRM114-Status: GOOD ( 10.18 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- Subject: [LEDE-DEV] [PATCH] Fix resetting of "respawn" flag 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 This patch stops using instance "respawn" flag as a state variable. This fixes the bug when instance loses "respawn" flag after it has been restarted (if instance is started before the process has exited, it will not copy all parameters). --- service/instance.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/service/instance.c b/service/instance.c index a968a0b..5aab23a 100644 --- a/service/instance.c +++ b/service/instance.c @@ -506,12 +506,17 @@ instance_timeout(struct uloop_timeout *t) in = container_of(t, struct service_instance, timeout); - if (in->halt) { - LOG("Instance %s::%s pid %d not stopped on SIGTERM, sending SIGKILL instead\n", - in->srv->name, in->name, in->proc.pid); - kill(in->proc.pid, SIGKILL); - } else if (in->restart || in->respawn) - instance_start(in); + if (!in->proc.pending) { + if (in->respawn) { + instance_start(in); + } + } else { + if (in->halt) { + LOG("Instance %s::%s pid %d not stopped on SIGTERM, sending SIGKILL instead\n", + in->srv->name, in->name, in->proc.pid); + kill(in->proc.pid, SIGKILL); + } + } } static void @@ -545,6 +550,7 @@ instance_exit(struct uloop_process *p, int ret) service_stopped(s); } } else if (in->restart) { + /* can never happen */ instance_start(in); } else if (in->respawn) { if (runtime < in->respawn_threshold) @@ -554,8 +560,8 @@ instance_exit(struct uloop_process *p, int ret) if (in->respawn_count > in->respawn_retry && in->respawn_retry > 0 ) { LOG("Instance %s::%s s in a crash loop %d crashes, %ld seconds since last crash\n", in->srv->name, in->name, in->respawn_count, runtime); - in->restart = in->respawn = 0; - in->halt = 1; + in->restart = false; + in->halt = true; service_event("instance.fail", in->srv->name, in->name); } else { service_event("instance.respawn", in->srv->name, in->name); @@ -570,7 +576,7 @@ instance_stop(struct service_instance *in) if (!in->proc.pending) return; in->halt = true; - in->restart = in->respawn = false; + in->restart = false; kill(in->proc.pid, SIGTERM); uloop_timeout_set(&in->timeout, in->term_timeout * 1000); }