Skip to content

Commit

Permalink
file_watch: don't watch special files
Browse files Browse the repository at this point in the history
While /dev/null is always empty, it still generates inotify events. So
using /dev/null as config file will cause the compositor to reset itself
frequently.

Not entire sure if only allowing regular files is sufficient, but we
will be doing this until an issue comes up.

Fixes chjj#320

Signed-off-by: Yuxuan Shui <[email protected]>
  • Loading branch information
yshui committed Feb 26, 2020
1 parent 630d6f3 commit a8e8b74
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/file_watch.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ bool file_watch_add(void *_fwr, const char *filename, file_watch_cb_t cb, void *
log_debug("Adding \"%s\" to watched files", filename);
auto fwr = (struct file_watch_registry *)_fwr;
int wd = -1;

struct stat statbuf;
int ret = stat(filename, &statbuf);
if (ret < 0) {
log_error_errno("Failed to retrieve information about file \"%s\"", filename);
return false;
}
if (!S_ISREG(statbuf.st_mode)) {
log_info("\"%s\" is not a regular file, not watching it.", filename);
return false;
}

#ifdef HAS_INOTIFY
wd = inotify_add_watch(fwr->w.fd, filename,
IN_CLOSE_WRITE | IN_MOVE_SELF | IN_DELETE_SELF);
Expand Down

0 comments on commit a8e8b74

Please sign in to comment.