mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-10 11:04:58 -06:00
tests/qtest: pflash-cfi02-test: Avoid using hardcoded /tmp
This case was written to use hardcoded /tmp directory for temporary files. Update to use g_file_open_tmp() for a portable implementation. Signed-off-by: Bin Meng <bin.meng@windriver.com> Message-Id: <20220927110632.1973965-16-bmeng.cn@gmail.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
This commit is contained in:
parent
52ca92d6d7
commit
8189b27d3b
1 changed files with 7 additions and 8 deletions
|
@ -56,7 +56,7 @@ typedef struct {
|
||||||
QTestState *qtest;
|
QTestState *qtest;
|
||||||
} FlashConfig;
|
} FlashConfig;
|
||||||
|
|
||||||
static char image_path[] = "/tmp/qtest.XXXXXX";
|
static char *image_path;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The pflash implementation allows some parameters to be unspecified. We want
|
* The pflash implementation allows some parameters to be unspecified. We want
|
||||||
|
@ -608,6 +608,7 @@ static void test_cfi_in_autoselect(const void *opaque)
|
||||||
static void cleanup(void *opaque)
|
static void cleanup(void *opaque)
|
||||||
{
|
{
|
||||||
unlink(image_path);
|
unlink(image_path);
|
||||||
|
g_free(image_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -635,16 +636,14 @@ static const FlashConfig configuration[] = {
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int fd = mkstemp(image_path);
|
GError *err = NULL;
|
||||||
if (fd == -1) {
|
int fd = g_file_open_tmp("qtest.XXXXXX", &image_path, &err);
|
||||||
g_printerr("Failed to create temporary file %s: %s\n", image_path,
|
g_assert_no_error(err);
|
||||||
strerror(errno));
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
if (ftruncate(fd, UNIFORM_FLASH_SIZE) < 0) {
|
if (ftruncate(fd, UNIFORM_FLASH_SIZE) < 0) {
|
||||||
int error_code = errno;
|
int error_code = errno;
|
||||||
close(fd);
|
close(fd);
|
||||||
unlink(image_path);
|
cleanup(NULL);
|
||||||
g_printerr("Failed to truncate file %s to %u MB: %s\n", image_path,
|
g_printerr("Failed to truncate file %s to %u MB: %s\n", image_path,
|
||||||
UNIFORM_FLASH_SIZE, strerror(error_code));
|
UNIFORM_FLASH_SIZE, strerror(error_code));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue