Files
re:fi.64 35b818b901 run: Write to --instance-id-fd after the pid is written
In commit 21f413f1, flatpak_instance_new was changed to require the pid
file to be written in order to succeed. This causes problems when
calling Spawn with NOTIFY_START, however, because portal expects to be
able to call flatpak_instance_new once the instance ID is retrieved. As
per the comments in the code that writes said instance ID, the idea was
that the instance would be *usable* at the point where the write takes
place (hence it being positioned *after* saving `bwrapinfo.json`), so it
makes sense to now move the write to *after* after the pid file is
written.

Since the pid file write and the instance ID write now go hand-in-hand,
both actions now take place in a separate function, so the logic can be
in one place. Additionally, the write itself is migrated to
`glnx_loop_write`, to shorten the code.

Assisted-by: DeepSeek-V4.1-Flash
2026-10-10 22:43:46 +00:00

41 lines
1.3 KiB
Bash

#!/bin/bash
set -euo pipefail
# shellcheck source=tests/libtest.sh
. "$(dirname "$0")/libtest.sh"
skip_without_bwrap
skip_revokefs_without_fuse
setup_repo test
install_repo
# We can't pass fds via D-Bus over the socat intermediary, so instead use the
# presence of an output file as a marker of success.
run_with_sandboxed_bus "${test_builddir}/test-spawn" \
bash -c "echo ok > '${test_tmpdir}/spawn-output'" > spawn.out
assert_file_has_content spawn.out "spawn-exited.*status=0$"
assert_file_has_content "${test_tmpdir}/spawn-output" "ok"
ok "spawn"
# It's normal for SpawnStarted to *not* get emitted if the command exits too
# quickly, which means we wouldn't be able to check if we actually received it
# in this test. Thus, we have the test binary write to a FIFO upon receiving
# SpawnStarted, and the inner command will block on that FIFO before exiting.
mkfifo "${test_tmpdir}/spawn-started"
run_with_sandboxed_bus "${test_builddir}/test-spawn" \
--notify-start \
--write-after-start="${test_tmpdir}/spawn-started" \
bash -c "echo ok > '${test_tmpdir}/spawn-output-notify'; head -1 ${test_tmpdir}/spawn-started" > spawn.out
assert_file_has_content spawn.out "spawn-started"
assert_file_has_content spawn.out "spawn-exited.*status=0$"
assert_file_has_content "${test_tmpdir}/spawn-output-notify" "ok"
ok "spawn with notify-start"
done_testing