}
static int fd_set_perms(Item *i, int fd, const char *path, const struct stat *st) {
- _cleanup_free_ char *buffer = NULL;
struct stat stbuf;
- int r;
assert(i);
assert(fd);
-
- if (!path) {
- r = fd_get_path(fd, &buffer);
- if (r < 0)
- return log_error_errno(r, "Failed to get path: %m");
-
- path = buffer;
- }
+ assert(path);
if (!i->mode_set && !i->uid_set && !i->gid_set)
goto shortcut;
static int fd_set_xattrs(Item *i, int fd, const char *path, const struct stat *st) {
char procfs_path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int)];
- _cleanup_free_ char *buffer = NULL;
char **name, **value;
- int r;
assert(i);
assert(fd);
-
- if (!path) {
- r = fd_get_path(fd, &buffer);
- if (r < 0)
- return log_error_errno(r, "Failed to get path: %m");
-
- path = buffer;
- }
+ assert(path);
xsprintf(procfs_path, "/proc/self/fd/%i", fd);
int r = 0;
#if HAVE_ACL
char procfs_path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int)];
- _cleanup_free_ char *buffer = NULL;
struct stat stbuf;
assert(item);
assert(fd);
-
- if (!path) {
- r = fd_get_path(fd, &buffer);
- if (r < 0)
- return log_error_errno(r, "Failed to get path: %m");
-
- path = buffer;
- }
+ assert(path);
if (!st) {
if (fstat(fd, &stbuf) < 0)
static int fd_set_attribute(Item *item, int fd, const char *path, const struct stat *st) {
_cleanup_close_ int procfs_fd = -1;
- _cleanup_free_ char *buffer = NULL;
struct stat stbuf;
unsigned f;
int r;
+ assert(item);
+ assert(fd);
+ assert(path);
+
if (!item->attribute_set || item->attribute_mask == 0)
return 0;
- if (!path) {
- r = fd_get_path(fd, &buffer);
- if (r < 0)
- return log_error_errno(r, "Failed to get path: %m");
-
- path = buffer;
- }
-
if (!st) {
if (fstat(fd, &stbuf) < 0)
return log_error_errno(errno, "fstat(%s) failed: %m", path);
int r = 0, q;
assert(i);
+ assert(path);
assert(fd >= 0);
if (fstat(fd, &st) < 0) {
de_fd = openat(fd, de->d_name, O_NOFOLLOW|O_CLOEXEC|O_PATH);
if (de_fd < 0)
q = log_error_errno(errno, "Failed to open() file '%s': %m", de->d_name);
- else
- /* Pass ownership of dirent fd over */
- q = item_do(i, de_fd, NULL, action);
+ else {
+ _cleanup_free_ char *de_path = NULL;
+
+ de_path = path_join(NULL, path, de->d_name);
+ if (!de_path)
+ q = log_oom();
+ else
+ /* Pass ownership of dirent fd over */
+ q = item_do(i, de_fd, de_path, action);
+ }
if (q < 0 && r == 0)
r = q;
--- /dev/null
+#! /bin/bash
+
+set -e
+set -x
+
+rm -fr /tmp/{z,Z}
+mkdir /tmp/{z,Z}
+
+#
+# 'z'
+#
+mkdir /tmp/z/d{1,2}
+touch /tmp/z/f1 /tmp/z/d1/f11 /tmp/z/d2/f21
+
+systemd-tmpfiles --create - <<EOF
+z /tmp/z/f1 0755 daemon daemon - -
+z /tmp/z/d1 0755 daemon daemon - -
+EOF
+
+test $(stat -c %U:%G /tmp/z/f1) = "daemon:daemon"
+test $(stat -c %U:%G /tmp/z/d1) = "daemon:daemon"
+test $(stat -c %U:%G /tmp/z/d1/f11) = "root:root"
+
+systemd-tmpfiles --create - <<EOF
+z /tmp/z/d2/* 0755 daemon daemon - -
+EOF
+
+test $(stat -c %U:%G /tmp/z/d2/f21) = "daemon:daemon"
+
+#
+# 'Z'
+#
+mkdir /tmp/Z/d1 /tmp/Z/d1/d11
+touch /tmp/Z/f1 /tmp/Z/d1/f11 /tmp/Z/d1/d11/f111
+
+systemd-tmpfiles --create - <<EOF
+Z /tmp/Z/f1 0755 daemon daemon - -
+Z /tmp/Z/d1 0755 daemon daemon - -
+EOF
+
+test $(stat -c %U:%G /tmp/Z/f1) = "daemon:daemon"
+test $(stat -c %U:%G /tmp/Z/d1) = "daemon:daemon"
+test $(stat -c %U:%G /tmp/Z/d1/d11) = "daemon:daemon"
+test $(stat -c %U:%G /tmp/Z/d1/f11) = "daemon:daemon"
+test $(stat -c %U:%G /tmp/Z/d1/d11/f111) = "daemon:daemon"