civodul pushed a commit to branch master
in repository guix.

commit 3aa132e8c30658019281d51caa28b0fb41bab24d
Author: Ludovic Courtès <l...@gnu.org>
AuthorDate: Tue Apr 8 08:37:04 2025 +0200

    syscalls: Add ‘get-user-ns’.
    
    * guix/build/syscalls.scm (NS_GET_USERNS): New variable.
    (get-user-ns): New procedure.
    
    Change-Id: I0cfba6a7cdf2ab64ef658b0f821ba4e7c6c89eab
---
 guix/build/syscalls.scm | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index cf09cae3a4..9c64b40d77 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -147,6 +147,7 @@
             clone
             unshare
             setns
+            get-user-ns
 
             kexec-load-file
             KEXEC_FILE_UNLOAD
@@ -1247,6 +1248,19 @@ there is no such limitation."
                   (list fdes nstype (strerror err))
                   (list err))))))))
 
+(define NS_GET_USERNS #xb701)
+
+(define (get-user-ns fdes)
+  "Return an open file descriptor to the user namespace that owns the
+namespace pointed to by FDES, a file descriptor obtained by opening
+/proc/PID/ns/*."
+  (let-values (((ret err) (%ioctl fdes NS_GET_USERNS %null-pointer)))
+    (when (< ret 0)
+      (throw 'system-error "get-user-ns" "~d: ~A"
+             (list fdes (strerror err))
+             (list err)))
+    ret))
+
 (define pivot-root
   (let ((proc (syscall->procedure int "pivot_root" (list '* '*))))
     (lambda (new-root put-old)

Reply via email to