Subject: bug#41855: [PATCH 1/2] hurd-boot: Create individual translators instead of running MAKEDEV.

From: Ludovic Courtès <[email-masked]>
Date: Mon, 15 Jun 2020 21:54:52 +0200

Hi!

"Jan (janneke) Nieuwenhuizen" <[email-masked]> skribis:

> * gnu/build/hurd-boot.scm (make-hurd-device-nodes): Do not create
> dev/{null,zero,full,random,urandom} mount points.
> (setup-translator, xattr-translator,
> showtrans-translator?, translated?, set-hurd-device-translators): New
> procedures.
> (boot-hurd-system): Use them instead of running MAKEDEV.

This is mostly about moving the logic from the MAKEDEV script to this
file, right?  Sounds nice.

> +(define (xattr-translator? file-name)
> +  "Return true if FILE-NAME has an extended @code{gnu.translator} attribute
> +set."
> +  (false-if-exception
> +   (not (string-null? (getxattr file-name "gnu.translator")))))

I’d call it ‘passive-translator-xattr?’.

In general, I’d avoid ‘false-if-exception’ as much as possible because
it can hide real issues.  So here, you could catch 'system-error and
check for ENODATA.  If you need it in several places, you can define a
‘false-if-ENODATA’ macro

> +(define (showtrans-translator? file-name)
> +  "Return true if @file{showtrans} finds a translator installed on FILE-NAME."

Should be ‘passive-translator-installed?’ no?  (IIRC ‘showtrans’ only
shows passive translator settings by default.)

> +  (with-output-to-port (%make-void-port "w")
> +    (lambda _
> +      (with-error-to-port (%make-void-port "w")
> +        (lambda _
> +          (zero? (system* "showtrans" "--silent" file-name)))))))
> +
> +(define (translated? file-name)
> +  "Return true if a translator is installed on FILE-NAME."
> +  (if (string-contains %host-type "linux-gnu")
> +      (xattr-translator? file-name)
> +      (showtrans-translator? file-name)))

It’s counter-intuitive that hurd-boot.scm is used from GNU/Linux.
Should we move the shared bits in (gnu build hurd) or similar?

> +(define* (setup-translator file-name command #:optional (mode #o600))
> +  "Setup translator COMMAND on FILE-NAME."

‘set-translator’?  :-)

> +  (false-if-exception (mkdir-p (scope "dev/vcs/1")))
> +  (false-if-exception (mkdir-p (scope "dev/vcs/2")))
> +  (false-if-exception (mkdir-p (scope "dev/vcs/3")))
> +  (false-if-exception (rename-file "/dev/console" "/dev/console-"))
> +  (for-each scope-setup-translator devices)
> +
> +  (false-if-exception (symlink "/dev/random" "/dev/urandom"))
> +  (false-if-exception (mkdir-p "/dev/fd"))
> +  (false-if-exception (symlink "/dev/fd/0"   "/dev/stdin"))
> +  (false-if-exception (symlink "/dev/fd/1"   "/dev/stdout"))
> +  (false-if-exception (symlink "/dev/fd/2"   "/dev/stderr")))

‘false-if-EEXIST’?

Thanks!

Ludo’.