chiark / gitweb /
add DEVLINKS to the event environment
authorKay Sievers <kay.sievers@suse.de>
Sat, 17 Dec 2005 15:20:51 +0000 (16:20 +0100)
committerKay Sievers <kay.sievers@suse.de>
Sat, 17 Dec 2005 15:20:51 +0000 (16:20 +0100)
Multiple symlinks are separated by a space character.

Signed-off-by: Kay Sievers <kay.sievers@suse.de>
RELEASE-NOTES
udev.h
udev_add.c
udev_event.c
udev_remove.c
udevstart.c

index 4006e510d757093256af920094bf359cfd0f5fa2..19af28fb66a719a1075c918a60781e1f3c6c35e3 100644 (file)
@@ -1,3 +1,13 @@
+udev 078
+========
+Symlinks are now exported to the event environment. Hopefully it's no
+longer needed to run udevinfo from an event process, like it was
+mentioned on the hotplug list:
+  UDEV  [1134776873.702967] add@/block/sdb
+  ...
+  DEVNAME=/dev/sdb
+  DEVLINKS=/dev/disk/by-id/usb-IBM_Memory_Key_0218B301030027E8 /dev/disk/by-path/usb-0218B301030027E8:0:0:0
+
 udev 077
 ========
 Fix a problem if udevsend is used as the hotplug handler and tries to use
 udev 077
 ========
 Fix a problem if udevsend is used as the hotplug handler and tries to use
