From: Mike Yuan Date: Mon, 29 Apr 2024 08:22:37 +0000 (+0800) Subject: fs-util: try AT_EMPTY_PATH first for futimens_opath X-Git-Tag: v256-rc2~163^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=973464ad0e1f4aabdc9f13e91af2dd8ac316d872;p=thirdparty%2Fsystemd.git fs-util: try AT_EMPTY_PATH first for futimens_opath --- diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 7f0b5814be5..43836f082ff 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -325,12 +325,22 @@ int fchmod_opath(int fd, mode_t m) { int futimens_opath(int fd, const struct timespec ts[2]) { /* Similar to fchmod_opath() but for futimens() */ - if (utimensat(AT_FDCWD, FORMAT_PROC_FD_PATH(fd), ts, 0) < 0) { + assert(fd >= 0); + + if (utimensat(fd, "", ts, AT_EMPTY_PATH) >= 0) + return 0; + if (errno != EINVAL) + return -errno; + + /* Support for AT_EMPTY_PATH is added rather late (kernel 5.8), so fall back to going through /proc/ + * if unavailable. */ + + if (utimensat(AT_FDCWD, FORMAT_PROC_FD_PATH(fd), ts, /* flags = */ 0) < 0) { if (errno != ENOENT) return -errno; if (proc_mounted() == 0) - return -ENOSYS; /* if we have no /proc/, the concept is not implementable */ + return -ENOSYS; return -ENOENT; }