From nobody Mon Dec 26 17:18:51 2022 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Ngkz14gqHz2G3X6 for ; Mon, 26 Dec 2022 17:18:53 +0000 (UTC) (envelope-from nhuff@acm.org) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4Ngkz067RSz3Htn for ; Mon, 26 Dec 2022 17:18:52 +0000 (UTC) (envelope-from nhuff@acm.org) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=messagingengine.com header.s=fm2 header.b="g plJN77"; spf=softfail (mx1.freebsd.org: 66.111.4.27 is neither permitted nor denied by domain of nhuff@acm.org) smtp.mailfrom=nhuff@acm.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=acm.org (policy=none) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id BE9AC5C00C6; Mon, 26 Dec 2022 12:18:52 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 26 Dec 2022 12:18:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:message-id:mime-version :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1672075132; x= 1672161532; bh=qVXJc+fyWnvk2nA9LT0oLoN1NFCuqkZHeT675O0AdVQ=; b=g plJN772IqD/Rev2p24AkgyoELZE/wYP/V8yF3ayhtbzMUYoMNvrdoHKekZG8WvTo X3TAFi/0L5S68T8OWU9EUiMVhrx4Vgm5+nPBeTFHXq4exA6S9SY230w/FrT/MAqM UcfYgduhDAXLnjQBaGTzVwblI/Vdxg1yhLQ2zWoo762aZfk1+TRdm5bN8hgqJ+Z2 XbAW2UKWeafgmREMUV1QK26g57HsWhK/kV1jbjZ7t+ZwFTZKedupI5GCRwRKXswv 2pDPv6lq9zu4a9NzfZ6umtmpt3q8ETmd6tx2iX+lWmZ9nOUvL9wdJRAva4qeBmWc sQYndqnaqf6g9rM5/xqHA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrheekgdellecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkfggtgesthdtredttddttd enucfhrhhomheppfgrthhhrghnucfjuhhffhcuoehnhhhufhhfsegrtghmrdhorhhgqeen ucggtffrrghtthgvrhhnpefgvdffgefgvedugfeifeduveefudeuveefheejveffffejle ekjeffkedvteevgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhl fhhrohhmpehnhhhufhhfsegrtghmrdhorhhg X-ME-Proxy: Feedback-ID: ida914761:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 26 Dec 2022 12:18:52 -0500 (EST) From: Nathan Huff To: freebsd-hackers@freebsd.org Subject: daemon(8) exit behavior Date: Mon, 26 Dec 2022 10:18:51 -0700 Message-ID: <86tu1i6q2s.fsf@enyo.nrhuff.com> List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain X-Spamd-Result: default: False [-4.30 / 15.00]; DWL_DNSWL_LOW(-1.00)[messagingengine.com:dkim]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-0.996]; R_DKIM_ALLOW(-0.20)[messagingengine.com:s=fm2]; MIME_GOOD(-0.10)[text/plain]; RCVD_IN_DNSWL_LOW(-0.10)[66.111.4.27:from]; DMARC_POLICY_SOFTFAIL(0.10)[acm.org : No valid SPF, DKIM not aligned (relaxed),none]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_THREE(0.00)[4]; DKIM_TRACE(0.00)[messagingengine.com:+]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; MLMMJ_DEST(0.00)[freebsd-hackers@freebsd.org]; R_SPF_SOFTFAIL(0.00)[~all]; ASN(0.00)[asn:19151, ipnet:66.111.4.0/24, country:US]; RWL_MAILSPIKE_POSSIBLE(0.00)[66.111.4.27:from]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; FROM_HAS_DN(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 4Ngkz067RSz3Htn X-Spamd-Bar: ---- X-ThisMailContainsUnwantedMimeParts: N The current behavior for the daemon command when it receives the HUP signal and it is supervising a process is to send a HUP signal to the supervised process and then exit immediately. According to the source comments this is the intended behavior. The issue I have run into with this behavior is that when the daemon process is when writing the supervised processes stdout/stderr to syslog or an output file you can lose any log messages that the supervised process outputs during its shutdown process. I created a small modification to the daemon process that allows setting a shutdown delay that will send HUP to the supervised process then continues to read the process output for up to delay seconds and then sends the supervised process the KILL signal. This allows a window for the supervised process to gracefully shutdown and we can still log any messages created during that time period. A couple questions for the list. 1. Is there any interest in upstreaming this? 2. What should happen if the supervised process doesn't exit after the KILL signal is sent? Something has probably gone sideways somewhere if we end up here, but I have definitely seen cases where something is stuck with signals blocked. Currently my modification waits for the process to actually exit possibly indefinitely. I chose that because I don't think we should clean up PID files if the process is in fact still running, but I can see wanting the daemon process to exit even if the supervised process is still running as that is the current behavior and still the behavior if a shutdown delay is not specified in my modified version. -- Nathan Huff