guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dmd] 01/01: dmd: Stop the 'dmd' service upon SIGINT.


From: Ludovic Courtès
Subject: [dmd] 01/01: dmd: Stop the 'dmd' service upon SIGINT.
Date: Wed, 16 Jul 2014 10:40:20 +0000

civodul pushed a commit to branch master
in repository dmd.

commit 5c888411ba6422d93321ef3e60fe516381e6994f
Author: Ludovic Courtès <address@hidden>
Date:   Wed Jul 16 12:40:09 2014 +0200

    dmd: Stop the 'dmd' service upon SIGINT.
    
    * modules/dmd.scm (main): Add 'sigaction' call.
    * tests/sigint.sh: New file.
    * Makefile.am (TESTS): Add it.
---
 .gitignore      |    2 +
 Makefile.am     |    7 +++++-
 modules/dmd.scm |    7 ++++++
 tests/sigint.sh |   56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 71 insertions(+), 1 deletions(-)

diff --git a/.gitignore b/.gitignore
index 5686016..230d029 100644
--- a/.gitignore
+++ b/.gitignore
@@ -46,3 +46,5 @@ Makefile
 /tests/respawn.trs
 /tests/no-home.log
 /tests/no-home.trs
+/tests/sigint.log
+/tests/sigint.trs
diff --git a/Makefile.am b/Makefile.am
index 8e075bc..35f242d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -123,7 +123,12 @@ modules/dmd/config.scm: modules/dmd/config.scm.in Makefile
 
 SUFFIXES = .go
 
-TESTS = tests/basic.sh tests/respawn.sh tests/no-home.sh
+TESTS =                                                \
+  tests/basic.sh                               \
+  tests/respawn.sh                             \
+  tests/no-home.sh                             \
+  tests/sigint.sh
+
 TEST_EXTENSIONS = .sh
 EXTRA_DIST += $(TESTS)
 
diff --git a/modules/dmd.scm b/modules/dmd.scm
index dee5f1e..cf72d7a 100644
--- a/modules/dmd.scm
+++ b/modules/dmd.scm
@@ -172,6 +172,13 @@
       (sigaction SIGALRM (lambda _ (alarm 1)))
       (alarm 1))
 
+    ;; Stop everything when we get SIGINT.  When running as PID 1, that means
+    ;; rebooting; this is what happens when pressing ctrl-alt-del, see
+    ;; ctrlaltdel(8).
+    (sigaction SIGINT
+      (lambda _
+        (stop dmd-service)))
+
     (if (not socket-file)
        ;; Get commands from the standard input port.
         (process-textual-commands (current-input-port))
diff --git a/tests/sigint.sh b/tests/sigint.sh
new file mode 100644
index 0000000..0b74578
--- /dev/null
+++ b/tests/sigint.sh
@@ -0,0 +1,56 @@
+# GNU dmd --- Make sure SIGINT is correctly handled.
+# Copyright © 2014 Ludovic Courtès <address@hidden>
+#
+# This file is part of GNU dmd.
+#
+# GNU dmd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or (at
+# your option) any later version.
+#
+# GNU dmd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU dmd.  If not, see <http://www.gnu.org/licenses/>.
+
+dmd --version
+deco --version
+
+socket="t-socket-$$"
+conf="t-conf-$$"
+stamp="t-stamp-$$"
+pid="t-pid-$$"
+
+deco="deco -s $socket"
+
+trap "rm -f $socket $conf $stamp $pid;
+      test -f $pid && kill \`cat $pid\` || true" EXIT
+
+cat > "$conf"<<EOF
+(use-modules (srfi srfi-26))
+(register-services
+ (make <service>
+   #:provides '(test)
+   #:start (const #t)
+   #:stop  (lambda _
+             (call-with-output-file "$stamp"
+               (lambda (port)
+                 (display "stopped" port))))
+   #:respawn? #f))
+ (start 'test)
+EOF
+
+rm -f "$pid" "$stamp"
+dmd -I -s "$socket" -c "$conf" --pid="$pid" &
+
+while [ ! -f "$pid" ] ; do sleep 0.5 ; done
+
+# Send SIGINT to dmd.
+kill -INT "`cat "$pid"`"
+while kill -0 "`cat "$pid"`" ; do sleep 0.5 ; done
+
+# Make sure the service's 'stop' method was called.
+test -f "$stamp"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]