From: "Magnus Vigerlöf" <wigge@bigfoot.com>
To: "Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
"Dmitry Torokhov" <dtor@insightbb.com>,
linux-input@atrey.karlin.mff.cuni.cz,
linux-kernel@vger.kernel.org, "Vojtech Pavlik" <vojtech@suse.cz>,
"Zephaniah E. Hull" <warp@aehallh.com>,
wigge@bigfoot.com
Subject: Re: input: evdev.c EVIOCGRAB semantics question
Date: Wed, 16 Aug 2006 01:20:03 +0200 [thread overview]
Message-ID: <200608160120.03398.wigge@bigfoot.com> (raw)
In-Reply-To: <200608150049.50815.wigge@bigfoot.com>
On Tuesday 15 August 2006 00:49, Magnus Vigerlöf wrote:
[...]
> However, this doesn't address the problem I initially described (I
> think)... What if two application open the same device and one of the
> application do a EVIOCGRAB. Should both applications still get events? With
> the above fix two applications that opens /dev/input/mouse2 resp
> /dev/input/event4 for the same hw and the latter grabs the device, both
> will get events. Using a counter for grab (just like the open-counter) on
> the handler should make them behave the same way in both cases I think.
> Gnnn... I'll make a patch tomorrow (ok today, Tuesday) so you can see what
> I rambling about..
Ok, this is what I mean (in code) if anyone's interested.. It should apply cleanly
on Dmitrys git-tree. It seems to work on my system without any side-effects
regarding the keyboard and Wacom tablet.
/Magnus
---
drivers/input/evdev.c | 41 +++++++++++++++++------------------------
1 files changed, 17 insertions(+), 24 deletions(-)
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 12c7ab8..c7e741b 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -29,7 +29,7 @@ struct evdev {
char name[16];
struct input_handle handle;
wait_queue_head_t wait;
- struct evdev_list *grab;
+ int grab;
struct list_head list;
};
@@ -37,6 +37,7 @@ struct evdev_list {
struct input_event buffer[EVDEV_BUFFER_SIZE];
int head;
int tail;
+ int grab;
struct fasync_struct *fasync;
struct evdev *evdev;
struct list_head node;
@@ -49,8 +50,7 @@ static void evdev_event(struct input_han
struct evdev *evdev = handle->private;
struct evdev_list *list;
- if (evdev->grab) {
- list = evdev->grab;
+ list_for_each_entry(list, &evdev->list, node) {
do_gettimeofday(&list->buffer[list->head].time);
list->buffer[list->head].type = type;
@@ -59,17 +59,7 @@ static void evdev_event(struct input_han
list->head = (list->head + 1) & (EVDEV_BUFFER_SIZE - 1);
kill_fasync(&list->fasync, SIGIO, POLL_IN);
- } else
- list_for_each_entry(list, &evdev->list, node) {
-
- do_gettimeofday(&list->buffer[list->head].time);
- list->buffer[list->head].type = type;
- list->buffer[list->head].code = code;
- list->buffer[list->head].value = value;
- list->head = (list->head + 1) & (EVDEV_BUFFER_SIZE - 1);
-
- kill_fasync(&list->fasync, SIGIO, POLL_IN);
- }
+ }
wake_up_interruptible(&evdev->wait);
}
@@ -104,9 +94,10 @@ static int evdev_release(struct inode *
{
struct evdev_list *list = file->private_data;
- if (list->evdev->grab == list) {
- input_release_device(&list->evdev->handle);
- list->evdev->grab = NULL;
+ if (list->grab) {
+ if(!--list->evdev->grab && list->evdev->exist)
+ input_release_device(&list->evdev->handle);
+ list->grab = 0;
}
evdev_fasync(-1, file, 0);
@@ -483,17 +474,19 @@ static long evdev_ioctl_handler(struct f
case EVIOCGRAB:
if (p) {
- if (evdev->grab)
- return -EBUSY;
- if (input_grab_device(&evdev->handle))
+ if (list->grab)
return -EBUSY;
- evdev->grab = list;
+ if (!evdev->grab++)
+ if (input_grab_device(&evdev->handle))
+ return -EBUSY;
+ list->grab = 0;
return 0;
} else {
- if (evdev->grab != list)
+ if (!list->grab)
return -EINVAL;
- input_release_device(&evdev->handle);
- evdev->grab = NULL;
+ if (!--evdev->grab)
+ input_release_device(&evdev->handle);
+ list->grab = 0;
return 0;
}
prev parent reply other threads:[~2006-08-15 23:20 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-12 15:24 input: evdev.c EVIOCGRAB semantics question Magnus Vigerlöf
2006-08-12 16:52 ` Zephaniah E. Hull
2006-08-12 21:06 ` Magnus Vigerlöf
2006-08-13 0:00 ` Dmitry Torokhov
2006-08-13 3:28 ` Zephaniah E. Hull
2006-08-14 14:20 ` Dmitry Torokhov
2006-08-14 14:28 ` Zephaniah E. Hull
2006-08-14 15:00 ` Dmitry Torokhov
2006-08-14 16:04 ` Ian Stirling
2006-08-14 16:09 ` Zephaniah E. Hull
2006-08-14 16:22 ` Dmitry Torokhov
2006-08-14 14:58 ` Mattia Dongili
2006-08-14 15:15 ` Dmitry Torokhov
2006-08-14 22:49 ` Magnus Vigerlöf
2006-08-15 11:51 ` Magnus Vigerlöf
2006-08-15 23:20 ` Magnus Vigerlöf [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200608160120.03398.wigge@bigfoot.com \
--to=wigge@bigfoot.com \
--cc=dmitry.torokhov@gmail.com \
--cc=dtor@insightbb.com \
--cc=linux-input@atrey.karlin.mff.cuni.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=vojtech@suse.cz \
--cc=warp@aehallh.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.