summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2007-10-04 16:00:51 +0000
committerMarcel Holtmann <marcel@holtmann.org>2007-10-04 16:00:51 +0000
commit2d903fdf08308d9b9239343598ee157351e81a2a (patch)
tree1631ccdb36bc3f4acdf1671f05656ad8082b1198
parent07ebeadd853277fa7b7fae80abb84c17bf1d303b (diff)
Fix potential infinite loop in inotify support
-rw-r--r--common/notify-inotify.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/common/notify-inotify.c b/common/notify-inotify.c
index 281d4179..a7a832da 100644
--- a/common/notify-inotify.c
+++ b/common/notify-inotify.c
@@ -60,23 +60,27 @@ static gboolean io_event(GIOChannel *chan, GIOCondition cond, gpointer data)
memset(buf, 0, sizeof(buf));
err = g_io_channel_read(chan, (gchar *) buf, sizeof(buf) - 1, &len);
- if (err == G_IO_ERROR_AGAIN)
- return TRUE;
+ if (err != G_IO_ERROR_NONE) {
+ if (err == G_IO_ERROR_AGAIN)
+ return TRUE;
+ error("Reading from inotify channel failed");
+ return FALSE;
+ }
+
while (len >= sizeof(struct inotify_event)) {
struct inotify_event *evt = (struct inotify_event *) ptr;
- if (evt->wd != wd || !callback)
- continue;
-
- if (evt->mask & (IN_CREATE | IN_MOVED_TO))
- callback(NOTIFY_CREATE, evt->name, NULL);
+ if (evt->wd == wd && callback) {
+ if (evt->mask & (IN_CREATE | IN_MOVED_TO))
+ callback(NOTIFY_CREATE, evt->name, NULL);
- if (evt->mask & (IN_DELETE | IN_MOVED_FROM))
- callback(NOTIFY_DELETE, evt->name, NULL);
+ if (evt->mask & (IN_DELETE | IN_MOVED_FROM))
+ callback(NOTIFY_DELETE, evt->name, NULL);
- if (evt->mask & IN_MODIFY)
- callback(NOTIFY_MODIFY, evt->name, NULL);
+ if (evt->mask & IN_MODIFY)
+ callback(NOTIFY_MODIFY, evt->name, NULL);
+ }
len -= sizeof(struct inotify_event) + evt->len;
ptr += sizeof(struct inotify_event) + evt->len;