build_library/qemu_template.sh: use POSIX kill -0 for swtpm cleanup watcher for macOS+linux portability - #4232
Conversation
Signed-off-by: shipitdev <harshsinghrajpoot07@gmail.com>
888caf8 to
df548fe
Compare
chewi
left a comment
There was a problem hiding this comment.
The fix looks fine, although when I try it on a Mac myself, QEMU dies immediately with this:
qemu-system-aarch64: -device tpm-tis-device,tpmdev=tpm0: Error: ret = HV_BAD_ARGUMENT (0xfae94003, at ../accel/hvf/hvf-all.c:123)
I guess you didn't hit that.
Ah yeah, I ran into that! With all the different Apple Silicon HVF quirks popping up, I didn't want to flood you with a whole laundry list of issues on day one lol, so I kept the scope of this PR strictly focused on fixing the swtpm daemon watcher and /proc portability. i'm not sure where to proceed from here though Would you like me to add a quick note to the PR description mentioning the limitation or something ? Although it looks like another upstream QEMU issue with tpm-tis-device under HVF. i'm gonna have a look at it later today |
|
It's fine, we can just take this now, especially if it's just an upstream issue. Most users don't need a TPM anyway. |
Description
(reopening (#4231) since i deleted the head of the last fork)
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.