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 4006e51..19af28f 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
diff --git a/udev.h b/udev.h
index 474f3f5..ca99da5 100644 (file)
--- a/udev.h
+++ b/udev.h
@@ -58,7 +58,6 @@ struct udevice {
 
        enum device_type type;
        char name[PATH_SIZE];
-       char devname[PATH_SIZE];
        struct list_head symlink_list;
        int symlink_final;
        char owner[USER_SIZE];
index 174474b..bf2d59d 100644 (file)
@@ -108,7 +108,6 @@ exit:
 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;
@@ -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;
+               setenv("DEVNAME", filename, 1);
        } 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) {
+               char partitionname[PATH_SIZE];
                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 */
-       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;
@@ -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");
-
-               /* 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) {
@@ -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);
                        }
-
-                       /* use netif name for the environment */
-                       strlcpy(udev->devname, udev->name, sizeof(udev->devname));
                }
        }
 
index 0b4b9dc..887537e 100644 (file)
@@ -130,10 +130,6 @@ int udev_process_event(struct udev_rules *rules, struct udevice *udev)
                                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;
 
index 6efa17e..f9592b4 100644 (file)
@@ -37,6 +37,7 @@
 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;
@@ -81,9 +82,9 @@ static int delete_node(struct udevice *udev)
        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) {
index 11063f6..a9959c5 100644 (file)
@@ -155,8 +155,6 @@ static int add_device(const char *devpath, const char *subsystem)
        }
 
        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;