From a23b99eaeac4369f23689cea204b1aa7edf57835 Mon Sep 17 00:00:00 2001 From: Bill Welliver <bill@welliver.org> Date: Wed, 21 Mar 2018 15:19:30 -0400 Subject: [PATCH] Filesystem.Monitor: don't auto monitor paths that don't exist. This should mitigate a race condition with inotify causing short lived directory monitors to remain indefinitely. --- lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike b/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike index ca65ab6ba2..fec611c29a 100644 --- a/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike +++ b/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike @@ -293,6 +293,12 @@ protected class Monitor(string path, void create() { + if(flags & MF_AUTO || flags & MF_HARD) { + Stdio.Stat fstat = file_stat(path); + if(!fstat) throw(Error.Generic("Cannot create Monitor for non-existent path " + path + + " when flags MF_AUTO or MF_HARD are present.\n")); + } + MON_WERR("Creating monitor for %O.\n", path); Element::create(this); register_path(1); @@ -1001,10 +1007,12 @@ protected void inotify_event(int wd, int event, int cookie, string(8bit) path) // // Create the submonitor. MON_WARN("Monitor lost for path %O.\n", full_path); - m = monitor(full_path, m->flags | MF_AUTO | MF_HARD, + mixed err = catch(m = monitor(full_path, m->flags | MF_AUTO | MF_HARD, m->max_dir_check_interval, m->file_interval_factor, - m->stable_time); + m->stable_time)); + if(err) + MON_WARN("Monitor for %O failed. Message: %s\n", full_path, Error.mkerror(err)->message()); // monitor() will not register monitor for path if filter_file() // returns 0. if (m) { -- GitLab