rpms/xorg-x11-drv-evdev/F-10 evdev-2.0.7-store-minmaj.patch, NONE, 1.1 xorg-x11-drv-evdev.spec, 1.35, 1.36
Peter Hutterer
whot at fedoraproject.org
Tue Oct 21 04:13:17 UTC 2008
Author: whot
Update of /cvs/pkgs/rpms/xorg-x11-drv-evdev/F-10
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv30658
Modified Files:
xorg-x11-drv-evdev.spec
Added Files:
evdev-2.0.7-store-minmaj.patch
Log Message:
* Tue Oct 21 2008 Peter Hutterer <peter.hutterer at redhat.com> 2.0.7-2
- evdev-2.0.7-store-minmaj.patch: store minor/major of device node to guard
against duplicates.
evdev-2.0.7-store-minmaj.patch:
--- NEW FILE evdev-2.0.7-store-minmaj.patch ---
diff -up ./src.orig ./src
diff -up ./src.orig/evdev.c ./src/evdev.c
--- ./src.orig/evdev.c 2008-10-21 14:13:38.000000000 +1030
+++ ./src/evdev.c 2008-10-21 14:16:23.000000000 +1030
@@ -33,6 +33,7 @@
#include <X11/XF86keysym.h>
#include <X11/extensions/XIproto.h>
+#include <sys/stat.h>
#include <unistd.h>
#include <misc.h>
@@ -43,6 +44,7 @@
#include <exevents.h>
#include <mipointer.h>
#include <xorgVersion.h>
+#include <inputstr.h> /* For MAX_DEVICES */
#include "evdev.h"
@@ -51,6 +53,7 @@
#include <errno.h>
#include <fcntl.h>
+
/* 2.4 compatibility */
#ifndef EVIOCGRAB
#define EVIOCGRAB _IOW('E', 0x90, int)
@@ -89,6 +92,88 @@
#define MODEFLAG 8
#define COMPOSEFLAG 16
+/* All devices the evdev driver has allocated and knows about.
+ * MAX_DEVICES is safe as null-terminated array, as two devices (VCP and VCK)
+ * cannot be used by evdev, leaving us with a space of 2 at the end. */
+static EvdevPtr evdev_devices[MAX_DEVICES] = {0};
+
+static int
+EvdevGetMajorMinor(InputInfoPtr pInfo)
+{
+ struct stat st;
+
+ if (fstat(pInfo->fd, &st) == -1)
+ {
+ xf86Msg(X_ERROR, "%s: stat failed (%s). cannot check for duplicates.\n",
+ pInfo->name, strerror(errno));
+ return 0;
+ }
+
+ return st.st_rdev;
+}
+
+/**
+ * Return TRUE if one of the devices we know about has the same min/maj
+ * number.
+ */
+static BOOL
+EvdevIsDuplicate(InputInfoPtr pInfo)
+{
+ EvdevPtr pEvdev = pInfo->private;
+ EvdevPtr* dev = evdev_devices;
+
+ if (pEvdev->min_maj)
+ {
+ while(*dev)
+ {
+ if ((*dev) != pEvdev &&
+ (*dev)->min_maj &&
+ (*dev)->min_maj == pEvdev->min_maj)
+ return TRUE;
+ dev++;
+ }
+ }
+ return FALSE;
+}
+
+/**
+ * Add to internal device list.
+ */
+static void
+EvdevAddDevice(InputInfoPtr pInfo)
+{
+ EvdevPtr pEvdev = pInfo->private;
+ EvdevPtr* dev = evdev_devices;
+
+ while(*dev)
+ dev++;
+
+ *dev = pEvdev;
+}
+
+/**
+ * Remove from internal device list.
+ */
+static void
+EvdevRemoveDevice(InputInfoPtr pInfo)
+{
+ EvdevPtr pEvdev = pInfo->private;
+ EvdevPtr *dev = evdev_devices;
+ int count = 0;
+
+ while(*dev)
+ {
+ count++;
+ if (*dev == pEvdev)
+ {
+ memmove(dev, dev + 1,
+ sizeof(evdev_devices) - (count * sizeof(EvdevPtr)));
+ break;
+ }
+ dev++;
+ }
+}
+
static const char *evdevDefaults[] = {
"XkbRules", "evdev",
@@ -192,6 +277,7 @@ EvdevReopenTimer(OsTimerPtr timer, CARD3
DisableDevice(pInfo->dev);
close(pInfo->fd);
pInfo->fd = -1;
+ pEvdev->min_maj = 0; /* don't hog the device */
}
pEvdev->reopen_left = 0;
return 0;
@@ -204,6 +290,7 @@ EvdevReopenTimer(OsTimerPtr timer, CARD3
xf86Msg(X_ERROR, "%s: Failed to reopen device after %d attempts.\n",
pInfo->name, pEvdev->reopen_attempts);
DisableDevice(pInfo->dev);
+ pEvdev->min_maj = 0; /* don't hog the device */
return 0;
}
@@ -935,6 +1022,14 @@ EvdevOn(DeviceIntPtr device)
pEvdev->reopen_timer = TimerSet(NULL, 0, 100, EvdevReopenTimer, pInfo);
} else
{
+ pEvdev->min_maj = EvdevGetMajorMinor(pInfo);
+ if (EvdevIsDuplicate(pInfo))
+ {
+ xf86Msg(X_WARNING, "%s: Refusing to enable duplicate device.\n",
+ pInfo->name);
+ return !Success;
+ }
+
xf86AddEnabledDevice(pInfo);
if ((pEvdev->flags & EVDEV_BUTTON_EVENTS) &&
!(pEvdev->flags & EVDEV_INITIALIZED))
@@ -976,6 +1071,7 @@ EvdevProc(DeviceIntPtr device, int what)
close(pInfo->fd);
pInfo->fd = -1;
}
+ pEvdev->min_maj = 0;
if (pEvdev->flags & EVDEV_INITIALIZED)
EvdevMBEmuFinalize(pInfo);
pEvdev->flags &= ~EVDEV_INITIALIZED;
@@ -993,6 +1089,8 @@ EvdevProc(DeviceIntPtr device, int what)
close(pInfo->fd);
pInfo->fd = -1;
}
+ EvdevRemoveDevice(pInfo);
+ pEvdev->min_maj = 0;
break;
}
@@ -1303,6 +1401,17 @@ EvdevPreInit(InputDriverPtr drv, IDevPtr
return NULL;
}
+ /* Check major/minor of device node to avoid adding duplicate devices. */
+ pEvdev->min_maj = EvdevGetMajorMinor(pInfo);
+ if (EvdevIsDuplicate(pInfo))
+ {
+ xf86Msg(X_WARNING, "%s: device file already in use. Ignoring.\n",
+ pInfo->name);
+ close(pInfo->fd);
+ xf86DeleteInput(pInfo, 0);
+ return NULL;
+ }
+
pEvdev->reopen_attempts = xf86SetIntOption(pInfo->options, "ReopenAttempts", 10);
/* Grabbing the event device stops in-kernel event forwarding. In other
@@ -1320,6 +1429,7 @@ EvdevPreInit(InputDriverPtr drv, IDevPtr
}
EvdevCacheCompare(pInfo, FALSE); /* cache device data */
+ EvdevAddDevice(pInfo);
return pInfo;
}
diff -up ./src/evdev.h.orig ./src/evdev.h
--- ./src/evdev.h.orig 2008-10-21 14:22:40.000000000 +1030
+++ ./src/evdev.h 2008-10-21 14:23:03.000000000 +1030
@@ -31,6 +31,7 @@
#define EVDEV_H
#include <linux/input.h>
+#include <linux/types.h>
#include <xf86Xinput.h>
#include <xf86_OSproc.h>
@@ -83,6 +84,9 @@ typedef struct {
long abs_bitmask[NBITS(ABS_MAX)];
long led_bitmask[NBITS(LED_MAX)];
struct input_absinfo absinfo[ABS_MAX];
+
+ /* minor/major number */
+ dev_t min_maj;
} EvdevRec, *EvdevPtr;
/* Middle Button emulation */
Index: xorg-x11-drv-evdev.spec
===================================================================
RCS file: /cvs/pkgs/rpms/xorg-x11-drv-evdev/F-10/xorg-x11-drv-evdev.spec,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- xorg-x11-drv-evdev.spec 17 Oct 2008 01:21:09 -0000 1.35
+++ xorg-x11-drv-evdev.spec 21 Oct 2008 04:12:46 -0000 1.36
@@ -7,7 +7,7 @@
Summary: Xorg X11 evdev input driver
Name: xorg-x11-drv-evdev
Version: 2.0.7
-Release: 1%{?dist}
+Release: 2%{?dist}
URL: http://www.x.org
License: MIT
Group: User Interface/X Hardware Support
@@ -22,6 +22,7 @@
# Not upstream until matching xserver commit is upstream. Won't be in 2.0
# branch anyway.
Patch0002: evdev-2.0.6-dont-grab.patch
+Patch0003: evdev-2.0.7-store-minmaj.patch
ExcludeArch: s390 s390x
@@ -41,6 +42,7 @@
# apply patches
%patch0001 -p1 -b .rules-evdev
%patch0002 -p1 -b .dont-grab
+%patch0003 -p1 -b .store-minmaj
%build
autoreconf -v --install || exit 1
@@ -65,6 +67,10 @@
%{_mandir}/man4/evdev.4*
%changelog
+* Tue Oct 21 2008 Peter Hutterer <peter.hutterer at redhat.com> 2.0.7-2
+- evdev-2.0.7-store-minmaj.patch: store minor/major of device node to guard
+ against duplicates.
+
* Fri Oct 17 2008 Peter Hutterer <peter.hutterer at redhat.com> 2.0.7-1
- update to 2.0.7
More information about the scm-commits
mailing list