guix-commits
[Top][All Lists]
Advanced

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

[shepherd] 05/08: service: Define <inetd-service> and serialize it.


From: Ludovic Courtès
Subject: [shepherd] 05/08: service: Define <inetd-service> and serialize it.
Date: Sat, 17 Feb 2024 13:07:18 -0500 (EST)

civodul pushed a commit to branch devel
in repository shepherd.

commit 0d302e3b4fbe5403d05d4efc6cf4911553460ee1
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Sat Feb 17 18:48:20 2024 +0100

    service: Define <inetd-service> and serialize it.
    
    * modules/shepherd/service.scm (endpoint->sexp): New procedure.
    (<inetd-service>): New record type.
    (inetd-service->sexp): New serializer.
    (make-inetd-constructor): Return an <inetd-service>.
    (make-inetd-destructor): Adjust accordingly.
---
 modules/shepherd/service.scm | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 686b5cf..8274634 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -1998,6 +1998,17 @@ waiting for the shell to terminate."
   (permissions endpoint-socket-directory-permissions)  ;integer
   (bind-attempts endpoint-bind-attempts))              ;integer
 
+(define (endpoint->sexp endpoint)
+  `(endpoint (version 0)
+             (name ,(endpoint-name endpoint))
+             (address ,(endpoint-address endpoint))
+             (style ,(endpoint-style endpoint))
+             (backlog ,(endpoint-backlog endpoint))
+             (owner ,(endpoint-socket-owner endpoint))
+             (group ,(endpoint-socket-group endpoint))
+             (permissions ,(endpoint-socket-directory-permissions endpoint))
+             (bind-attempts ,(endpoint-bind-attempts endpoint))))
+
 (define default-bind-attempts
   ;; Default number of 'bind' attempts upon EADDRINUSE.
   (make-parameter 5))
@@ -2123,6 +2134,20 @@ thrown an previously-opened sockets are closed."
 ;;; Inetd-style services.
 ;;;
 
+;; Representation of an inetd-style service.
+(define-record-type <inetd-service>
+  (inetd-service endpoints sockets)
+  inetd-service?
+  (endpoints   inetd-service-endpoints)
+  (sockets     inetd-service-sockets))
+
+(define-record-type-serializer (inetd-service->sexp (service <inetd-service>))
+  `(inetd-service (version 0)
+                  (endpoints
+                   ,(map endpoint->sexp (inetd-service-endpoints service)))
+                  (sockets
+                   ,(map fileno (inetd-service-sockets service)))))
+
 (define* (make-inetd-forkexec-constructor command connection
                                           #:key
                                           (user #f)
@@ -2307,12 +2332,12 @@ rejecting connection from ~:[~a~;~*local process~].")
                    (accept-clients (endpoint-address endpoint)
                                    socket)))
                 endpoints sockets)
-      sockets)))
+      (inetd-service endpoints sockets))))
 
 (define (make-inetd-destructor)
   "Return a procedure that terminates an inetd service."
-  (lambda (sockets)
-    (for-each close-port sockets)
+  (lambda (service)
+    (for-each close-port (inetd-service-sockets service))
     #f))
 
 



reply via email to

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