build_library/qemu_template.sh: use POSIX kill -0 for swtpm cleanup watcher for macOS+linux portability - #4231
Open
shipitdev wants to merge 1 commit into
Open
Conversation
Signed-off-by: shipitdev <harshsinghrajpoot07@gmail.com>
shipitdev
force-pushed
the
fix/qemu-template-tpm-proc-cleanup
branch
from
August 20, 2026 18:26
faddd25 to
a9c8cbb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Use POSIX
kill -0forswtpmcleanup watcher to ensure cross-platform compatibilityIn
build_library/qemu_template.sh, the background monitor responsible for cleaning up theswtpmdaemon process checks for parent termination by probing the/procfilesystem:On macOS (Darwin), the /proc filesystem does not exist. Because of this,
[ -e "/proc/${PARENT}" ]immediately returns false in 0 seconds, which causes the watcher to kill swtpm before QEMU can connect to the socket. Running with software TPM (-T) on macOS immediately crashes withFailed to connect to TPM socket: Connection refused.Solution
Replace /proc/${PARENT} with the POSIX standard kill -0 "${PARENT}".
kill -0 checks if the parent process ID is alive without sending a terminating signal:
While the launcher script is running ➡️ kill -0 returns 0 (true) and keeps swtpm alive.
When the launcher script exits ➡️ kill -0 returns non-zero (false) and cleanly kills swtpm to avoid orphaned processes.
This makes the cleanup logic fully portable across Linux, macOS, and BSD.
How to use
Run the QEMU launcher with a TPM directory (-T):
Testing done
changelog/directory (user-facing change, bug fix, security fix, update)/bootand/usrsize, packages, list files for any missing binaries, kernel modules, config files, kernel modules, etc.