From 10b1b4ee12957aa183d2695f69673706886ec14f Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Tue, 28 Oct 2014 13:37:42 +0000 Subject: [PATCH] devman: allow multiple event read calls up to EOF Read calls may be repeated by VFS if the user destination memory is not mapped in. Devman currently assumes that all reads are successful, and uses this to track whether EOF has been reached for a particular event, discarding it as soon as this happens. Upon repetition, this may result in lost events for devmand. With this patch, devman discards events only once devmand reads the EOF marker, which itself can never generate a user page fault. The result is that read calls for data can be repeated safely, without the risk of losing events in the process. Change-Id: I9dfdf7f8c8992a20a10302d79c3506e61f8564b0 --- minix/servers/devman/device.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/minix/servers/devman/device.c b/minix/servers/devman/device.c index 9075257e9..9d5ed54c4 100644 --- a/minix/servers/devman/device.c +++ b/minix/servers/devman/device.c @@ -143,13 +143,7 @@ devman_event_read(char **ptr, size_t *len,off_t offset, void *data) { struct devman_event *ev = NULL; struct devman_event_inode *n; - static int eof = 0; - if (eof) { - *len=0; - eof = 0; - return 0; - } n = (struct devman_event_inode *) data; if (!TAILQ_EMPTY(&n->event_queue)) { @@ -157,18 +151,17 @@ devman_event_read(char **ptr, size_t *len,off_t offset, void *data) } buf_init(offset, *len); - if (ev != NULL) { + if (ev != NULL) buf_printf("%s", ev->data); - /* read all? */ - if (*len + offset >= strlen(ev->data)) { - TAILQ_REMOVE(&n->event_queue, ev, events); - free(ev); - eof = 1; - } - } *len = buf_get(ptr); - + + /* read all (EOF)? */ + if (ev != NULL && *len == 0) { + TAILQ_REMOVE(&n->event_queue, ev, events); + free(ev); + } + return 0; }