return r;
}
+int fchmod_opath(int fd, mode_t m) {
+ char procfs_path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int)];
+
+ /* This function operates also on fd that might have been opened with
+ * O_PATH. Indeed fchmodat() doesn't have the AT_EMPTY_PATH flag like
+ * fchownat() does. */
+
+ xsprintf(procfs_path, "/proc/self/fd/%i", fd);
+
+ if (chmod(procfs_path, m) < 0)
+ return -errno;
+
+ return 0;
+}
+
int fd_warn_permissions(const char *path, int fd) {
struct stat st;
int chmod_and_chown(const char *path, 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 fd_warn_permissions(const char *path, int fd);
if (m == (st->st_mode & 07777))
log_debug("\"%s\" has correct mode %o already.", path, st->st_mode);
else {
- char procfs_path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int)];
-
log_debug("Changing \"%s\" to mode %o.", path, m);
-
- /* fchmodat() still doesn't have AT_EMPTY_PATH flag. */
- xsprintf(procfs_path, "/proc/self/fd/%i", fd);
-
- if (chmod(procfs_path, m) < 0)
- return log_error_errno(errno, "chmod() of %s via %s failed: %m", path, procfs_path);
+ if (fchmod_opath(fd, m) < 0)
+ return log_error_errno(errno, "fchmod() of %s failed: %m", path);
}
}
}