From c6569f39f17af1b05a8a9806d794343a65a0f267 Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Wed, 27 Oct 2010 09:29:48 -0400 Subject: [PATCH] Process multiple inotify events If multiple inotify events are presented, process *all* of them. This can happen when several device adds are pushed simultaneously. handle_inotify() was refactored. Signed-off-by: Peter Hurley Signed-off-by: Stefan Richter --- src/fw.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/fw.c b/src/fw.c index 2d8a292..558767c 100644 --- a/src/fw.c +++ b/src/fw.c @@ -360,21 +360,16 @@ handle_device_event(raw1394handle_t handle, } static int -handle_inotify(raw1394handle_t handle, struct epoll_closure *ec, - __uint32_t events) +process_inotify_event(fw_handle_t fwhandle, struct inotify_event *event) { - fw_handle_t fwhandle = handle->mode.fw; - struct inotify_event *event; char filename[32]; struct fw_cdev_get_info info; struct fw_cdev_event_bus_reset reset; struct epoll_event ep; - int i, len, fd, phy_id, fname_str_sz; + int i, fd, phy_id, fname_str_sz; - event = (struct inotify_event *) fwhandle->buffer; - len = read(fwhandle->inotify_fd, event, BUFFER_SIZE); if (!(event->mask & IN_CREATE)) - return -1; + return 0; if (!is_fw_device_name(event->name)) return 0; snprintf(filename, sizeof filename, FW_DEVICE_DIR "/%s", event->name); @@ -433,6 +428,30 @@ handle_inotify(raw1394handle_t handle, struct epoll_closure *ec, return 0; } +static int +handle_inotify(raw1394handle_t handle, struct epoll_closure *ec, + __uint32_t events) +{ + fw_handle_t fwhandle = handle->mode.fw; + struct inotify_event *event; + int len; + int retval = 0; + + event = (struct inotify_event *) fwhandle->buffer; + len = read(fwhandle->inotify_fd, event, BUFFER_SIZE); + + while (len >= sizeof(struct inotify_event)) { + retval = process_inotify_event(fwhandle, event); + if (retval == -1) + break; + len -= sizeof(struct inotify_event) + event->len; + event = (struct inotify_event *) ((char *)event + + (sizeof(struct inotify_event) + event->len)); + } + + return retval; +} + int fw_loop_iterate(raw1394handle_t handle) { int i, count, retval = 0;