From 767d817895d8da04cba526cb7ab890a3d2887f08 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Mon, 29 Apr 2024 15:46:32 +0800 Subject: [PATCH 1/4] pam_systemd_loadkey: add missing PAM_EXTERN --- src/login/pam_systemd_loadkey.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/login/pam_systemd_loadkey.c b/src/login/pam_systemd_loadkey.c index 3b4e91124a..088fd355ef 100644 --- a/src/login/pam_systemd_loadkey.c +++ b/src/login/pam_systemd_loadkey.c @@ -18,7 +18,7 @@ * This can be overridden by the keyname= parameter. */ static const char DEFAULT_KEYNAME[] = "cryptsetup"; -_public_ int pam_sm_authenticate( +_public_ PAM_EXTERN int pam_sm_authenticate( pam_handle_t *handle, int flags, int argc, const char **argv) { @@ -89,7 +89,7 @@ _public_ int pam_sm_authenticate( return PAM_SUCCESS; } -_public_ int pam_sm_setcred( +_public_ PAM_EXTERN int pam_sm_setcred( pam_handle_t *handle, int flags, int argc, const char **argv) { From cce82462a19d59c1e1bb2eafa9dc879a1c95cf40 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Mon, 29 Apr 2024 15:45:14 +0800 Subject: [PATCH 2/4] efivars: drop unneeded UTIME_NOW futimens(2) defaults to current time if 'times' is NULL. --- src/basic/efivars.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/basic/efivars.c b/src/basic/efivars.c index 43f498de0f..8470d085c7 100644 --- a/src/basic/efivars.c +++ b/src/basic/efivars.c @@ -239,10 +239,7 @@ int efi_set_variable(const char *variable, const void *value, size_t size) { /* For some reason efivarfs doesn't update mtime automatically. Let's do it manually then. This is * useful for processes that cache EFI variables to detect when changes occurred. */ - if (futimens(fd, (const struct timespec[2]) { - { .tv_nsec = UTIME_NOW }, - { .tv_nsec = UTIME_NOW } - }) < 0) + if (futimens(fd, /* times = */ NULL) < 0) log_debug_errno(errno, "Failed to update mtime/atime on %s, ignoring: %m", p); r = 0; From 973464ad0e1f4aabdc9f13e91af2dd8ac316d872 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Mon, 29 Apr 2024 16:22:37 +0800 Subject: [PATCH 3/4] fs-util: try AT_EMPTY_PATH first for futimens_opath --- src/basic/fs-util.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 7f0b5814be..43836f082f 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -325,12 +325,22 @@ int fchmod_opath(int fd, mode_t m) { int futimens_opath(int fd, const struct timespec ts[2]) { /* Similar to fchmod_opath() but for futimens() */ - if (utimensat(AT_FDCWD, FORMAT_PROC_FD_PATH(fd), ts, 0) < 0) { + assert(fd >= 0); + + if (utimensat(fd, "", ts, AT_EMPTY_PATH) >= 0) + return 0; + if (errno != EINVAL) + return -errno; + + /* Support for AT_EMPTY_PATH is added rather late (kernel 5.8), so fall back to going through /proc/ + * if unavailable. */ + + if (utimensat(AT_FDCWD, FORMAT_PROC_FD_PATH(fd), ts, /* flags = */ 0) < 0) { if (errno != ENOENT) return -errno; if (proc_mounted() == 0) - return -ENOSYS; /* if we have no /proc/, the concept is not implementable */ + return -ENOSYS; return -ENOENT; } From f0fb2943696fca8b908bdb11f1939ad4c8922e51 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Mon, 29 Apr 2024 16:23:00 +0800 Subject: [PATCH 4/4] fs-util: modernize touch_file a bit --- src/basic/fs-util.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 43836f082f..b3d5e8a07d 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -415,17 +415,14 @@ int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gi ret = fchmod_and_chown(fd, mode, uid, gid); if (stamp != USEC_INFINITY) { - struct timespec ts[2]; + struct timespec ts; + timespec_store(&ts, stamp); - timespec_store(&ts[0], stamp); - ts[1] = ts[0]; - r = futimens_opath(fd, ts); + r = futimens_opath(fd, (const struct timespec[2]) { ts, ts }); } else - r = futimens_opath(fd, NULL); - if (r < 0 && ret >= 0) - return r; + r = futimens_opath(fd, /* ts = */ NULL); - return ret; + return RET_GATHER(ret, r); } int symlink_idempotent(const char *from, const char *to, bool make_relative) {