Skip to content
Snippets Groups Projects
Commit a23b99ea authored by Bill Welliver's avatar Bill Welliver
Browse files

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.
parent 8019350c
Branches
Tags
No related merge requests found
...@@ -293,6 +293,12 @@ protected class Monitor(string path, ...@@ -293,6 +293,12 @@ protected class Monitor(string path,
void create() 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); MON_WERR("Creating monitor for %O.\n", path);
Element::create(this); Element::create(this);
register_path(1); register_path(1);
...@@ -1001,10 +1007,12 @@ protected void inotify_event(int wd, int event, int cookie, string(8bit) path) ...@@ -1001,10 +1007,12 @@ protected void inotify_event(int wd, int event, int cookie, string(8bit) path)
// //
// Create the submonitor. // Create the submonitor.
MON_WARN("Monitor lost for path %O.\n", full_path); 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->max_dir_check_interval,
m->file_interval_factor, 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() // monitor() will not register monitor for path if filter_file()
// returns 0. // returns 0.
if (m) { if (m) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment