From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33971) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eqmq1-0006wb-Ku for guix-patches@gnu.org; Tue, 27 Feb 2018 16:31:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eqmpy-0001HU-CI for guix-patches@gnu.org; Tue, 27 Feb 2018 16:31:05 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:56371) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eqmpy-0001Gu-6d for guix-patches@gnu.org; Tue, 27 Feb 2018 16:31:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eqmpx-000144-R9 for guix-patches@gnu.org; Tue, 27 Feb 2018 16:31:01 -0500 Subject: [bug#30532] [PATCH] Shepherd: Terminate all services upon SIGTERM or SIGHUP Resent-Message-ID: References: <87sh9wnbu6.fsf@zancanaro.id.au> <87lgfe4vft.fsf@gnu.org> From: Carlo Zancanaro In-reply-to: <87lgfe4vft.fsf@gnu.org> Date: Wed, 28 Feb 2018 08:29:50 +1100 Message-ID: <87a7vu9l4h.fsf@zancanaro.id.au> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" 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: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 30532@debbugs.gnu.org --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Hey Ludo, On Tue, Feb 27 2018, Ludovic Court=C3=A8s wrote: >> It's also worth noting that I had to run `gettextize` to get=20 >> Shepherd >> to build on current master, but I haven't included those=20 >> changes in >> this commit (because I don't know what should be committed and=20 >> what >> shouldn't). > > Right, I=E2=80=99m not sure what=E2=80=99s wrong with that. I=E2=80=99ve= committed the=20 > same > files under po/ as I did for Guix: > > --8<---------------cut=20 > here---------------start------------->8--- > $ git ls-files po/ > po/Makevars > po/POTFILES.in > --8<---------------cut=20 > here---------------end--------------->8--- If you clone shepherd from the repository, can you build it?=20 Comparing the guix repository to the shepherd one I can't easily=20 work out what needs to be done for this, but hopefully you can at=20 least reproduce my problem. > I have one request: since the three tests differ only in the=20 > signal > name, could you make it a single test file and have a loop like: > > for signal in SIGTERM SIGHUP SIGINT Updated patch is attached. Carlo --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=0001-Terminate-all-services-upon-SIGTERM-or-SIGHUP.patch Content-Transfer-Encoding: quoted-printable From=20717456edd92ba753daf5dd40e2f8d51eab3e7a73 Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Tue, 20 Feb 2018 02:52:47 +1100 Subject: [PATCH] Terminate all services upon SIGTERM or SIGHUP * modules/shepherd.scm (main): Add SIGTERM and SIGHUP handlers which stop root-service. * tests/sigint.sh: Rename to... * tests/signals.sh: ... this, and add tests for SIGTERM and SIGUP. =2D-- Makefile.am | 3 ++- modules/shepherd.scm | 11 +++++++++++ tests/{sigint.sh =3D> signals.sh} | 23 ++++++++++++++--------- 3 files changed, 27 insertions(+), 10 deletions(-) rename tests/{sigint.sh =3D> signals.sh} (72%) diff --git a/Makefile.am b/Makefile.am index a30b11d..1c394e1 100644 =2D-- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,7 @@ # Makefile.am -- How to build and install the Shepherd. # Copyright =C2=A9 2002, 2003 Wolfgang J=C3=A4hrling # Copyright =C2=A9 2013, 2014, 2015, 2016, 2018 Ludovic Court=C3=A8s +# Copyright =C2=A9 2018 Carlo Zancanaro # # This file is part of the GNU Shepherd. # @@ -188,7 +189,7 @@ TESTS =3D \ tests/no-home.sh \ tests/pid-file.sh \ tests/status-sexp.sh \ =2D tests/sigint.sh + tests/signals.sh =20 TEST_EXTENSIONS =3D .sh EXTRA_DIST +=3D $(TESTS) diff --git a/modules/shepherd.scm b/modules/shepherd.scm index 5334657..650ba63 100644 =2D-- a/modules/shepherd.scm +++ b/modules/shepherd.scm @@ -1,6 +1,7 @@ ;; shepherd.scm -- The daemon shepherd. ;; Copyright (C) 2013, 2014, 2016, 2018 Ludovic Court=C3=A8s ;; Copyright (C) 2002, 2003 Wolfgang J=C3=A4hrling +;; Copyright (C) 2018 Carlo Zancanaro ;; ;; This file is part of the GNU Shepherd. ;; @@ -182,6 +183,16 @@ (lambda _ (stop root-service))) =20 + ;; Stop everything when we get SIGTERM. + (sigaction SIGTERM + (lambda _ + (stop root-service))) + + ;; Stop everything when we get SIGHUP. + (sigaction SIGHUP + (lambda _ + (stop root-service))) + ;; Ignore SIGPIPE so that we don't die if a client closes the connecti= on ;; prematurely. (sigaction SIGPIPE SIG_IGN) diff --git a/tests/sigint.sh b/tests/signals.sh similarity index 72% rename from tests/sigint.sh rename to tests/signals.sh index 7354848..acb254a 100644 =2D-- a/tests/sigint.sh +++ b/tests/signals.sh @@ -1,5 +1,6 @@ =2D# GNU Shepherd --- Make sure SIGINT is correctly handled. +# GNU Shepherd --- Make sure SIGINT, SIGTERM, and SIGHUP are correctly han= dled. # Copyright =C2=A9 2014, 2016 Ludovic Court=C3=A8s +# Copyright =C2=A9 2018 Carlo Zancanaro # # This file is part of the GNU Shepherd. # @@ -44,14 +45,18 @@ cat > "$conf"<