Subject: [bug#72395] [PATCH] syscalls: Support musl libc in openpty and login-tty

From: [email-masked]
Date: Wed, 31 Jul 2024 11:41:58 +0200

From: Sören Tempel <[email-masked]>

Contrary to glibc, musl does not define the openpty and login-tty
function in libutil.so. In fact, libutil.so does not exist on musl-based
Linux distributions.  Therefore, on musl-based systems we don't have
to pass any #:library keyword argument to syscall->procedure.
---
 guix/build/syscalls.scm | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index 39bcffd516..b92b6955a4 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -2382,8 +2382,10 @@ (define terminal-string-width
         string-length)))                      ;using a statically-linked Guile
 
 (define openpty
-  (let ((proc (syscall->procedure int "openpty" '(* * * * *)
-                                  #:library "libutil")))
+  (let ((proc (if musl-libc?
+                (syscall->procedure int "openpty" '(* * * * *)
+                                    #:library "libutil")
+                (syscall->procedure int "openpty" '(* * * * *)))))
     (lambda ()
       "Return two file descriptors: one for the pseudo-terminal control side,
 and one for the controlled side."
@@ -2404,8 +2406,10 @@ (define openpty
           (values (* head) (* inferior)))))))
 
 (define login-tty
-  (let* ((proc (syscall->procedure int "login_tty" (list int)
-                                   #:library "libutil")))
+  (let* ((proc (if musl-libc?
+                 (syscall->procedure int "login_tty" (list int)
+                                     #:library "libutil")
+                 (syscall->procedure int "login_tty" (list int)))))
     (lambda (fd)
       "Make FD the controlling terminal of the current process (with the
 TIOCSCTTY ioctl), redirect standard input, standard output and standard error

base-commit: 01d4363168ed10ea223047f7a7b83201f161ec0b