file_watch: don't watch special files

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 #320

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2020-02-26 21:11:55 +00:00
parent 630d6f3a26
commit a8e8b747fe
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
1 changed files with 12 additions and 0 deletions

View File

@ -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);