This is an automatic generated email to let you know that the following patch 
were queued at the 
http://git.linuxtv.org/cgit.cgi/v4l-utils.git tree:

Subject: v4l2-ctl: look in /sys/dev/char instead of /dev/char
Author:  Hans Verkuil <[email protected]>
Date:    Fri Aug 21 10:25:02 2026 +0200

Sometimes /dev/char/ is not populated, while /sys/dev/char is.
This causes failures in the virtme regression tests.

Only v4l2-ctl uses /dev/char, the other utilities use /sys/dev/char.
So align with that.

Signed-off-by: Hans Verkuil <[email protected]>

 utils/v4l2-ctl/v4l2-ctl.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 46 insertions(+), 3 deletions(-)

---

http://git.linuxtv.org/cgit.cgi/v4l-utils.git/commit/?id=5b3d43f8ba5663a2f7c84777e24e579cc70e64f5
diff --git a/utils/v4l2-ctl/v4l2-ctl.cpp b/utils/v4l2-ctl/v4l2-ctl.cpp
index 14f5c51fc070..6afb572c9d7c 100644
--- a/utils/v4l2-ctl/v4l2-ctl.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl.cpp
@@ -26,6 +26,9 @@
 #include <dirent.h>
 #include <getopt.h>
 #include <sys/epoll.h>
+#include <sys/sysmacros.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 
 #include <linux/media.h>
 
@@ -1053,6 +1056,13 @@ static int open_media_bus_info(const std::string 
&bus_info)
 static const char *make_devname(const char *device, const char *devname,
                                      const std::string &media_bus_info)
 {
+       static char newdev[32];
+       char sysname[32];
+       char target[1024];
+       struct stat devstat;
+       char *p;
+       int ret;
+
        if (device[0] >= '0' && device[0] <= '9' && strlen(device) <= 3) {
                static char newdev[32];
 
@@ -1109,10 +1119,43 @@ static const char *make_devname(const char *device, 
const char *devname,
        if (i >= topology.num_interfaces)
                goto err;
 
-       static char newdev[32];
-       sprintf(newdev, "/dev/char/%d:%d",
+       sprintf(sysname, "/sys/dev/char/%d:%d",
                ifaces[i].devnode.major, ifaces[i].devnode.minor);
-       device = newdev;
+       ret = readlink(sysname, target, sizeof(target) - 1);
+       if (ret < 0)
+               goto err;
+
+       target[ret] = '\0';
+       p = strrchr(target, '/');
+       if (p == NULL)
+               return NULL;
+
+       sprintf(newdev, "/dev/%s", p + 1);
+       if (strstr(p + 1, "dvb")) {
+               char *s = p + 1;
+
+               if (strncmp(s, "dvb", 3))
+                       goto err;
+               s += 3;
+               p = strchr(s, '.');
+               if (!p)
+                       goto err;
+               *p = '/';
+               sprintf(newdev, "/dev/dvb/adapter%s", s);
+       } else {
+               sprintf(newdev, "/dev/%s", p + 1);
+       }
+       ret = stat(newdev, &devstat);
+       if (ret < 0)
+               goto err;
+
+       /* Sanity check: udev might have reordered the device nodes.
+        * Make sure the major/minor match. We should really use
+        * libudev.
+        */
+       if (major(devstat.st_rdev) == ifaces[i].devnode.major &&
+           minor(devstat.st_rdev) == ifaces[i].devnode.minor)
+               device = newdev;
 
 err:
        delete [] ents;
_______________________________________________
linuxtv-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to