From 59b8636bc83249062eb66394d67125b1ada36185 Mon Sep 17 00:00:00 2001 From: Aman Gupta Karmani Date: Mon, 12 Oct 2020 15:38:04 -0700 Subject: [PATCH] Fix systemd-time-wait-sync getting stuck with upstream patches (#897) --- ...02-time-wait-sync-log-inotify-errors.patch | 23 ++++++++ .../systemd/0003-fix-inotify-watches.patch | 54 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 buildroot-external/patches/systemd/0002-time-wait-sync-log-inotify-errors.patch create mode 100644 buildroot-external/patches/systemd/0003-fix-inotify-watches.patch diff --git a/buildroot-external/patches/systemd/0002-time-wait-sync-log-inotify-errors.patch b/buildroot-external/patches/systemd/0002-time-wait-sync-log-inotify-errors.patch new file mode 100644 index 000000000..35ae36b2d --- /dev/null +++ b/buildroot-external/patches/systemd/0002-time-wait-sync-log-inotify-errors.patch @@ -0,0 +1,23 @@ +From 4a4298ef78e943d36f3b8d8e78bfa21b1506961e Mon Sep 17 00:00:00 2001 +From: Aman Gupta Karmani +Date: Mon, 12 Oct 2020 13:39:26 -0700 +Subject: [PATCH] time-wait-sync: log errors trying to watch + /run/systemd/timesync + +--- + src/time-wait-sync/time-wait-sync.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/time-wait-sync/time-wait-sync.c b/src/time-wait-sync/time-wait-sync.c +index 96072445f6e..c8ec4850426 100644 +--- a/src/time-wait-sync/time-wait-sync.c ++++ b/src/time-wait-sync/time-wait-sync.c +@@ -50,7 +50,7 @@ static void clock_state_release(ClockState *sp) { + static int clock_state_update(ClockState *sp, sd_event *event); + + static int update_notify_run_systemd_timesync(ClockState *sp) { +- sp->run_systemd_timesync_wd = inotify_add_watch(sp->inotify_fd, "/run/systemd/timesync", IN_CREATE|IN_DELETE_SELF); ++ sp->run_systemd_timesync_wd = inotify_add_watch_and_warn(sp->inotify_fd, "/run/systemd/timesync", IN_CREATE|IN_DELETE_SELF); + return sp->run_systemd_timesync_wd; + } + diff --git a/buildroot-external/patches/systemd/0003-fix-inotify-watches.patch b/buildroot-external/patches/systemd/0003-fix-inotify-watches.patch new file mode 100644 index 000000000..30d322691 --- /dev/null +++ b/buildroot-external/patches/systemd/0003-fix-inotify-watches.patch @@ -0,0 +1,54 @@ +From f6f4f5fe5395a57f10dd446c7266c53f0673eaac Mon Sep 17 00:00:00 2001 +From: Balaji Punnuru +Date: Thu, 9 Apr 2020 12:21:49 -0400 +Subject: [PATCH] util: return the correct correct wd from inotify helpers + +We need to propagate the acquired watch descriptors because our callers +are counting on them. + +[Lennart: this is split out of #15381 and simplified] +--- + src/basic/fs-util.c | 14 ++++++++------ + 1 file changed, 8 insertions(+), 6 deletions(-) + +diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c +index 558cafbcaf5..ef3b5a51842 100644 +--- a/src/basic/fs-util.c ++++ b/src/basic/fs-util.c +@@ -692,28 +692,30 @@ int unlink_or_warn(const char *filename) { + + int inotify_add_watch_fd(int fd, int what, uint32_t mask) { + char path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int) + 1]; +- int r; ++ int wd; + + /* This is like inotify_add_watch(), except that the file to watch is not referenced by a path, but by an fd */ + xsprintf(path, "/proc/self/fd/%i", what); + +- r = inotify_add_watch(fd, path, mask); +- if (r < 0) ++ wd = inotify_add_watch(fd, path, mask); ++ if (wd < 0) + return -errno; + +- return r; ++ return wd; + } + + int inotify_add_watch_and_warn(int fd, const char *pathname, uint32_t mask) { ++ int wd; + +- if (inotify_add_watch(fd, pathname, mask) < 0) { ++ wd = inotify_add_watch(fd, pathname, mask); ++ if (wd < 0) { + if (errno == ENOSPC) + return log_error_errno(errno, "Failed to add a watch for %s: inotify watch limit reached", pathname); + + return log_error_errno(errno, "Failed to add a watch for %s: %m", pathname); + } + +- return 0; ++ return wd; + } + + static bool unsafe_transition(const struct stat *a, const struct stat *b) {