From a8e8b747feb999ab302797974c779a3ad9f2a728 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Wed, 26 Feb 2020 21:11:55 +0000 Subject: [PATCH] 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 --- src/file_watch.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/file_watch.c b/src/file_watch.c index dcd0e1d..faa8f68 100644 --- a/src/file_watch.c +++ b/src/file_watch.c @@ -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);