Re: [PATCH 2/3] Add /dev/fd and /dev/std*

Alyssa Ross
2025-09-17T11:29:39Z

[-- Attachment #1: Type: text/plain, Size: 3208 bytes --]

Demi Marie Obenour <demiobenour@gmail.com> writes:

> 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.

s6-linux-init is certainly designed to be run before these links exist,
so I don't think we need them in init. I'd rather keep setup in a
single place as much as possibl,e and that's rc.init.

> 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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 227 bytes --]