os: Allow re-registering fd with InputThreadRegisterDev

Calling InputThreadRegisterDev twice with the same fd should replace
the existing function and args instead of creating a new entry with
the same fd.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Keith Packard 2016-08-11 12:34:54 -07:00 committed by Peter Hutterer
parent 2df2815d6a
commit bf31d6f43e

View File

@ -188,24 +188,38 @@ InputThreadRegisterDev(int fd,
NotifyFdProcPtr readInputProc, NotifyFdProcPtr readInputProc,
void *readInputArgs) void *readInputArgs)
{ {
InputThreadDevice *dev; InputThreadDevice *dev, *old;
if (!inputThreadInfo) if (!inputThreadInfo)
return SetNotifyFd(fd, readInputProc, X_NOTIFY_READ, readInputArgs); return SetNotifyFd(fd, readInputProc, X_NOTIFY_READ, readInputArgs);
dev = calloc(1, sizeof(InputThreadDevice)); input_lock();
if (dev == NULL) {
DebugF("input-thread: could not register device\n"); dev = NULL;
return 0; xorg_list_for_each_entry(old, &inputThreadInfo->devs, node) {
if (old->fd == fd) {
dev = old;
break;
}
} }
dev->fd = fd; if (dev) {
dev->readInputProc = readInputProc; dev->readInputProc = readInputProc;
dev->readInputArgs = readInputArgs; dev->readInputArgs = readInputArgs;
dev->state = device_state_added; } else {
dev = calloc(1, sizeof(InputThreadDevice));
if (dev == NULL) {
DebugF("input-thread: could not register device\n");
input_unlock();
return 0;
}
input_lock(); dev->fd = fd;
xorg_list_append(&dev->node, &inputThreadInfo->devs); dev->readInputProc = readInputProc;
dev->readInputArgs = readInputArgs;
dev->state = device_state_added;
xorg_list_append(&dev->node, &inputThreadInfo->devs);
}
inputThreadInfo->changed = TRUE; inputThreadInfo->changed = TRUE;