From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from atuin.qyliss.net (localhost [IPv6:::1]) by atuin.qyliss.net (Postfix) with ESMTP id 1F9C3D38C; Fri, 13 Jun 2025 14:05:36 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 993) id 2E0F6D2A1; Fri, 13 Jun 2025 14:05:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on atuin.qyliss.net X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DMARC_MISSING,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=4.0.1 Received: from fhigh-a3-smtp.messagingengine.com (fhigh-a3-smtp.messagingengine.com [103.168.172.154]) by atuin.qyliss.net (Postfix) with ESMTPS id 5CA5AD294 for ; Fri, 13 Jun 2025 14:05:26 +0000 (UTC) Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfhigh.phl.internal (Postfix) with ESMTP id 6A96F1140147; Fri, 13 Jun 2025 10:05:23 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-10.internal (MEProxy); Fri, 13 Jun 2025 10:05:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alyssa.is; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1749823523; x= 1749909923; bh=BggqNnizQm6L70QNC7pyqQrZFvQB1DE4uP9dDckhb5Q=; b=G V1+NKxtxHAnLLxOZkDd1+lTmD6nBdrxsp4yHnaIoo5+b1NAvuMFv1pETOWia78Bg OLduB9pvldR9oEL6SMiP1hFohIktzhb9jkzSY4jhkecv8wPRaDSQ8EW0tKr9KZ2f pYpz39V9USSPX4Hpsp4fvzJjq7TLhaLVyUuXk8sBPOILz9BMXfb3zLcRBRwG6AT2 7e0DsW+oBpLb8FOnmqKIQL2hyfHMrDmc0OXnE07Zz+lU0RfWBihXvzSvwfzKyGyE e6GKkJOcKHijRTKSw4JycEIDc2Bq+Meb6NrrBTrHrLJlCRALl2acdfLGiyiyl04U 9BgYQig89cLv55bPuXXeg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1749823523; x=1749909923; bh=B ggqNnizQm6L70QNC7pyqQrZFvQB1DE4uP9dDckhb5Q=; b=DotJ8EXS0ljwwZygS HOwuVb9hXtYycQa0pfqSgb0e6SMyYuLVbtPk/H/o+nH1tGvzUd1dKvm1ulNuixCY 7ypy8YAkB5elG8yMw7JOYJtTcDVHBe4Nb7hBMPYPdUPVjsEaD+TU6AZIr9oPc1rg SVLAfDUwBHiWPQPDVd2yuRXs5UuKUg6tnzLAhp+ilmsGrs8h7QqsNNEhnDBZUC0M qGUwqsRiL2tc605aqappkxxvzpIOzDPb3ekPsVuQtt9ymbOMZYrvBr/5KZJXmGLo 1YPSWpoNoWqEwb+vTgGRdH3jrBgbD+NYKKr374g3qQAdhdUGyn7IVRhRPGIkIdyD O4VnA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddugddukedugecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhephffvve fufffkofgjfhgggfestdekredtredttdenucfhrhhomheptehlhihsshgrucftohhsshcu oehhihesrghlhihsshgrrdhisheqnecuggftrfgrthhtvghrnhepgeeuieduueekkeeivd etffegkeduhfduvedvledvkefhfeeiteekuddujefffeegnecuvehluhhsthgvrhfuihii vgeptdenucfrrghrrghmpehmrghilhhfrhhomhephhhisegrlhihshhsrgdrihhspdhnsg gprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopeguvghvvghl sehsphgvtghtrhhumhdqohhsrdhorhhgpdhrtghpthhtohephihukhgrseihuhhkrgdrug gvvh X-ME-Proxy: Feedback-ID: i12284293:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 13 Jun 2025 10:05:22 -0400 (EDT) Received: by sf.qyliss.net (Postfix, from userid 1000) id BAD87245D66F9; Fri, 13 Jun 2025 16:05:20 +0200 (CEST) From: Alyssa Ross To: devel@spectrum-os.org Subject: [PATCH 1/8] host/rootfs: poll active consoles for serial getty Date: Fri, 13 Jun 2025 16:05:01 +0200 Message-ID: <20250613140508.76998-2-hi@alyssa.is> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250613140508.76998-1-hi@alyssa.is> References: <20250613140508.76998-1-hi@alyssa.is> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: AV66VZSYWDBRSEIW4DAKBWLNBJP45VD7 X-Message-ID-Hash: AV66VZSYWDBRSEIW4DAKBWLNBJP45VD7 X-MailFrom: hi@alyssa.is X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-devel.spectrum-os.org-0; header-match-devel.spectrum-os.org-1; header-match-devel.spectrum-os.org-2; header-match-devel.spectrum-os.org-3; header-match-devel.spectrum-os.org-4; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Yureka X-Mailman-Version: 3.3.9 Precedence: list List-Id: Patches and low-level development discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Previously, the active consoles were only checked once, so if a console appeared later, getty wouldn't be run for it. This meant that if the console was set to a serial device whose driver was not built-in, it might have no shell if the module was not loaded until after rc.init had already run. Also, if a console device was removed, its instance of the serial-getty would hang around. To fix this, replace the getty instantiation in rc.init with a service that will create and destroy serial-getty instances to match the currently configured consoles, which will rerun whenever the configured consoles change. Fixes: b096279 ("host/rootfs: run getty for active serial consoles") Signed-off-by: Alyssa Ross --- host/rootfs/Makefile | 1 + host/rootfs/default.nix | 8 ++-- .../service/serial-getty-generator/run | 43 +++++++++++++++++++ host/rootfs/etc/s6-linux-init/scripts/rc.init | 9 ---- 4 files changed, 48 insertions(+), 13 deletions(-) create mode 100755 host/rootfs/etc/s6-linux-init/run-image/service/serial-getty-generator/run diff --git a/host/rootfs/Makefile b/host/rootfs/Makefile index d54538b..d5b9b55 100644 --- a/host/rootfs/Makefile +++ b/host/rootfs/Makefile @@ -31,6 +31,7 @@ FILES = \ etc/s6-linux-init/run-image/service/getty-tty4/run \ etc/s6-linux-init/run-image/service/s6-svscan-log/notification-fd \ etc/s6-linux-init/run-image/service/s6-svscan-log/run \ + etc/s6-linux-init/run-image/service/serial-getty-generator/run \ etc/s6-linux-init/run-image/service/serial-getty/notification-fd \ etc/s6-linux-init/run-image/service/serial-getty/run \ etc/s6-linux-init/run-image/service/serial-getty/template/run \ diff --git a/host/rootfs/default.nix b/host/rootfs/default.nix index b50d090..bfc1ba8 100644 --- a/host/rootfs/default.nix +++ b/host/rootfs/default.nix @@ -9,8 +9,8 @@ pkgsStatic.callPackage ( { start-vmm , lib, stdenvNoCC, nixos, runCommand, writeClosure, erofs-utils, s6-rc , bcachefs-tools, busybox, cloud-hypervisor, cryptsetup, dbus, execline -, e2fsprogs, inkscape, jq, kmod, mdevd, s6, s6-linux-init, socat -, util-linuxMinimal, virtiofsd, xorg +, e2fsprogs, inkscape, inotify-tools, jq, kmod, mdevd, s6 +, s6-linux-init, socat, util-linuxMinimal, virtiofsd, xorg , xdg-desktop-portal-spectrum-host }: @@ -137,8 +137,8 @@ let foot = pkgsGui.foot.override { allowPgo = false; }; packages = [ - bcachefs-tools cloud-hypervisor dbus execline jq kmod mdevd s6 - s6-linux-init s6-rc socat start-vmm virtiofsd + bcachefs-tools cloud-hypervisor dbus execline inotify-tools jq + kmod mdevd s6 s6-linux-init s6-rc socat start-vmm virtiofsd xdg-desktop-portal-spectrum-host (cryptsetup.override { diff --git a/host/rootfs/etc/s6-linux-init/run-image/service/serial-getty-generator/run b/host/rootfs/etc/s6-linux-init/run-image/service/serial-getty-generator/run new file mode 100755 index 0000000..445604f --- /dev/null +++ b/host/rootfs/etc/s6-linux-init/run-image/service/serial-getty-generator/run @@ -0,0 +1,43 @@ +#!/bin/execlineb -P +# SPDX-License-Identifier: EUPL-1.2+ +# SPDX-FileCopyrightText: 2024-2025 Alyssa Ross + +piperw 3 4 +background { + fdclose 3 + fdmove 2 4 + inotifywait -e MODIFY /sys/class/tty/console/active +} +fdclose 4 +importas -i inotifywait_pid ! + +foreground { + if { fdmove 0 3 grep -qx "Watches established." } + background { fdmove 0 3 cat } + fdclose 3 + + # Wait until inotifywait is ready before updating serial gettys, + # so that changes won't be missed in between updating and starting + # inotifywait. + pipeline { s6-instance-list /run/service/serial-getty } + pipeline { sort } + fdmove -c 3 0 + + redirfd -r 0 /sys/class/tty/console/active + pipeline { tr " " "\n" } + pipeline { sort } + + pipeline { comm -3 - /proc/self/fd/3 } + forstdin -Ep line + case -N $line { + " ?tty[0-9]*" { } + " (.*)" { + importas -i tty 1 + s6-instance-delete /run/service/serial-getty $tty + } + } + s6-instance-create /run/service/serial-getty $line +} + +# Block until the active consoles change, then let s6 restart us. +wait -- $inotifywait_pid diff --git a/host/rootfs/etc/s6-linux-init/scripts/rc.init b/host/rootfs/etc/s6-linux-init/scripts/rc.init index c778714..674fd38 100755 --- a/host/rootfs/etc/s6-linux-init/scripts/rc.init +++ b/host/rootfs/etc/s6-linux-init/scripts/rc.init @@ -2,15 +2,6 @@ # SPDX-License-Identifier: EUPL-1.2+ # SPDX-FileCopyrightText: 2020-2022, 2024 Alyssa Ross -background { - redirfd -r 0 /sys/class/tty/console/active - withstdinas active - importas -isu active active - forx -po0 -E tty { $active } - case $tty { tty[0-9]* { } } - s6-instance-create /run/service/serial-getty $tty -} - if { s6-rc-init -c /etc/s6-rc /run/service } if { mount --make-shared /run } -- 2.49.0