From d92f1366c838fd8e4f7508a4431138384dbff259 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 10 Jun 2025 14:06:53 +0200 Subject: [PATCH] libmount: (monitor) check for utab delete Also, monitor for "rm -rf /run/mount" to reinitialize the monitor. Signed-off-by: Karel Zak --- libmount/src/monitor_utab.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libmount/src/monitor_utab.c b/libmount/src/monitor_utab.c index f0e90c204..24b7b5450 100644 --- a/libmount/src/monitor_utab.c +++ b/libmount/src/monitor_utab.c @@ -94,7 +94,7 @@ static int userspace_add_watch(struct monitor_entry *me, int *final, int *fd) /* try event file if already exists */ errno = 0; - wd = inotify_add_watch(me->fd, filename, IN_CLOSE_WRITE); + wd = inotify_add_watch(me->fd, filename, IN_CLOSE_WRITE | IN_DELETE_SELF); if (wd >= 0) { DBG(MONITOR, ul_debug(" added inotify watch for %s [fd=%d]", filename, wd)); rc = 0; @@ -126,7 +126,7 @@ static int userspace_add_watch(struct monitor_entry *me, int *final, int *fd) break; /* already exist */ } errno = 0; - wd = inotify_add_watch(me->fd, filename, IN_CREATE|IN_ISDIR); + wd = inotify_add_watch(me->fd, filename, IN_CREATE|IN_ISDIR|IN_DELETE_SELF); if (wd >= 0) { DBG(MONITOR, ul_debug(" added inotify watch for %s [fd=%d]", filename, wd)); rc = 0; @@ -216,6 +216,11 @@ static int userspace_process_event(struct libmnt_monitor *mn, if (e->mask & IN_CLOSE_WRITE) status = 0; else { + if (e->mask & IN_DELETE_SELF) { + DBG(MONITOR, ul_debugobj(mn, " reseting watch")); + userspace_free_data(me); + } + /* add watch for the event file */ userspace_add_watch(me, &status, &fd); -- 2.47.3