GNU bug report logs - #27323
[PATCH shepherd] Make sure that shepherd does not serve already-served sockets.

Previous Next

Package: guix-patches;

Reported by: Danny Milosavljevic <dannym <at> scratchpost.org>

Date: Sun, 11 Jun 2017 02:38:01 UTC

Severity: normal

Tags: patch

Done: ludo <at> gnu.org (Ludovic Courtès)

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Danny Milosavljevic <dannym <at> scratchpost.org>
Subject: bug#27323: closed (Re: [bug#27323] [PATCH v2 shepherd 0/2] Make
 sure that shepherd does not serve already-served sockets.)
Date: Fri, 16 Jun 2017 08:20:02 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#27323: [PATCH shepherd] Make sure that shepherd does not serve already-served sockets.

which was filed against the guix-patches package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 27323 <at> debbugs.gnu.org.

-- 
27323: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=27323
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: ludo <at> gnu.org (Ludovic Courtès)
To: Danny Milosavljevic <dannym <at> scratchpost.org>
Cc: 27323-done <at> debbugs.gnu.org
Subject: Re: [bug#27323] [PATCH v2 shepherd 0/2] Make sure that shepherd does
 not serve already-served sockets.
Date: Fri, 16 Jun 2017 10:19:40 +0200
Hi,

Danny Milosavljevic <dannym <at> scratchpost.org> skribis:

> Danny Milosavljevic (2):
>   Use XDG_RUNTIME_DIR for the shepherd socket.
>   Make sure that shepherd does not serve already-served sockets.
>
>  modules/shepherd.scm         | 1 -
>  modules/shepherd/support.scm | 7 ++++++-
>  2 files changed, 6 insertions(+), 2 deletions(-)

Cool, applied both with a commit log and doc/test adjustments.

Thanks!

Ludo’.

[Message part 3 (message/rfc822, inline)]
From: Danny Milosavljevic <dannym <at> scratchpost.org>
To: guix-patches <at> gnu.org
Cc: Danny Milosavljevic <dannym <at> scratchpost.org>
Subject: [PATCH shepherd] Make sure that shepherd does not serve
 already-served sockets.
Date: Sun, 11 Jun 2017 04:36:50 +0200
* modules/shepherd.scm (server-present?): New variable.
(main): Adapt.
---
 modules/shepherd.scm | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/modules/shepherd.scm b/modules/shepherd.scm
index dd8a076..4998e09 100644
--- a/modules/shepherd.scm
+++ b/modules/shepherd.scm
@@ -32,10 +32,21 @@
   #:use-module (shepherd runlevel)
   #:use-module (shepherd args)
   #:use-module (shepherd comm)
+  #:use-module (rnrs io ports)
   #:export (main))
 
 
 
+(define (server-present? file-name)
+  "Open a socket at FILE-NAME, and connect to the server, if any.
+Return #t if that worked."
+  (with-fluids ((%default-port-encoding "UTF-8"))
+    (let ((sock (socket PF_UNIX SOCK_STREAM 0)))
+      (call-with-port sock
+        (lambda (sock)
+          (let ((address (make-socket-address AF_UNIX file-name)))
+            (false-if-exception (connect sock address))))))))
+
 (define (open-server-socket file-name)
   "Open a socket at FILE-NAME, and listen for connections there."
   (with-fluids ((%default-port-encoding "UTF-8"))
@@ -132,8 +143,12 @@
 					      ;; we use no socket.
 					      #f)))))))
     ;; We do this early so that we can abort early if necessary.
-    (and socket-file
-         (verify-dir (dirname socket-file) #:secure? secure))
+    (if socket-file
+      (begin
+         (verify-dir (dirname socket-file) #:secure? secure)
+         (if (server-present? socket-file)
+             (exit 0)))) ; There's already a shepherd instance running.
+
     ;; Enable logging as first action.
     (start-logging logfile)
 



This bug report was last modified 7 years and 341 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.