mirror of
https://github.com/systemd/systemd.git
synced 2025-03-22 06:50:18 +03:00
tmpfiles,chown-recursive: port to xsetxattr()/xremovexattr()
This commit is contained in:
parent
d228afd792
commit
61b3d116ee
@ -3,7 +3,6 @@
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/xattr.h>
|
||||
|
||||
#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)
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/xattr.h>
|
||||
#include <sysexits.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user