[PATCH xorg-gtest 3/6] device: split device comparison into a helper function

Peter Hutterer peter.hutterer at who-t.net
Wed Aug 29 15:29:01 PDT 2012


On Wed, Aug 29, 2012 at 01:07:31PM -0700, Chase Douglas wrote:
> On 08/28/2012 11:14 PM, Peter Hutterer wrote:
> >No functional changes, we'll re-use this though.
> >
> >Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> >---
> >  src/device.cpp | 38 +++++++++++++++++++++++---------------
> >  1 file changed, 23 insertions(+), 15 deletions(-)
> >
> >diff --git a/src/device.cpp b/src/device.cpp
> >index ffe33c6..5868036 100644
> >--- a/src/device.cpp
> >+++ b/src/device.cpp
> >@@ -62,6 +62,26 @@ static int _event_device_filter(const struct dirent *d) {
> >    return (strncmp("event", d->d_name, sizeof("event") - 1) == 0);
> >  }
> >
> >+static bool event_is_device(const std::string &path,
> >+                            const std::string &devname,
> >+                            time_t ctime) {
> >+    char device_name[256];
> >+    bool equal = false;
> >+    int fd = open(path.c_str(), O_RDONLY);
> 
> There's no error check here. It's possible that the path has ceased
> to exist or can't be opened for some other reason.

this is code that moved place, so I didn't fix this bit up in this patch,
it's fixed in patch 4/6. If need be, I can squash the two together.

Cheers,
   Peter

> In fact, in patch 6 there's the possibility of wait_for_notify()
> returning an empty string, which would be passed directly into this
> function.
> 
> >+
> >+    if (ioctl(fd, EVIOCGNAME(sizeof(device_name)), device_name) != -1 &&
> >+        devname.compare(device_name) == 0) {
> >+      struct stat buf;
> >+
> >+      if (fstat(fd, &buf) == 0)
> >+        if (buf.st_ctime >= ctime)
> >+          equal = true;
> >+    }
> >+    close(fd);
> >+
> >+    return equal;
> >+}
> >+
> >  void xorg::testing::evemu::Device::GuessDeviceNode(time_t ctime) {
> >    struct dirent **event_devices = NULL;
> >    int n_event_devices;
> >@@ -73,21 +93,9 @@ void xorg::testing::evemu::Device::GuessDeviceNode(time_t ctime) {
> >    for (int i = 0; i < n_event_devices && !found; i++) {
> >      std::stringstream s;
> >      s << DEV_INPUT_DIR << event_devices[i]->d_name;
> >-
> >-    int fd = open(s.str().c_str(), O_RDONLY);
> >-    char device_name[256];
> >-
> >-    if (ioctl(fd, EVIOCGNAME(sizeof(device_name)), device_name) != -1 &&
> >-        strcmp(device_name, evemu_get_name(d_->device)) == 0) {
> >-      struct stat buf;
> >-      if (fstat(fd, &buf) == 0) {
> >-        if (buf.st_ctime >= ctime) {
> >-          d_->device_node = s.str();
> >-          found = true;
> >-        }
> >-      }
> >-    }
> >-    close(fd);
> >+    found = event_is_device(s.str(), evemu_get_name(d_->device), ctime);
> >+    if (found)
> >+      d_->device_node = s.str();
> >    }
> >
> >    if (!found)
> >
> 


More information about the xorg-devel mailing list