--- vdr-plugin-remote-0.3.3.orig/remote.c +++ vdr-plugin-remote-0.3.3/remote.c @@ -174,7 +174,7 @@ // -1 - error // // --------------------------------------------------------------------------- -int identifyInputDevice(const int fh, char *name) +int identifyInputDevice(const int fh, const char *name) // --------------------------------------------------------------------------- { char description[256]; @@ -651,6 +651,23 @@ } +class cListString : public cListObject +{ +private: + cString *content; +public: + cListString (const char *obj) { content = new cString (obj); } + ~cListString () { delete content; } + int Compare (const cListObject &obj) const; + const cString& Get () { return *content; } +}; + +int cListString::Compare (const cListObject &obj) const +{ + return strcmp (**content, **((const cListString &)obj).content); +} + + // --------------------------------------------------------------------------- bool cPluginRemote::Start(void) // --------------------------------------------------------------------------- @@ -668,17 +685,59 @@ devcnt = 1; } + cList devices; + + DIR *dir = opendir ("/dev/input"); + if (!dir) + { + esyslog ("%s: unable to open '%s': %s", + Name (), "/dev/input", strerror (errno)); + return false; + } + + long devmin = INT_MAX; + for (;;) + { + dirent obj, *ret; + int err = readdir_r (dir, &obj, &ret); + if (err) + { + esyslog ("%s: unable to read '%s': %s", + Name (), "/dev/input", strerror (errno)); + closedir (dir); + return false; + } + if (!ret) + break; + + if (strncmp (obj.d_name, "event", 5)) + continue; + + long j; + char *end; + j = strtol (obj.d_name + 5, &end, 10); + if (j < 0 || end == obj.d_name || *end) + continue; + + // keep track of the lowest device number (in case it's not 0) + if (j < devmin) + devmin = j; + + devices.Add (new cListString (cString::sprintf ("/dev/input/%s", obj.d_name))); + } + closedir (dir); + + devices.Sort (); + /* probe eventX devices */ for (int i = 0; i < devcnt; i++) { if (devtyp[i] == 'i' && strcmp(devnam[i], "autodetect") == 0) { - char nam[80]; - for (int j = 0; ; j++) + for (cListString *dev = devices.First (); dev; dev = devices.Next (dev)) { - sprintf(nam, "/dev/input/event%d", j); - fh[i] = open(nam, O_RDONLY); + fh[i] = open(dev->Get (), O_RDONLY); if (fh[i] < 0) { switch (errno) @@ -691,22 +750,23 @@ break; } - if (identifyInputDevice(fh[i], nam) >= 1) + if (identifyInputDevice(fh[i], dev->Get ()) >= 1) { // found DVB card receiver - devnam[i] = strdup(nam); + devnam[i] = strdup(dev->Get ()); close(fh[i]); + devices.Del (dev); break; } // unknown device, try next one close(fh[i]); - } // for j + } // for each (remaining) eventX } // if autodetect // use default device if nothing could be identified if (devtyp[i] == 'i' && strcmp(devnam[i], "autodetect") == 0) - devnam[i] = "/dev/input/event0"; + asprintf (&devnam[i], "/dev/input/event%ld", devmin); } // for i for (int i = 0; i < devcnt; i++)