]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fs-util: add new futimens_opath() helper
authorLennart Poettering <lennart@poettering.net>
Fri, 25 Sep 2020 14:40:02 +0000 (16:40 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 28 Sep 2020 16:45:54 +0000 (18:45 +0200)
futimens() that works for O_PATH fds.

src/basic/fs-util.c
src/basic/fs-util.h

index c20a29332a55c9b35fe8bafe41cda3916a3ce300..587b3504ee86ad7489663e881b3f8b75fca5b78a 100644 (file)
@@ -312,6 +312,25 @@ int fchmod_opath(int fd, mode_t m) {
         return 0;
 }
 
+int futimens_opath(int fd, const struct timespec ts[2]) {
+        char procfs_path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int)];
+
+        /* Similar to fchmod_path() but for futimens() */
+
+        xsprintf(procfs_path, "/proc/self/fd/%i", fd);
+        if (utimensat(AT_FDCWD, procfs_path, ts, 0) < 0) {
+                if (errno != ENOENT)
+                        return -errno;
+
+                if (proc_mounted() == 0)
+                        return -ENOSYS; /* if we have no /proc/, the concept is not implementable */
+
+                return -ENOENT;
+        }
+
+        return 0;
+}
+
 int stat_warn_permissions(const char *path, const struct stat *st) {
         assert(path);
         assert(st);
index eb6e1eee4fa018a652e8bd1b4f259a1f95d8d3b1..cf87a1e4d5696e968d6c3774c14a3ae3110c612d 100644 (file)
@@ -38,6 +38,8 @@ int fchmod_and_chown(int fd, mode_t mode, uid_t uid, gid_t gid);
 int fchmod_umask(int fd, mode_t mode);
 int fchmod_opath(int fd, mode_t m);
 
+int futimens_opath(int fd, const struct timespec ts[2]);
+
 int fd_warn_permissions(const char *path, int fd);
 int stat_warn_permissions(const char *path, const struct stat *st);