patches and low-level development discussion
 help / color / mirror / code / Atom feed
From: Demi Marie Obenour <demiobenour@gmail.com>
To: Alyssa Ross <hi@alyssa.is>, devel@spectrum-os.org
Subject: Re: [PATCH 3/3] host/rootfs: add run-flatpak script
Date: Fri, 14 Nov 2025 14:36:40 -0500	[thread overview]
Message-ID: <06f57b2f-97c7-42bf-97e1-a7abe4a5254d@gmail.com> (raw)
In-Reply-To: <20251113120452.65711-3-hi@alyssa.is>


[-- Attachment #1.1.1: Type: text/plain, Size: 4062 bytes --]

On 11/13/25 07:04, Alyssa Ross wrote:
> This is the entrypoint for running Flatpak applications.
> 
> It would be good to only add mounts for the VM in virtiofsd's mount
> namespace, so we don't need to do lots of manual unmounts, but that's
> a wider change affecting more than just Flatpak.
> 
> Signed-off-by: Alyssa Ross <hi@alyssa.is>
> ---
>  host/rootfs/file-list.mk              |  1 +
>  host/rootfs/image/usr/bin/run-flatpak | 56 +++++++++++++++++++++++++++
>  2 files changed, 57 insertions(+)
>  create mode 100755 host/rootfs/image/usr/bin/run-flatpak
> 
> diff --git a/host/rootfs/file-list.mk b/host/rootfs/file-list.mk
> index 9acaa1d..a796b90 100644
> --- a/host/rootfs/file-list.mk
> +++ b/host/rootfs/file-list.mk
> @@ -48,6 +48,7 @@ FILES = \
>  	image/usr/bin/assign-devices \
>  	image/usr/bin/create-vm-dependencies \
>  	image/usr/bin/run-appimage \
> +	image/usr/bin/run-flatpak \
>  	image/usr/bin/run-vmm \
>  	image/usr/bin/vm-console \
>  	image/usr/bin/vm-import \
> diff --git a/host/rootfs/image/usr/bin/run-flatpak b/host/rootfs/image/usr/bin/run-flatpak
> new file mode 100755
> index 0000000..39ee17b
> --- /dev/null
> +++ b/host/rootfs/image/usr/bin/run-flatpak
> @@ -0,0 +1,56 @@
> +#!/bin/execlineb -S2

Missing -W?

> +# SPDX-License-Identifier: EUPL-1.2+
> +# SPDX-FileCopyrightText: 2024 Alyssa Ross <hi@alyssa.is>
> +
> +backtick -E dir { mktemp -d /run/vm/by-id/XXXXXX }
> +backtick -E id { basename -- $dir }

Serial substitution: if $1 or $2 contains something like ${dir} or ${id}
they will be expanded again.  Can be avoided with multisubstitute:

backtick dir { mktemp -d /run/vm/by-id/XXXXXX }
backtick id { importas -iS dir basename -- $dir }
multisubstitute {
   import -iS dir
   import -iS id
   define install_dir $1
   define app_id $2
}

The general rule I follow is to never substitute a parameter into
an argv that has already been substituted into.  This can be done
by renaming all "variables" whenever one does a substitution.

> +if { mkdir -p /run/configs/${id}/fs }
> +if { redirfd -w 1 /run/configs/${id}/fs/type echo flatpak }
> +if { cd /run/configs/${id}/fs mount-flatpak $1 $2 }
> +if {
> +  ln -s /usr/lib/spectrum/img/appvm/blk /usr/lib/spectrum/img/appvm/vmlinux
> +    /run/configs/${id}
> +}
> +
> +if { ln -s /run/configs/${id} ${dir}/config }
> +
> +if { create-vm-dependencies $id }
> +
> +piperw 4 3
> +background {
> +  fdclose 3
> +  fdmove 0 4
> +
> +  # Wait for the VMM to be up, then start the VM.
> +  if { redirfd -w 1 /dev/null head -1 }
> +  vm-start $id
> +}
> +fdclose 4
> +
> +foreground { run-vmm $id }
> +fdclose 3
> +
> +if {
> +  forx -pE service {
> +    dbus
> +    vhost-user-fs
> +    vhost-user-gpu
> +    xdg-desktop-portal-spectrum-host
> +  }
> +  s6-instance-delete /run/service/${service} $id
> +}

Serial substitution again.  This should not be an issue: POSIX requires
mktemp to use only characters in the portable filename character set,
and $ is not in that set.  An execline static analyzer would flag
this, though.

If you want to avoid serial substitution, the usual workaround of
multisubstitute should do the job.

In the future, it would be best to run all of these services in their
own PID namespace, so after exit() they get destroyed by the kernel.
Essentially, every VM should be run inside a container.

This might also be one of the reasons that s6 isn't an ideal fit for
some of the future improvements I'd like to make.  Those require a
super-simple container manager, and s6 definitely isn't one.

> +if {
> +  elglob -0 flatpak_dir_mounts /run/configs/${id}/fs/flatpak/*/*/*/*/*

That's a lot of subdirectories!

> +  forx -E mount {
> +    ${dir}/fs/doc
> +    /run/configs/${id}/fs/flatpak/repo/config
> +    $flatpak_dir_mounts
> +    /run/configs/${id}/fs/flatpak
> +    ${dir}/fs/config
> +  }
> +  umount $mount
> +}
> +
> +rm -r $dir /run/configs/${id}
-- 
Sincerely,
Demi Marie Obenour (she/her/hers)

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 7253 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2025-11-14 19:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-13 12:04 [PATCH 1/3] tools/mount-flatpak: init Alyssa Ross
2025-11-13 12:04 ` [PATCH 2/3] img/app: run Flatpak applications Alyssa Ross
2025-11-13 12:04 ` [PATCH 3/3] host/rootfs: add run-flatpak script Alyssa Ross
2025-11-14 19:36   ` Demi Marie Obenour [this message]
2025-11-24 15:25     ` Alyssa Ross
2025-11-13 19:25 ` [PATCH 1/3] tools/mount-flatpak: init Demi Marie Obenour
2025-11-14 11:12   ` Alyssa Ross
2025-11-14 22:52     ` Demi Marie Obenour
2025-11-15 12:00       ` Alyssa Ross
2025-11-15 12:01         ` Alyssa Ross
2025-11-18  1:37         ` Demi Marie Obenour
2025-11-14 19:11 ` Demi Marie Obenour

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=06f57b2f-97c7-42bf-97e1-a7abe4a5254d@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).