diff --git a/udev.h b/udev.h
index 474f3f5e2586c7365df96070b690660a08a9ce4e..ca99da512d9d0f06d35f7f2eb4220cf27b1977f9 100644 (file)
--- a/udev.h
+++ b/udev.h
@@ -58,7 +58,6 @@ struct udevice {
 
        enum device_type type;
        char name[PATH_SIZE];
 
        enum device_type type;
        char name[PATH_SIZE];
-       char devname[PATH_SIZE];
        struct list_head symlink_list;
        int symlink_final;
        char owner[USER_SIZE];
        struct list_head symlink_list;
        int symlink_final;
        char owner[USER_SIZE];
index 174474bdc703a1bf0e6adb966979afd5b0635653..bf2d59d1989900c7e05f62d339d7a949233dac56 100644 (file)
@@ -108,7 +108,6 @@ exit:
 static int create_node(struct udevice *udev, struct sysfs_class_device *class_dev)
 {
        char filename[PATH_SIZE];
 static int create_node(struct udevice *udev, struct sysfs_class_device *class_dev)
 {
        char filename[PATH_SIZE];
-       char partitionname[PATH_SIZE];
        struct name_entry *name_loop;
        uid_t uid;
        gid_t gid;
        struct name_entry *name_loop;
        uid_t uid;
        gid_t gid;
@@ -152,6 +151,7 @@ static int create_node(struct udevice *udev, struct sysfs_class_device *class_de
                info("creating device node '%s'", filename);
                if (udev_make_node(udev, filename, udev->devt, udev->mode, uid, gid) != 0)
                        goto error;
                info("creating device node '%s'", filename);
                if (udev_make_node(udev, filename, udev->devt, udev->mode, uid, gid) != 0)
                        goto error;
+               setenv("DEVNAME", filename, 1);
        } else {
                info("creating device node '%s', major = '%d', minor = '%d', "
                     "mode = '%#o', uid = '%d', gid = '%d'", filename,
        } else {
                info("creating device node '%s', major = '%d', minor = '%d', "
                     "mode = '%#o', uid = '%d', gid = '%d'", filename,
@@ -160,6 +160,7 @@ static int create_node(struct udevice *udev, struct sysfs_class_device *class_de
 
        /* create all_partitions if requested */
        if (udev->partitions) {
 
        /* create all_partitions if requested */
        if (udev->partitions) {
+               char partitionname[PATH_SIZE];
                struct sysfs_attribute *attr;
                int range;
 
                struct sysfs_attribute *attr;
                int range;
 
@@ -184,45 +185,55 @@ static int create_node(struct udevice *udev, struct sysfs_class_device *class_de
        }
 
        /* create symlink(s) if requested */
        }
 
        /* create symlink(s) if requested */
-       list_for_each_entry(name_loop, &udev->symlink_list, node) {
-               int retval;
-               char linktarget[PATH_SIZE];
-
-               snprintf(filename, sizeof(filename), "%s/%s", udev_root, name_loop->name);
-               filename[sizeof(filename)-1] = '\0';
-
-               dbg("symlink '%s' to node '%s' requested", filename, udev->name);
-               if (!udev->test_run)
-                       if (strchr(filename, '/'))
-                               create_path(filename);
-
-               /* optimize relative link */
-               linktarget[0] = '\0';
-               i = 0;
-               tail = 0;
-               while (udev->name[i] && (udev->name[i] == name_loop->name[i])) {
-                       if (udev->name[i] == '/')
-                               tail = i+1;
-                       i++;
-               }
-               while (name_loop->name[i] != '\0') {
-                       if (name_loop->name[i] == '/')
-                               strlcat(linktarget, "../", sizeof(linktarget));
-                       i++;
-               }
+       if (!list_empty(&udev->symlink_list)) {
+               char symlinks[512] = "";
+
+               list_for_each_entry(name_loop, &udev->symlink_list, node) {
+                       int retval;
+                       char linktarget[PATH_SIZE];
+
+                       snprintf(filename, sizeof(filename), "%s/%s", udev_root, name_loop->name);
+                       filename[sizeof(filename)-1] = '\0';
+
+                       dbg("symlink '%s' to node '%s' requested", filename, udev->name);
+                       if (!udev->test_run)
+                               if (strchr(filename, '/'))
+                                       create_path(filename);
+
+                       /* optimize relative link */
+                       linktarget[0] = '\0';
+                       i = 0;
+                       tail = 0;
+                       while (udev->name[i] && (udev->name[i] == name_loop->name[i])) {
+                               if (udev->name[i] == '/')
+                                       tail = i+1;
+                               i++;
+                       }
+                       while (name_loop->name[i] != '\0') {
+                               if (name_loop->name[i] == '/')
+                                       strlcat(linktarget, "../", sizeof(linktarget));
+                               i++;
+                       }
 
 
-               strlcat(linktarget, &udev->name[tail], sizeof(linktarget));
+                       strlcat(linktarget, &udev->name[tail], sizeof(linktarget));
+
+                       info("creating symlink '%s' to '%s'", filename, linktarget);
+                       if (!udev->test_run) {
+                               unlink(filename);
+                               selinux_setfscreatecon(filename, NULL, S_IFLNK);
+                               retval = symlink(linktarget, filename);
+                               selinux_resetfscreatecon();
+                               if (retval != 0)
+                                       err("symlink(%s, %s) failed: %s",
+                                           linktarget, filename, strerror(errno));
+                       }
 
 
-               info("creating symlink '%s' to '%s'", filename, linktarget);
-               if (!udev->test_run) {
-                       unlink(filename);
-                       selinux_setfscreatecon(filename, NULL, S_IFLNK);
-                       retval = symlink(linktarget, filename);
-                       selinux_resetfscreatecon();
-                       if (retval != 0)
-                               err("symlink(%s, %s) failed: %s",
-                                   linktarget, filename, strerror(errno));
+                       strlcat(symlinks, filename, sizeof(symlinks));
+                       strlcat(symlinks, " ", sizeof(symlinks));
                }
                }
+
+               remove_trailing_chars(symlinks, ' ');
+               setenv("DEVLINKS", symlinks, 1);
        }
 
        return 0;
        }
 
        return 0;
@@ -273,11 +284,6 @@ int udev_add_device(struct udevice *udev, struct sysfs_class_device *class_dev)
 
                if (udev_db_add_device(udev) != 0)
                        dbg("udev_db_add_dev failed, remove might not work for custom names");
 
                if (udev_db_add_device(udev) != 0)
                        dbg("udev_db_add_dev failed, remove might not work for custom names");
-
-               /* use full path to the environment */
-               snprintf(udev->devname, sizeof(udev->devname), "%s/%s", udev_root, udev->name);
-               udev->devname[sizeof(udev->devname)-1] = '\0';
-
        } else if (udev->type == DEV_NET) {
                /* look if we want to change the name of the netif */
                if (strcmp(udev->name, udev->kernel_name) != 0) {
        } else if (udev->type == DEV_NET) {
                /* look if we want to change the name of the netif */
                if (strcmp(udev->name, udev->kernel_name) != 0) {
@@ -298,9 +304,6 @@ int udev_add_device(struct udevice *udev, struct sysfs_class_device *class_dev)
                                setenv("DEVPATH", udev->devpath, 1);
                                setenv("INTERFACE", udev->name, 1);
                        }
                                setenv("DEVPATH", udev->devpath, 1);
                                setenv("INTERFACE", udev->name, 1);
                        }
-
-                       /* use netif name for the environment */
-                       strlcpy(udev->devname, udev->name, sizeof(udev->devname));
                }
        }
 
                }
        }
 
index 0b4b9dc4957188c9c877487db91fc710aedaec46..887537e0e97770c1a11dcf05e904c482e9a9722c 100644 (file)
@@ -130,10 +130,6 @@ int udev_process_event(struct udev_rules *rules, struct udevice *udev)
                                return 0;
                        }
                }
                                return 0;
                        }
                }
