guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#30216] [WIP v5] services: agetty: Make tty optional.


From: Ludovic Courtès
Subject: [bug#30216] [WIP v5] services: agetty: Make tty optional.
Date: Tue, 30 Jan 2018 21:56:37 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)

Hi,

Danny Milosavljevic <address@hidden> skribis:

> * gnu/system/install.scm (agetty-default-service): Delete variable.
> (beaglebone-black-installation-os): Do not specify tty.
> (a20-olinuxino-lime-installation-os): Do not specify tty.
> (a20-olinuxino-lime2-emmc-installation-os): Do not specify tty.
> (a20-olinuxino-micro-installation-os): Do not specify tty.
> (banana-pi-m2-ultra-installation-os): Do not specify tty.
> (nintendo-nes-classic-edition-installation-os): Do not specify tty.
> (embedded-installation-os): Move agetty-service instantiation to...
> * gnu/services/base.scm (%base-services): ...here.
> (default-tty): New variable.
> (agetty-shepherd-service): Make tty optional, default to the above.

Neat, it looks better than hardcoding a default tty for each of these
machines.  :-)

> +(define (default-tty)

Could you add a docstring, like, IIUC: “Return a gexp that determines a
reasonable default serial port to use as the tty.  This is primarily
useful for headless systems such as ARM SoCs.”

In the manual, for the agetty service, it would be good to document the
‘agetty.tty’ kernel command-line option.

Perhaps ‘default-serial-port’ is more appropriate in fact?

> +  #~(begin
> +      ;; console=device,options
> +      ;; device: can be tty0, ttyS0, lp0, ttyUSB0 (serial).
> +      ;; options: BBBBPNF. P n|o|e, N number of bits,
> +      ;; F flow control (r RTS)
> +      (use-modules (rnrs io ports))
> +      (let* ((command (call-with-input-file "/proc/cmdline" get-string-all))
> +             (not-comma (char-set-complement (char-set #\,)))
> +             (items (string-tokenize command))
> +             (items-by-key (lambda (key target-prefix)
> +                            (let ((keylen (string-length key)))
> +                              (map (lambda (a)
> +                                     (string-append target-prefix
> +                                                    (string-drop a keylen)))
> +                                   (filter (lambda (b)
> +                                             (string-prefix? key b)) 
> items)))))
> +             (agetty-ttys (items-by-key "agetty.tty=" ""))

Rather use ‘linux-command-line’ from (gnu build linux-boot).
‘find-long-option’ in the same module does almost what you want, but if
you really want to support repeated “agetty.tty” options, you’ll have to
make a new ‘find-long-options’ (plural) variant.

> +             (console-ttys (filter (lambda (tty)
> +                                     (not (or
> +                                            (string-prefix? tty "tty0")
> +                                            (string-prefix? tty "tty1")
> +                                            (string-prefix? tty "tty2")
> +                                            (string-prefix? tty "tty3")
> +                                            (string-prefix? tty "tty4")
> +                                            (string-prefix? tty "tty5")
> +                                            (string-prefix? tty "tty6")
> +                                            (string-prefix? tty "tty7")
> +                                            (string-prefix? tty "tty8")
> +                                            (string-prefix? tty "tty9"))))
> +                                   (items-by-key "console=tty" "tty")))

I think this would work:

  (let* ((consoles     (find-long-option "console" (linux-command-line)))
         (console-ttys (remove (lambda (console)
                                 (string-prefix? "tty" console))
                               (string-tokenize consoles not-comma))))
    …)

> +             (ttys (or agetty-ttys (map (lambda (console-spec)
> +                                          ;; Extract device name.
> +                                          (car (string-tokenize console-spec
> +                                                                not-comma)))
> +                                        console-ttys))))
> +        (if (null? ttys)
> +          "XXX" ; would crash entire boot process: (error "agetty: No 
> default tty found.")
> +          (car ttys)))))

Maybe default to /dev/ttyS0?

Could you send an updated patch?

Thanks,
Ludo’.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]