tmpfiles: skip redundant label writes to avoid unnecessary timestamp changes
When systemd-tmpfiles processes a 'z' (relabel) entry, fd_set_perms() unconditionally calls label_fix_full() even when mode, owner, and group already match. This causes setfilecon_raw() (SELinux) or xsetxattr() (SMACK) to write the security label even if it is already correct, which on some kernels updates the file's timestamps unnecessarily. Fix this by comparing the current label with the desired label before writing, and skipping the write when they already match. This is consistent with how fd_set_perms() already skips chmod/chown when the values are unchanged.
This commit is contained in:
committed by
Luca Boccassi
parent
40d0fb2eb2
commit
8a8f22f1d8
@@ -301,6 +301,18 @@ int xsetxattr_full(
|
||||
if (size == SIZE_MAX)
|
||||
size = strlen(value);
|
||||
|
||||
/* Skip the write if the xattr already has the correct value, to avoid
|
||||
* unnecessary timestamp changes on the file. Only do this for plain
|
||||
* replace mode (xattr_flags == 0) — XATTR_CREATE callers expect
|
||||
* -EEXIST when the xattr already exists. */
|
||||
_cleanup_free_ char *old_value = NULL;
|
||||
size_t old_size;
|
||||
|
||||
if (xattr_flags == 0 &&
|
||||
getxattr_at_malloc(fd, path, name, at_flags, &old_value, &old_size) >= 0 &&
|
||||
memcmp_nn(old_value, old_size, value, size) == 0)
|
||||
return 0;
|
||||
|
||||
if (have_xattrat && !isempty(path)) {
|
||||
struct xattr_args args = {
|
||||
.value = PTR_TO_UINT64(value),
|
||||
|
||||
Reference in New Issue
Block a user