-
-               /* export name of device node or netif */
-               if (udev->devname[0] != '\0')
-                       setenv("DEVNAME", udev->devname, 1);
        } else if (udev->type == DEV_DEVICE && strcmp(udev->action, "add") == 0) {
                struct sysfs_device *devices_dev;
 
        } else if (udev->type == DEV_DEVICE && strcmp(udev->action, "add") == 0) {
                struct sysfs_device *devices_dev;
 
index 6efa17eb7c7957cf4aaf6f97e7d2b4e7cf2245f8..f9592b4c701a93cf432e5cc2f8147b25ab92ec22 100644 (file)
@@ -37,6 +37,7 @@
 static int delete_node(struct udevice *udev)
 {
        char filename[PATH_SIZE];
 static int delete_node(struct udevice *udev)
 {
        char filename[PATH_SIZE];
+       char devname[PATH_SIZE];
        char partitionname[PATH_SIZE];
        struct name_entry *name_loop;
        struct stat stats;
        char partitionname[PATH_SIZE];
        struct name_entry *name_loop;
        struct stat stats;
@@ -81,9 +82,9 @@ static int delete_node(struct udevice *udev)
        if (retval)
                return retval;
 
        if (retval)
                return retval;
 
-       /* export DEVNAME to the environment */
-       snprintf(udev->devname, sizeof(udev->devname), "%s/%s", udev_root, udev->name);
-       udev->devname[sizeof(udev->devname)-1] = '\0';
+       snprintf(devname, sizeof(devname), "%s/%s", udev_root, udev->name);
+       devname[sizeof(devname)-1] = '\0';
+       setenv("DEVNAME", devname, 1);
 
        num = udev->partitions;
        if (num > 0) {
 
        num = udev->partitions;
        if (num > 0) {
index 11063f67991ce23e23ed6fbea3a82dcbe7f70bfc..a9959c5d6b85cb631106addf567d0af81c242747 100644 (file)
@@ -155,8 +155,6 @@ static int add_device(const char *devpath, const char *subsystem)
        }
 
        udev_add_device(&udev, class_dev);
        }
 
        udev_add_device(&udev, class_dev);
-       if (udev.devname[0] != '\0')
-               setenv("DEVNAME", udev.devname, 1);
 run:
        if (udev_run && !list_empty(&udev.run_list)) {
                struct name_entry *name_loop;
 run:
        if (udev_run && !list_empty(&udev.run_list)) {
                struct name_entry *name_loop;