From: Danny Milosavljevic <dannym@scratchpost.org>
To: 27323@debbugs.gnu.org
Subject: bug#27323: [PATCH shepherd] Make sure that shepherd does not serve already-served sockets.
Date: Sun, 11 Jun 2017 04:36:50 +0200 [thread overview]
Message-ID: <20170611023650.6928-1-dannym@scratchpost.org> (raw)
* 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))
\f
+(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)
next reply other threads:[~2017-06-11 2:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-11 2:36 Danny Milosavljevic [this message]
2017-06-14 7:49 ` [bug#27323] [PATCH v2 shepherd 0/2] Make sure that shepherd does not serve already-served sockets Danny Milosavljevic
2017-06-14 7:49 ` [bug#27323] [PATCH v2 shepherd 1/2] Use XDG_RUNTIME_DIR for the shepherd socket Danny Milosavljevic
2017-06-14 7:49 ` [bug#27323] [PATCH v2 shepherd 2/2] Make sure that shepherd does not serve already-served sockets Danny Milosavljevic
2017-06-16 8:19 ` bug#27323: [PATCH v2 shepherd 0/2] " Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170611023650.6928-1-dannym@scratchpost.org \
--to=dannym@scratchpost.org \
--cc=27323@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).