guix-patches
[Top][All Lists]
Advanced

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

[bug#54986] [PATCH v3 1/2] services: shepherd: Add support for socket ac


From: Liliana Marie Prikler
Subject: [bug#54986] [PATCH v3 1/2] services: shepherd: Add support for socket activation endpoints.
Date: Sat, 10 Sep 2022 18:32:03 -0000

* gnu/services/shepherd.scm (<shepherd-endpoint>): New record type.
(shepherd-endpoint->sexp): New variable.
* doc/guix.texi (Shepherd Services): Document it.
---
 doc/guix.texi             | 32 ++++++++++++++++++++
 gnu/services/shepherd.scm | 64 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+)

diff --git a/doc/guix.texi b/doc/guix.texi
index c21235f28d..30cc3b6d45 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -39332,6 +39332,38 @@ This, as you can see, is a fairly sophisticated way to 
say hello.
 info on actions.
 @end deftp
 
+@deftp {Data Type} shepherd-endpoint
+This data type represents an endpoint for inetd-style and systemd-style
+services.  Its fields reflect the arguments to shepherd's
+@code{endpoint} procedure.
+
+@table @code
+@item address
+The socket address to bind via shepherd and forward to the service.
+
+@item name
+A ``descriptive'' name to forward to the service along with the socket.
+
+@item style
+The socket style to use.
+@xref{Network Sockets and Communication,,, guile, GNU Guile Reference
+Manual}.
+
+@item backlog
+The maximum length of the queue for pending connections.
+
+@item socket-owner
+The user ID owning the socket.
+
+@item socket-group
+The group ID owning the socket.
+
+@item socket-directory-permissions
+The UNIX permissions to set for the directory the socket resides in.
+
+@end table
+@end deftp
+
 @defvr {Scheme Variable} shepherd-root-service-type
 The service type for the Shepherd ``root service''---i.e., PID@tie{}1.
 
diff --git a/gnu/services/shepherd.scm b/gnu/services/shepherd.scm
index 4fd4b2a497..f0d204ff3a 100644
--- a/gnu/services/shepherd.scm
+++ b/gnu/services/shepherd.scm
@@ -66,6 +66,17 @@ (define-module (gnu services shepherd)
             shepherd-action-documentation
             shepherd-action-procedure
 
+            shepherd-endpoint
+            shepherd-endpoint?
+            shepherd-endpoint-address
+            shepherd-endpoint-name
+            shepherd-endpoint-style
+            shepherd-endpoint-backlog
+            shepherd-endpoint-socket-owner
+            shepherd-endpoint-socket-group
+            shepherd-endpoint-socket-directory-permissions
+            shepherd-endpoint->sexp
+
             %default-modules
 
             shepherd-service-file
@@ -183,6 +194,59 @@ (define %default-modules
     ((guix build utils) #:hide (delete))
     (guix build syscalls)))
 
+(define-record-type* <shepherd-endpoint>
+  shepherd-endpoint make-shepherd-endpoint
+  shepherd-endpoint?
+  (address                      shepherd-endpoint-address)      ; sockaddr
+  (name                         shepherd-endpoint-name          ; string | #f
+                                (default #f))
+  (style                        shepherd-endpoint-style         ; int | #f
+                                (default #f))
+  (backlog                      shepherd-endpoint-backlog       ; int | #f
+                                (default #f))
+  (socket-owner                 shepherd-endpoint-socket-owner  ; uid | #f
+                                (default #f))
+  (socket-group                 shepherd-endpoint-socket-group  ; gid | #f
+                                (default #f))
+  (socket-directory-permissions
+   shepherd-endpoint-socket-directory-permissions ; chmod pattern (int) | #f
+   (default #f)))
+
+(define (shepherd-endpoint->sexp endpoint)
+  (match endpoint
+    (($ <shepherd-endpoint> address
+                            name style backlog socket-owner socket-group
+                            socket-directory-permissions)
+     `(endpoint
+       ,(match (sockaddr:fam address)
+          ((? (cute = <> AF_INET) _)
+           `((@ (guile) make-socket-addr)
+             AF_INET
+             ,(sockaddr:addr address)
+             ,(sockaddr:port address)))
+          ((? (cute = <> AF_INET6) _)
+           `((@ (guile) make-socket-addr)
+             AF_INET6
+             ,(sockaddr:addr address)
+             ,(sockaddr:port address)
+             ,(sockaddr:flowinfo address)
+             ,(sockaddr:scopeid address)))
+          ((? (cute = <> AF_UNIX) _)
+           `((@ (guile) make-socket-addr)
+             AF_UNIX
+             ,(sockaddr:path address))))
+       ,@(fold
+          (match-lambda*
+            (((key value) seed)
+             (if value (cons* key value seed) seed)))
+          '()
+          `((#:name ,name)
+            (#:style ,style)
+            (#:backlog ,backlog)
+            (#:socket-owner ,socket-owner)
+            (#:socket-group ,socket-group)
+            (#:socket-directory-permissions 
,socket-directory-permissions)))))))
+
 (define-record-type* <shepherd-service>
   shepherd-service make-shepherd-service
   shepherd-service?
-- 
2.37.3






reply via email to

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