[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 05/10: system: Add 'pipe2' bindings.
From: |
Ludovic Courtès |
Subject: |
[shepherd] 05/10: system: Add 'pipe2' bindings. |
Date: |
Wed, 7 Sep 2022 17:19:10 -0400 (EDT) |
civodul pushed a commit to branch master
in repository shepherd.
commit 10c65fcf2b33dd3d20f5fe9fb9b31d5b4e66c644
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Wed Sep 7 15:31:09 2022 +0200
system: Add 'pipe2' bindings.
* modules/shepherd/system.scm.in (define-as-needed): New macro.
(pipe2): New procedure.
---
modules/shepherd/system.scm.in | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/modules/shepherd/system.scm.in b/modules/shepherd/system.scm.in
index 0978c18..48ca9db 100644
--- a/modules/shepherd/system.scm.in
+++ b/modules/shepherd/system.scm.in
@@ -33,6 +33,7 @@
PR_SET_CHILD_SUBREAPER
getpgid
ipv6-only
+ pipe2
SFD_CLOEXEC
signalfd
consume-signalfd-siginfo
@@ -152,6 +153,43 @@ only (by default, Linux binds AF_INET6 addresses on IPv4
as well)."
(setsockopt port @IPPROTO_IPV6@ @IPV6_V6ONLY@ 1)
port)
+(define-syntax define-as-needed ;copied from (guix build syscalls)
+ (syntax-rules ()
+ "Define VARIABLE. If VARIABLE already exists in (guile) then re-export it,
+ otherwise export the newly-defined VARIABLE."
+ ((_ (proc args ...) body ...)
+ (define-as-needed proc (lambda* (args ...) body ...)))
+ ((_ variable value)
+ (if (module-defined? the-scm-module 'variable)
+ (module-re-export! (current-module) '(variable))
+ (begin
+ (module-define! (current-module) 'variable value)
+ (module-export! (current-module) '(variable)))))))
+
+(define-as-needed pipe2
+ ;; Use 'define-as-needed' in case Guile > 3.0.8 comes with a same-named
+ ;; binding.
+ (let ((proc (syscall->procedure int "pipe2" `(* ,int))))
+ (lambda* (#:optional (flags 0))
+ "Return a newly created pipe: a pair of ports linked together on the
+local machine. The car is the input port, and the cdr is the output port.
+
+The difference compared to 'pipe' is that is the optional FLAGS argument."
+ (let* ((bv (make-bytevector (* (sizeof int) 2)))
+ (ptr (bytevector->pointer bv)))
+ (let-values (((result err) (proc ptr flags)))
+ (if (zero? result)
+ (let ((in (bytevector-sint-ref bv 0
+ (native-endianness)
+ (sizeof int)))
+ (out (bytevector-sint-ref bv (sizeof int)
+ (native-endianness)
+ (sizeof int))))
+ (cons (fdopen in "r") (fdopen out "w")))
+ (throw 'system-error "pipe2" "~A"
+ (list (strerror err))
+ (list err))))))))
+
(define (allocate-sigset)
(bytevector->pointer (make-bytevector @SIZEOF_SIGSET_T@)))
- [shepherd] branch master updated (5c3a618 -> 978e5b4), Ludovic Courtès, 2022/09/07
- [shepherd] 04/10: shepherd: Mark client connection sockets as SOCK_NONBLOCK., Ludovic Courtès, 2022/09/07
- [shepherd] 07/10: service: Mark systemd listening sockets as SOCK_CLOEXEC., Ludovic Courtès, 2022/09/07
- [shepherd] 01/10: doc: Update inetd service example., Ludovic Courtès, 2022/09/07
- [shepherd] 09/10: shepherd: Upon startup, mark preexisting file descriptors as FD_CLOEXEC., Ludovic Courtès, 2022/09/07
- [shepherd] 10/10: shepherd: Add test ensuring proper use of close-on-exec., Ludovic Courtès, 2022/09/07
- [shepherd] 02/10: shepherd: Open listening socket as SOCK_NONBLOCK., Ludovic Courtès, 2022/09/07
- [shepherd] 03/10: shepherd: Mark client connection sockets as SOCK_CLOEXEC., Ludovic Courtès, 2022/09/07
- [shepherd] 05/10: system: Add 'pipe2' bindings.,
Ludovic Courtès <=
- [shepherd] 06/10: service: Mark service logging pipe as O_CLOEXEC., Ludovic Courtès, 2022/09/07
- [shepherd] 08/10: service: Mark inetd connection sockets as SOCK_CLOEXEC., Ludovic Courtès, 2022/09/07