summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@suse.de>2005-12-17 16:20:51 +0100
committerKay Sievers <kay.sievers@suse.de>2005-12-17 16:20:51 +0100
commitfb6e4c28248cdeed30a1d3eb42aba477f0429472 (patch)
tree7aa0023c85b989edb2face40b57523ec54aa1791
parentd2e7c6bf67b1b0d1f5d12ac533131c73bc046454 (diff)
add DEVLINKS to the event environment
Multiple symlinks are separated by a space character. Signed-off-by: Kay Sievers <kay.sievers@suse.de>
-rw-r--r--RELEASE-NOTES10
-rw-r--r--udev.h1
-rw-r--r--udev_add.c93
-rw-r--r--udev_event.c4
-rw-r--r--udev_remove.c7
-rw-r--r--udevstart.c2
6 files changed, 62 insertions, 55 deletions
diff --git a/RELEASE-NOTES b/RELEASE-NOTES
index 4006e510d7..19af28fb66 100644
--- a/RELEASE-NOTES
+++ b/RELEASE-NOTES
@@ -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 474f3f5e25..ca99da512d 100644
--- 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];
diff --git a/udev_add.c b/udev_add.c
index 174474bdc7..bf2d59d198 100644
--- a/udev_add.c
+++ b/udev_add.c
@@ -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));
}
}
diff --git a/udev_event.c b/udev_event.c
index 0b4b9dc495..887537e0e9 100644
--- a/udev_event.c
+++ b/udev_event.c
@@ -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;
diff --git a/udev_remove.c b/udev_remove.c
index 6efa17eb7c..f9592b4c70 100644
--- a/udev_remove.c
+++ b/udev_remove.c
@@ -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) {
diff --git a/udevstart.c b/udevstart.c
index 11063f6799..a9959c5d6b 100644
--- a/udevstart.c
+++ b/udevstart.c
@@ -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;