Skip to content

Commit df45055

Browse files
authored
tmpfiles: do not require STATX_ATIME (#41232)
Timestamps are not guaranteed to be set by `statx()`, and their presence should not be asserted as a proxy to judge the kernel version. In particular, `STATX_ATIME` is omitted from the return when querying a file on a `noatime` superblock, causing spurious errors from tmpfiles: ```console # SYSTEMD_LOG_LEVEL=debug systemd-tmpfiles --clean <...> Running clean action for entry X /var/tmp/systemd-private-94cc8a77688e497f96d5b9019e66ed6f-*/tmp statx() does not support 'STATX_ATIME' mask (running on an old kernel?) statx(/var/tmp/systemd-private-94cc8a77688e497f96d5b9019e66ed6f-prometheus-smartctl-exporter.service-GKguQK/tmp) failed: Protocol driver not attached statx() does not support 'STATX_ATIME' mask (running on an old kernel?) statx(/var/tmp/systemd-private-94cc8a77688e497f96d5b9019e66ed6f-systemd-logind.service-k8j52T/tmp) failed: Protocol driver not attached statx() does not support 'STATX_ATIME' mask (running on an old kernel?) statx(/var/tmp/systemd-private-94cc8a77688e497f96d5b9019e66ed6f-irqbalance.service-7RJkev/tmp) failed: Protocol driver not attached statx() does not support 'STATX_ATIME' mask (running on an old kernel?) statx(/var/tmp/systemd-private-94cc8a77688e497f96d5b9019e66ed6f-chronyd.service-8hkO5G/tmp) failed: Protocol driver not attached statx() does not support 'STATX_ATIME' mask (running on an old kernel?) statx(/var/tmp/systemd-private-94cc8a77688e497f96d5b9019e66ed6f-dbus-broker.service-6P6LVl/tmp) failed: Protocol driver not attached statx() does not support 'STATX_ATIME' mask (running on an old kernel?) statx(/var/tmp/systemd-private-94cc8a77688e497f96d5b9019e66ed6f-nginx.service-B5HX8B/tmp) failed: Protocol driver not attached Running clean action for entry x /var/tmp/systemd-private-94cc8a77688e497f96d5b9019e66ed6f-* Running clean action for entry q /var/tmp statx() does not support 'STATX_ATIME' mask (running on an old kernel?) statx(/var/tmp) failed: Protocol driver not attached <...> ``` Additionally, refactor `dir_cleanup()` slightly for self-consistency to make it evident that the `NSEC_INFINITY` transformation is correct. Fixes #41227.
2 parents 3d5bd67 + 122de8d commit df45055

2 files changed

Lines changed: 26 additions & 13 deletions

File tree

‎src/basic/time-util.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ struct timespec* timespec_store(struct timespec *ts, usec_t u);
114114
struct timespec* timespec_store_nsec(struct timespec *ts, nsec_t n);
115115

116116
#define TIMESPEC_STORE(u) timespec_store(&(struct timespec) {}, (u))
117+
#define TIMESPEC_STORE_NSEC(n) timespec_store_nsec(&(struct timespec) {}, (n))
117118

118119
usec_t timeval_load(const struct timeval *tv) _pure_;
119120
struct timeval* timeval_store(struct timeval *tv, usec_t u);

‎src/tmpfiles/tmpfiles.c‎

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,8 @@ static int opendir_and_stat(
592592
/* path= */ NULL,
593593
AT_EMPTY_PATH,
594594
/* xstatx_flags= */ 0,
595-
STATX_MODE|STATX_INO|STATX_ATIME|STATX_MTIME,
596-
/* optional_mask= */ 0,
595+
STATX_MODE|STATX_INO,
596+
STATX_ATIME|STATX_MTIME,
597597
STATX_ATTR_MOUNT_ROOT,
598598
&sx);
599599
if (r < 0)
@@ -711,10 +711,10 @@ static int dir_cleanup(
711711
continue;
712712
}
713713

714-
atime_nsec = FLAGS_SET(sx.stx_mask, STATX_ATIME) ? statx_timestamp_load_nsec(&sx.stx_atime) : 0;
715-
mtime_nsec = FLAGS_SET(sx.stx_mask, STATX_MTIME) ? statx_timestamp_load_nsec(&sx.stx_mtime) : 0;
716-
ctime_nsec = FLAGS_SET(sx.stx_mask, STATX_CTIME) ? statx_timestamp_load_nsec(&sx.stx_ctime) : 0;
717-
btime_nsec = FLAGS_SET(sx.stx_mask, STATX_BTIME) ? statx_timestamp_load_nsec(&sx.stx_btime) : 0;
714+
atime_nsec = FLAGS_SET(sx.stx_mask, STATX_ATIME) ? statx_timestamp_load_nsec(&sx.stx_atime) : NSEC_INFINITY;
715+
mtime_nsec = FLAGS_SET(sx.stx_mask, STATX_MTIME) ? statx_timestamp_load_nsec(&sx.stx_mtime) : NSEC_INFINITY;
716+
ctime_nsec = FLAGS_SET(sx.stx_mask, STATX_CTIME) ? statx_timestamp_load_nsec(&sx.stx_ctime) : NSEC_INFINITY;
717+
btime_nsec = FLAGS_SET(sx.stx_mask, STATX_BTIME) ? statx_timestamp_load_nsec(&sx.stx_btime) : NSEC_INFINITY;
718718

719719
sub_path = path_join(p, de->d_name);
720720
if (!sub_path) {
@@ -868,11 +868,19 @@ static int dir_cleanup(
868868
log_action("Would restore", "Restoring",
869869
"%s access and modification time on \"%s\": %s, %s",
870870
p,
871-
FORMAT_TIMESTAMP_STYLE(self_atime_nsec / NSEC_PER_USEC, TIMESTAMP_US),
872-
FORMAT_TIMESTAMP_STYLE(self_mtime_nsec / NSEC_PER_USEC, TIMESTAMP_US));
873-
874-
timespec_store_nsec(ts + 0, self_atime_nsec);
875-
timespec_store_nsec(ts + 1, self_mtime_nsec);
871+
self_atime_nsec != NSEC_INFINITY
872+
? FORMAT_TIMESTAMP_STYLE(self_atime_nsec / NSEC_PER_USEC, TIMESTAMP_US)
873+
: "(omitted)",
874+
self_mtime_nsec != NSEC_INFINITY
875+
? FORMAT_TIMESTAMP_STYLE(self_mtime_nsec / NSEC_PER_USEC, TIMESTAMP_US)
876+
: "(omitted)");
877+
878+
ts[0] = self_atime_nsec != NSEC_INFINITY
879+
? *TIMESPEC_STORE_NSEC(self_atime_nsec)
880+
: TIMESPEC_OMIT;
881+
ts[1] = self_mtime_nsec != NSEC_INFINITY
882+
? *TIMESPEC_STORE_NSEC(self_mtime_nsec)
883+
: TIMESPEC_OMIT;
876884

877885
/* Restore original directory timestamps */
878886
if (!arg_dry_run &&
@@ -3117,6 +3125,7 @@ static int clean_item_instance(
31173125
return 0;
31183126

31193127
usec_t cutoff = n - i->age;
3128+
nsec_t atime_nsec, mtime_nsec;
31203129

31213130
_cleanup_closedir_ DIR *d = NULL;
31223131
struct statx sx;
@@ -3127,6 +3136,9 @@ static int clean_item_instance(
31273136
if (r <= 0)
31283137
return r;
31293138

3139+
atime_nsec = FLAGS_SET(sx.stx_mask, STATX_ATIME) ? statx_timestamp_load_nsec(&sx.stx_atime) : NSEC_INFINITY;
3140+
mtime_nsec = FLAGS_SET(sx.stx_mask, STATX_MTIME) ? statx_timestamp_load_nsec(&sx.stx_mtime) : NSEC_INFINITY;
3141+
31303142
if (DEBUG_LOGGING) {
31313143
_cleanup_free_ char *ab_f = NULL, *ab_d = NULL;
31323144

@@ -3146,8 +3158,8 @@ static int clean_item_instance(
31463158
}
31473159

31483160
return dir_cleanup(c, i, instance, d,
3149-
statx_timestamp_load_nsec(&sx.stx_atime),
3150-
statx_timestamp_load_nsec(&sx.stx_mtime),
3161+
atime_nsec,
3162+
mtime_nsec,
31513163
cutoff * NSEC_PER_USEC,
31523164
sx.stx_dev_major, sx.stx_dev_minor,
31533165
mountpoint,

0 commit comments

Comments
 (0)