From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45356) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dJslR-0001EO-Hh for guix-patches@gnu.org; Sat, 10 Jun 2017 22:38:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dJslO-0005J9-EL for guix-patches@gnu.org; Sat, 10 Jun 2017 22:38:05 -0400 Received: from debbugs.gnu.org ([208.118.235.43]:36917) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dJslO-0005J5-Bq for guix-patches@gnu.org; Sat, 10 Jun 2017 22:38:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dJslO-0005cR-6D for guix-patches@gnu.org; Sat, 10 Jun 2017 22:38:02 -0400 Subject: bug#27323: [PATCH shepherd] Make sure that shepherd does not serve already-served sockets. Resent-Message-ID: Received: from eggs.gnu.org ([2001:4830:134:3::10]:45236) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dJskP-0000df-Ni for guix-patches@gnu.org; Sat, 10 Jun 2017 22:37:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dJskM-00051U-LV for guix-patches@gnu.org; Sat, 10 Jun 2017 22:37:01 -0400 Received: from dd1012.kasserver.com ([85.13.128.8]:47110) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dJskM-00051J-EV for guix-patches@gnu.org; Sat, 10 Jun 2017 22:36:58 -0400 From: Danny Milosavljevic Date: Sun, 11 Jun 2017 04:36:50 +0200 Message-Id: <20170611023650.6928-1-dannym@scratchpost.org> 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: 27323@debbugs.gnu.org * 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)