#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <sys/xattr.h>
#include "chown-recursive.h"
#include "dirent-util.h"
#include "stdio-util.h"
#include "strv.h"
#include "user-util.h"
+#include "xattr-util.h"
static int chown_one(
int fd,
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)
#include <stddef.h>
#include <stdlib.h>
#include <sys/file.h>
-#include <sys/xattr.h>
#include <sysexits.h>
#include <time.h>
#include <unistd.h>
#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
const struct stat *st,
CreationMode creation) {
+ int r;
+
assert(c);
assert(i);
assert(fd >= 0);
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;
}