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

Previous Next

Package: guix-patches;

Reported by: soeren <at> soeren-tempel.net

Date: Wed, 31 Jul 2024 09:44:02 UTC

Severity: normal

Tags: patch

Full log


Message #8 received at 72395 <at> debbugs.gnu.org (full text, mbox):

From: Z572 <zhengjunjie <at> iscas.ac.cn>
To: soeren <at> soeren-tempel.net
Cc: dev <at> jpoiret.xyz, me <at> tobias.gr, zimon.toutoune <at> gmail.com, othacehe <at> gnu.org,
 ludo <at> gnu.org, 72395 <at> debbugs.gnu.org, guix <at> cbaines.net
Subject: Re: [bug#72395] [PATCH] syscalls: Support musl libc in openpty and
 login-tty
Date: Fri, 02 Aug 2024 00:03:29 +0800
[Message part 1 (text/plain, inline)]
soeren <at> soeren-tempel.net writes:

> From: Sören Tempel <soeren <at> soeren-tempel.net>
>
> 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

see syscall->procedure definition:

```
(define* (syscall->procedure return-type name argument-types
                             #:key library)
  "Return a procedure that wraps the C function NAME using the dynamic FFI,
and that returns two values: NAME's return value, and errno.  When LIBRARY is
specified, look up NAME in that library rather than in the global symbol name
space.

If an error occurs while creating the binding, defer the error report until
the returned procedure is called."
  (catch #t
    (lambda ()
      ;; Note: When #:library is set, try it first and fall back to libc
      ;; proper.  This is because libraries like libutil.so have been subsumed
      ;; by libc.so with glibc >= 2.34.
      (let ((ptr (dynamic-func name
                               (if library
                                   (or (false-if-exception
                                        (dynamic-link library))
                                       (dynamic-link))
                                   (dynamic-link)))))
        ;; The #:return-errno? facility was introduced in Guile 2.0.12.
        (pointer->procedure return-type ptr argument-types
                            #:return-errno? #t)))
    (lambda args
      (lambda _
        (throw 'system-error name  "~A" (list (strerror ENOSYS))
               (list ENOSYS))))))
```

In my understanding, when we can't find libutil, will try to find it in
libc. Do you have any problems using it?
[signature.asc (application/pgp-signature, inline)]

This bug report was last modified 315 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.