Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ asdf_standard_dir = $(abs_top_srcdir)/asdf-standard
asdf_standard_submodule = $(asdf_standard_dir)/.git
munit_dir = $(top_builddir)/tests/munit
munit_submodule = $(munit_dir)/.git
munit_cflags = -std=c11 -I$(top_srcdir)/tests
munit_cflags = -std=gnu11 -I$(top_srcdir)/tests
munit_ldflags = $(builddir)/libmunit.a
submodules = $(asdf_standard_submodule) $(munit_submodule)

Expand Down
19 changes: 14 additions & 5 deletions tests/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ static void pioneer_setup(int fd_create, const char *pgid_file) {

/* Reuse the previous run directory if it is still empty. */
if (try_reuse_latest(serial_str)) {
(void)write(fd_create, serial_str, strlen(serial_str));
if (write(fd_create, serial_str, strlen(serial_str)) < 0)
goto failure;
close(fd_create);
return;
}
Expand All @@ -249,20 +250,28 @@ static void pioneer_setup(int fd_create, const char *pgid_file) {
if (n < 0 || n >= (int)sizeof(run_dir_storage))
break;
if (mkdir(run_dir_storage, 0777) == 0) {
snprintf(serial_str, sizeof(serial_str), TEST_SERIAL_FMT, run_num);
(void)write(fd_create, serial_str, strlen(serial_str));
/* Use a larger buffer to avoid format-truncation: run_num is
* bounded by TEST_SERIAL_MAX (1000000) so the output is always
* TEST_SERIAL_LEN digits, but GCC sees the full int range. */
char serial_buf[32];
snprintf(serial_buf, sizeof(serial_buf), TEST_SERIAL_FMT, run_num);
memcpy(serial_str, serial_buf, TEST_SERIAL_LEN + 1);
if (write(fd_create, serial_str, strlen(serial_str)) < 0)
goto failure;
close(fd_create);
char latest[PATH_MAX];
snprintf(latest, sizeof(latest), TEMP_DIR "/latest");
unlink(latest);
symlink(serial_str, latest); /* best-effort */
int rc = symlink(serial_str, latest); /* best-effort */
(void)rc;
return;
}
if (errno != EEXIST)
break;
}

/* Failed to create a run directory; clean up and fall back. */
failure:
/* Failed to create a run directory or write the serial; clean up. */
run_dir_storage[0] = '\0';
close(fd_create);
unlink(pgid_file);
Expand Down
Loading