From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52942) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esquM-0000jg-QO for guix-patches@gnu.org; Mon, 05 Mar 2018 09:16:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esquI-00067P-Jv for guix-patches@gnu.org; Mon, 05 Mar 2018 09:16:06 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:37362) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1esquI-000679-FQ for guix-patches@gnu.org; Mon, 05 Mar 2018 09:16:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1esquI-00009J-87 for guix-patches@gnu.org; Mon, 05 Mar 2018 09:16:02 -0500 Subject: bug#30637: [WIP] shepherd: Poll every 0.5s to find dead forked services Resent-To: guix-patches@gnu.org Resent-Message-ID: From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) References: <878tbe9jvx.fsf@zancanaro.id.au> <87y3jcu5v5.fsf@gnu.org> <87d10nwhfl.fsf@zancanaro.id.au> <87r2p2izgz.fsf@gnu.org> <87371ihjj2.fsf@zancanaro.id.au> <87po4mhcn2.fsf@gnu.org> <87inadr3np.fsf@zancanaro.id.au> <87h8px9od8.fsf@gnu.org> <87woys9961.fsf@zancanaro.id.au> <87371f4hkf.fsf@gnu.org> <871sgzpiy9.fsf@zancanaro.id.au> <87o9k33199.fsf@gnu.org> <87y3j7o2wd.fsf@zancanaro.id.au> Date: Mon, 05 Mar 2018 15:15:10 +0100 In-Reply-To: <87y3j7o2wd.fsf@zancanaro.id.au> (Carlo Zancanaro's message of "Mon, 05 Mar 2018 10:08:02 +1100") Message-ID: <87d10ia9sh.fsf@gnu.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: Carlo Zancanaro Cc: 30637-done@debbugs.gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Carlo Zancanaro skribis: > From be442ea64e4fd8e235378a5f04d38296c0af9cf3 Mon Sep 17 00:00:00 2001 > From: Carlo Zancanaro > Date: Wed, 21 Feb 2018 22:57:59 +1100 > Subject: [PATCH] Poll every 0.5s to find dead forked services if prctl fa= ils. > > * modules/shepherd.scm (open-server-socket): Set socket to be > non-blocking. > (main): If we are unable to use prctl/PR_SET_CHILD_SUBREAPER, then poll= for > service processes between client connections, or every 0.5 seconds. > * modules/shepherd/service.scm (fork+exec-command): Install handle-SIGCHL= D as > signal handler. > (respawn-service): Separate logic for respawning services from handling > SIGCHLD. > (handle-SIGCHLD, check-for-dead-services): New exported procedures. > * tests/basic.sh, tests/status-sexp.sh: Replace constant integers with > symbols. > * doc/shepherd.texi (Slots of services): Add note about service running s= lot > being a process id. Awesome. Applied with minor cosmetic changes (see below). Thank you! Ludo=E2=80=99. --=-=-= Content-Type: text/x-patch Content-Disposition: inline diff --git a/modules/shepherd.scm b/modules/shepherd.scm index 9d94881..2b4a7b5 100644 --- a/modules/shepherd.scm +++ b/modules/shepherd.scm @@ -52,7 +52,8 @@ ;; Main program. (define (main . args) (define poll-services? - (and (not (= 1 (getpid))) ;; if we're pid 1 we don't need to do anything + ;; Do we need polling to find out whether services died? + (and (not (= 1 (getpid))) ;if we're pid 1, we don't (catch 'system-error (lambda () ;; Register for orphaned processes to be reparented onto us when @@ -60,14 +61,13 @@ ;; daemon processes that would otherwise have been reparented ;; under pid 1. Obviously this is unnecessary when we are pid 1. (prctl PR_SET_CHILD_SUBREAPER 1) - #f) ;; don't poll + #f) ;don't poll (lambda args ;; We fall back to polling for services on systems that don't - ;; support prctl/PR_SET_CHILD_SUBREAPER + ;; support prctl/PR_SET_CHILD_SUBREAPER. (let ((errno (system-error-errno args))) - (if (or (= ENOSYS errno) ;; prctl not available - (= EINVAL errno)) ;; PR_SET_CHILD_SUBREAPER not available - #t ;; poll + (or (= ENOSYS errno) ;prctl unavailable + (= EINVAL errno) ;PR_SET_CHILD_SUBREAPER unavailable (apply throw args))))))) (initialize-cli) --=-=-=--