diff --git a/src/shared/chown-recursive.c b/src/shared/chown-recursive.c index 6aa5f6723ec..06c5adb1e50 100644 --- a/src/shared/chown-recursive.c +++ b/src/shared/chown-recursive.c @@ -3,7 +3,6 @@ #include #include #include -#include #include "chown-recursive.h" #include "dirent-util.h" @@ -13,6 +12,7 @@ #include "stdio-util.h" #include "strv.h" #include "user-util.h" +#include "xattr-util.h" static int chown_one( int fd, @@ -26,14 +26,12 @@ static int chown_one( assert(fd >= 0); assert(st); - /* We change ACLs through the /proc/self/fd/%i path, so that we have a stable reference that works - * with O_PATH. */ - /* Drop any ACL if there is one */ - FOREACH_STRING(n, "system.posix_acl_access", "system.posix_acl_default") - if (removexattr(FORMAT_PROC_FD_PATH(fd), n) < 0) - if (!ERRNO_IS_XATTR_ABSENT(errno)) - return -errno; + FOREACH_STRING(n, "system.posix_acl_access", "system.posix_acl_default") { + r = xremovexattr(fd, /* path = */ NULL, AT_EMPTY_PATH, n); + if (r < 0 && !ERRNO_IS_NEG_XATTR_ABSENT(r)) + return r; + } r = fchmod_and_chown(fd, st->st_mode & mask, uid, gid); if (r < 0) diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 6ce4a78adc1..e401eaa88fe 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -73,6 +72,7 @@ #include "umask-util.h" #include "user-util.h" #include "virt.h" +#include "xattr-util.h" /* This reads all files listed in /etc/tmpfiles.d/?*.conf and creates * them in the file system. This is intended to be used to create @@ -1189,6 +1189,8 @@ static int fd_set_xattrs( const struct stat *st, CreationMode creation) { + int r; + assert(c); assert(i); assert(fd >= 0); @@ -1198,10 +1200,12 @@ static int fd_set_xattrs( log_action("Would set", "Setting", "%s extended attribute '%s=%s' on %s", *name, *value, path); - if (!arg_dry_run && - setxattr(FORMAT_PROC_FD_PATH(fd), *name, *value, strlen(*value), 0) < 0) - return log_error_errno(errno, "Setting extended attribute %s=%s on %s failed: %m", - *name, *value, path); + if (!arg_dry_run) { + r = xsetxattr(fd, /* path = */ NULL, AT_EMPTY_PATH, *name, *value); + if (r < 0) + return log_error_errno(r, "Failed to set extended attribute %s=%s on '%s': %m", + *name, *value, path); + } } return 0; }