patches and low-level development discussion
 help / color / mirror / code / Atom feed
From: Demi Marie Obenour <demiobenour@gmail.com>
To: Spectrum OS Development <devel@spectrum-os.org>
Cc: Demi Marie Obenour <demiobenour@gmail.com>, Alyssa Ross <hi@alyssa.is>
Subject: [PATCH 2/3] Add /dev/fd and /dev/std*
Date: Sun, 14 Sep 2025 20:18:59 -0400	[thread overview]
Message-ID: <20250914-util-linux-switch-root-v1-2-9cf9349cbca3@gmail.com> (raw)
In-Reply-To: <20250914-util-linux-switch-root-v1-0-9cf9349cbca3@gmail.com>

This is nearly same as 14483e1a690c (img/app: add /dev/fd and /dev/std*),
but for the host and for vm/sys/net.  The only difference is that the
symlinks are created in init, rather than in rc.init.  This ensures that
nothing in the main system can run before they the links are created.

While only Spectrum-provided code should run in these VMs, third-party
dependencies are likely to only be tested in an environment where these
links are present.  Since the BSDs also have these links, some code
might even use them on purpose.

Not having these links could cause severe bugs.  For instance, if
/dev/stdout or /dev/stderr is missing, writing to them will create a
regular file instead.  This could cause other code to misbehave.
Furthermore, /dev is a devtmpfs, so this could consume a lot of memory.

In the host, the links are added in the main system, rather than in the
initramfs.  This is per Alyssa's suggestion in [1].

[1]: https://spectrum-os.org/lists/archives/spectrum-devel/87h5xdjo9p.fsf@alyssa.is/

Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
---
 host/rootfs/etc/init | 8 ++++++++
 vm/sys/net/etc/init  | 8 ++++++++
 2 files changed, 16 insertions(+)

diff --git a/host/rootfs/etc/init b/host/rootfs/etc/init
index 4085fa55545e7309004967e443e47fc2b82b0663..b6e6122ddb987a5463c0924cd56e1a26cf5bfd98 100755
--- a/host/rootfs/etc/init
+++ b/host/rootfs/etc/init
@@ -1,5 +1,13 @@
 #!/bin/execlineb -s0
 # SPDX-License-Identifier: EUPL-1.2+
 # SPDX-FileCopyrightText: 2022 Alyssa Ross <hi@alyssa.is>
+# Symlink creation (if it's copyrightable):
+# SPDX-License-Identifier: CC0-1.0
+# SPDX-FileCopyrightText: 2025 Demi Marie Obenour <demiobenour@gmail.com>
+
+/usr/bin/if { /usr/bin/ln -s /proc/self/fd /dev }
+/usr/bin/if { /usr/bin/ln -s /proc/self/fd/0 /dev/stdin }
+/usr/bin/if { /usr/bin/ln -s /proc/self/fd/1 /dev/stdout }
+/usr/bin/if { /usr/bin/ln -s /proc/self/fd/2 /dev/stderr }
 
 /bin/s6-linux-init -c /etc/s6-linux-init -s /run/param -- $@
diff --git a/vm/sys/net/etc/init b/vm/sys/net/etc/init
index 6424e221e0fb929e107271bd52b61706b9f1855e..de409e9296a24d42cef50605496efc520790559e 100755
--- a/vm/sys/net/etc/init
+++ b/vm/sys/net/etc/init
@@ -1,5 +1,13 @@
 #!/bin/execlineb -s0
 # SPDX-License-Identifier: EUPL-1.2+
 # SPDX-FileCopyrightText: 2022 Alyssa Ross <hi@alyssa.is>
+# Symlink creation (if it's copyrightable):
+# SPDX-License-Identifier: CC0-1.0
+# SPDX-FileCopyrightText: 2025 Demi Marie Obenour <demiobenour@gmail.com>
+
+/usr/bin/if { /usr/bin/ln -s /proc/self/fd /dev }
+/usr/bin/if { /usr/bin/ln -s /proc/self/fd/0 /dev/stdin }
+/usr/bin/if { /usr/bin/ln -s /proc/self/fd/1 /dev/stdout }
+/usr/bin/if { /usr/bin/ln -s /proc/self/fd/2 /dev/stderr }
 
 /bin/s6-linux-init -Bc /etc/s6-linux-init -- $@

-- 
2.51.0


  parent reply	other threads:[~2025-09-15  0:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-15  0:18 [PATCH 0/3] Minor improvements to the Spectrum OS boot process Demi Marie Obenour
2025-09-15  0:18 ` [PATCH 1/3] host/initramfs: Use util-linux switch_root Demi Marie Obenour
2025-09-17 11:44   ` Alyssa Ross
2025-09-18  2:39     ` Demi Marie Obenour
2025-09-19  9:12       ` Alyssa Ross
2025-09-18 19:41     ` Demi Marie Obenour
2025-09-15  0:18 ` Demi Marie Obenour [this message]
2025-09-17 11:29   ` [PATCH 2/3] Add /dev/fd and /dev/std* Alyssa Ross
2025-09-15  0:19 ` [PATCH 3/3] host/rootfs: Avoid redundant mounts of /proc and /sys Demi Marie Obenour
2025-09-17 11:31   ` Alyssa Ross
2025-09-18  2:42     ` Demi Marie Obenour
2025-09-19  9:16       ` Alyssa Ross
2025-09-18 19:45 ` [PATCH v2] Add /dev/fd and /dev/std* Demi Marie Obenour
2025-09-19  9:29   ` Alyssa Ross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250914-util-linux-switch-root-v1-2-9cf9349cbca3@gmail.com \
    --to=demiobenour@gmail.com \
    --cc=devel@spectrum-os.org \
    --cc=hi@alyssa.is \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).