From mboxrd@z Thu Jan 1 00:00:00 1970 From: iyzsong@member.fsf.org (=?UTF-8?Q?=E5=AE=8B=E6=96=87=E6=AD=A6?=) Subject: bug#34407: [PATCH] shepherd: Delete the socket file upon exit. Date: Sun, 17 Feb 2019 11:38:16 +0800 Message-ID: <87ef87w0d3.fsf__31901.1671048187$1550374758$gmane$org@member.fsf.org> References: <87k1i868hk.fsf@disroot.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([209.51.188.92]:41620) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvDIF-0001mE-OL for bug-guix@gnu.org; Sat, 16 Feb 2019 22:39:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gvDIE-0002B3-HA for bug-guix@gnu.org; Sat, 16 Feb 2019 22:39:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:51363) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gvDIE-0002Au-Dr for bug-guix@gnu.org; Sat, 16 Feb 2019 22:39:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gvDIE-0006jt-3G for bug-guix@gnu.org; Sat, 16 Feb 2019 22:39:02 -0500 In-Reply-To: <87k1i868hk.fsf@disroot.org> Sender: "Debbugs-submit" Resent-Message-ID: List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org Sender: "bug-Guix" To: 34407@debbugs.gnu.org Cc: guix-devel@gnu.org --=-=-= Content-Type: text/plain Yes, I have the 'rm /run/user/1000/shepherd/socket' workaround in my session script too... According to 'man 2 bind', the socket pathname should be deleted when no longer required, so a patch to fix this bug: --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-shepherd-Delete-the-socket-file-upon-exit.patch >From f171f6adb2fc6ee3bf4d25378c2e7bba109b43d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E6=96=87=E6=AD=A6?= Date: Sun, 17 Feb 2019 11:27:28 +0800 Subject: [PATCH] shepherd: Delete the socket file upon exit. Fixes . * modules/shepherd.scm (call-with-server-socket): New procedure. (main): Use it instead of 'open-server-socket'. --- modules/shepherd.scm | 65 ++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/modules/shepherd.scm b/modules/shepherd.scm index e241e7a..314b989 100644 --- a/modules/shepherd.scm +++ b/modules/shepherd.scm @@ -49,6 +49,17 @@ (listen sock 10) sock))) +(define (call-with-server-socket file-name proc) + "Call PROC, passing it a listening socket at FILE-NAME and deleting the +socket file at FILE-NAME upon exit of PROC. Return the values of PROC." + (let ((sock (open-server-socket file-name))) + (dynamic-wind + noop + (lambda () (proc sock)) + (lambda () + (close sock) + (delete-file file-name))))) + ;; Main program. (define (main . args) @@ -256,32 +267,34 @@ ;; Get commands from the standard input port. (process-textual-commands (current-input-port)) ;; Process the data arriving at a socket. - (let ((sock (open-server-socket socket-file))) - - ;; Possibly write out our PID, which means we're ready to accept - ;; connections. XXX: What if we daemonized already? - (match pid-file - ((? string? file) - (with-atomic-file-output pid-file - (cute display (getpid) <>))) - (#t (display (getpid))) - (_ #t)) - - (let next-command () - (define (read-from sock) - (match (accept sock) - ((command-source . client-address) - (setvbuf command-source (buffering-mode block) 1024) - (process-connection command-source)) - (_ #f))) - (match (select (list sock) (list) (list) (if poll-services? 0.5 #f)) - (((sock) _ _) - (read-from sock)) - (_ - #f)) - (when poll-services? - (check-for-dead-services)) - (next-command))))))) + (call-with-server-socket + socket-file + (lambda (sock) + + ;; Possibly write out our PID, which means we're ready to accept + ;; connections. XXX: What if we daemonized already? + (match pid-file + ((? string? file) + (with-atomic-file-output pid-file + (cute display (getpid) <>))) + (#t (display (getpid))) + (_ #t)) + + (let next-command () + (define (read-from sock) + (match (accept sock) + ((command-source . client-address) + (setvbuf command-source (buffering-mode block) 1024) + (process-connection command-source)) + (_ #f))) + (match (select (list sock) (list) (list) (if poll-services? 0.5 #f)) + (((sock) _ _) + (read-from sock)) + (_ + #f)) + (when poll-services? + (check-for-dead-services)) + (next-command)))))))) ;; Start all of SERVICES, which is a list of canonical names (FIXME?), ;; but in a order where all dependencies are fulfilled before we -- 2.19.2 --=-=-=--