]> err.no Git - systemd/commitdiff
do not create temporary node ($tempnode) if node already exists
authorKay Sievers <kay.sievers@vrfy.org>
Wed, 22 Oct 2008 23:13:52 +0000 (01:13 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Wed, 22 Oct 2008 23:13:52 +0000 (01:13 +0200)
TODO
udev/udev-event.c

diff --git a/TODO b/TODO
index fd9b2be563491946add41847303ca2879bc66437..b4a967c2580a52ae896823eec96dea2c415646fc 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,4 +1,3 @@
-  o use node for tmpnode, if it already exists
   o add DVB variables to kernel, and drop shell script rule
   o DEVTYPE for disks is set by the kernel, they will be removed from
     the default rules
index b41dcd070ef285792c01b9a78cea022dafd4d958..a41d4edb41dc5994db555b9b81d89ec24bddfe00 100644 (file)
@@ -332,15 +332,41 @@ found:
                        }
                        break;
                case SUBST_TEMP_NODE:
-                       if (event->tmp_node[0] == '\0' && major(udev_device_get_devnum(dev)) > 0) {
-                               dbg(event->udev, "create temporary device node for callout\n");
-                               snprintf(event->tmp_node, sizeof(event->tmp_node), "%s/.tmp-%u-%u",
-                                        udev_get_dev_path(event->udev),
-                                        major(udev_device_get_devnum(dev)), minor(udev_device_get_devnum(dev)));
-                               udev_node_mknod(dev, event->tmp_node, makedev(0,0), 0600, 0, 0);
+                       {
+                               dev_t devnum;
+                               struct stat statbuf;
+                               char filename[UTIL_PATH_SIZE];
+                               const char *devtype;
+
+                               if (event->tmp_node[0] != '\0') {
+                                       util_strlcat(string, event->tmp_node, maxsize);
+                                       dbg(event->udev, "return existing temporary node\n");
+                                       break;
+                               }
+                               devnum = udev_device_get_devnum(dev);
+                               if (major(udev_device_get_devnum(dev) == 0))
+                                       break;
+                               if (strcmp(udev_device_get_subsystem(dev), "block") == 0)
+                                       devtype = "block";
+                               else
+                                       devtype = "char";
+                               snprintf(filename, sizeof(filename), "%s/%s/%u:%u",
+                                        udev_get_dev_path(event->udev), devtype,
+                                        major(udev_device_get_devnum(dev)),
+                                        minor(udev_device_get_devnum(dev)));
+                               if (stat(filename, &statbuf) == 0 && statbuf.st_rdev == devnum) {
+                                       util_strlcat(string, filename, maxsize);
+                                       dbg(event->udev, "return existing temporary node\n");
+                                       break;
+                               }
+                               dbg(event->udev, "create temporary node\n");
+                               snprintf(event->tmp_node, sizeof(event->tmp_node), "%s/.tmp-%s-%u:%u",
+                                        udev_get_dev_path(event->udev), devtype,
+                                        major(udev_device_get_devnum(dev)),
+                                        minor(udev_device_get_devnum(dev)));
+                               udev_node_mknod(dev, event->tmp_node, makedev(0, 0), 0600, 0, 0);
+                               util_strlcat(string, event->tmp_node, maxsize);
                        }
-                       util_strlcat(string, event->tmp_node, maxsize);
-                       dbg(event->udev, "substitute temporary device node name '%s'\n", event->tmp_node);
                        break;
                case SUBST_NAME:
                        if (event->name != NULL) {