diff --git a/src/client/dfuse/pil4dfs/int_dfs.c b/src/client/dfuse/pil4dfs/int_dfs.c index a7e835d278f..492b7710bc1 100644 --- a/src/client/dfuse/pil4dfs/int_dfs.c +++ b/src/client/dfuse/pil4dfs/int_dfs.c @@ -5859,8 +5859,10 @@ utimens_timespec(const char *path, const struct timespec times[2], int flags) int utimensat(int dirfd, const char *path, const struct timespec times[2], int flags) { - int idx_dfs, error = 0, rc; - char *full_path = NULL; + int idx_dfs, error = 0, rc; + char *full_path = NULL; + struct timespec times_loc[2]; + struct timespec *times_ptr; if (next_utimensat == NULL) { next_utimensat = dlsym(RTLD_NEXT, "utimensat"); @@ -5878,18 +5880,30 @@ utimensat(int dirfd, const char *path, const struct timespec times[2], int flags } _Pragma("GCC diagnostic pop") + /* clang-format off */ + + if (times == NULL) { + clock_gettime(CLOCK_REALTIME, ×_loc[0]); + times_loc[1].tv_sec = times_loc[0].tv_sec; + times_loc[1].tv_nsec = times_loc[0].tv_nsec; + times_ptr = times_loc; + } else { + times_ptr = (struct timespec *)times; + } + /* clang-format on */ + /* absolute path, dirfd is ignored */ if (path[0] == '/') - return utimens_timespec(path, times, flags); + return utimens_timespec(path, times_ptr, flags); idx_dfs = check_path_with_dirfd(dirfd, &full_path, path, &error); if (error) goto out_err; if (idx_dfs >= 0) - rc = utimens_timespec(full_path, times, flags); + rc = utimens_timespec(full_path, times_ptr, flags); else - rc = next_utimensat(dirfd, path, times, flags); + rc = next_utimensat(dirfd, path, times_ptr, flags); error = errno; if (full_path) { diff --git a/src/tests/suite/dfuse_test.c b/src/tests/suite/dfuse_test.c index 0c53d1f322c..632acf801dc 100644 --- a/src/tests/suite/dfuse_test.c +++ b/src/tests/suite/dfuse_test.c @@ -1,5 +1,6 @@ /** * (C) Copyright 2021-2024 Intel Corporation. + * (C) Copyright 2026 Hewlett Packard Enterprise Development LP * * SPDX-License-Identifier: BSD-2-Clause-Patent */ @@ -516,6 +517,15 @@ do_mtime(void **state) rc = close(fd); assert_return_code(rc, errno); + usleep(10000); + prev_ts.tv_sec = stbuf.st_mtim.tv_sec; + prev_ts.tv_nsec = stbuf.st_mtim.tv_nsec; + rc = utimensat(root, "mtime_file", NULL, 0); + assert_return_code(rc, errno); + rc = fstatat(root, "mtime_file", &stbuf, 0); + assert_return_code(rc, errno); + assert_true(timespec_gt(stbuf.st_mtim, prev_ts)); + rc = unlinkat(root, "mtime_file", 0); assert_return_code(rc, errno);