tests/qtest: boot-serial-test: Close the serial file before starting QEMU
authorBin Meng <bin.meng@windriver.com>
Tue, 27 Sep 2022 11:06:17 +0000 (19:06 +0800)
committerThomas Huth <thuth@redhat.com>
Tue, 27 Sep 2022 18:51:21 +0000 (20:51 +0200)
commit65a2eff0f53871166dee6767494f0cc6ffbf4a14
treece1eb4e24f89d65f2cb5565352b642ecffd08903
parente6efe236c1d1f2451d59a7151c50d1c79360857c
tests/qtest: boot-serial-test: Close the serial file before starting QEMU

This qtest executable created a serial chardev file to be passed to
the QEMU executable. The serial file was created by g_file_open_tmp(),
which internally opens the file with FILE_SHARE_WRITE security attribute
on Windows. Based on [1], there is only one case that allows the first
call to CreateFile() with GENERIC_READ & FILE_SHARE_WRITE, and second
call to CreateFile() with GENERIC_WRITE & FILE_SHARE_READ. All other
combinations require FILE_SHARE_WRITE in the second call. But there is
no way for the second call (in this case the QEMU executable) to know
what combination was passed to the first call, unless FILE_SHARE_WRITE
is passed to the second call.

Two processes shouldn't share the same file for writing with a chardev.
Let's close the serial file before starting QEMU.

[1] https://docs.microsoft.com/en-us/windows/win32/fileio/creating-and-opening-files

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Message-Id: <20220927110632.1973965-40-bmeng.cn@gmail.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
tests/qtest/boot-serial-test.c