mirror of
https://github.com/AuxXxilium/eudev.git
synced 2024-12-16 19:47:24 +07:00
add DEVLINKS to the event environment
Multiple symlinks are separated by a space character. Signed-off-by: Kay Sievers <kay.sievers@suse.de>
This commit is contained in:
parent
d2e7c6bf67
commit
fb6e4c2824
@ -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
|
udev 077
|
||||||
========
|
========
|
||||||
Fix a problem if udevsend is used as the hotplug handler and tries to use
|
Fix a problem if udevsend is used as the hotplug handler and tries to use
|
||||||
|
1
udev.h
1
udev.h
@ -58,7 +58,6 @@ struct udevice {
|
|||||||
|
|
||||||
enum device_type type;
|
enum device_type type;
|
||||||
char name[PATH_SIZE];
|
char name[PATH_SIZE];
|
||||||
char devname[PATH_SIZE];
|
|
||||||
struct list_head symlink_list;
|
struct list_head symlink_list;
|
||||||
int symlink_final;
|
int symlink_final;
|
||||||
char owner[USER_SIZE];
|
char owner[USER_SIZE];
|
||||||
|
89
udev_add.c
89
udev_add.c
@ -108,7 +108,6 @@ exit:
|
|||||||
static int create_node(struct udevice *udev, struct sysfs_class_device *class_dev)
|
static int create_node(struct udevice *udev, struct sysfs_class_device *class_dev)
|
||||||
{
|
{
|
||||||
char filename[PATH_SIZE];
|
char filename[PATH_SIZE];
|
||||||
char partitionname[PATH_SIZE];
|
|
||||||
struct name_entry *name_loop;
|
struct name_entry *name_loop;
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
gid_t gid;
|
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);
|
info("creating device node '%s'", filename);
|
||||||
if (udev_make_node(udev, filename, udev->devt, udev->mode, uid, gid) != 0)
|
if (udev_make_node(udev, filename, udev->devt, udev->mode, uid, gid) != 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
setenv("DEVNAME", filename, 1);
|
||||||
} else {
|
} else {
|
||||||
info("creating device node '%s', major = '%d', minor = '%d', "
|
info("creating device node '%s', major = '%d', minor = '%d', "
|
||||||
"mode = '%#o', uid = '%d', gid = '%d'", filename,
|
"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 */
|
/* create all_partitions if requested */
|
||||||
if (udev->partitions) {
|
if (udev->partitions) {
|
||||||
|
char partitionname[PATH_SIZE];
|
||||||
struct sysfs_attribute *attr;
|
struct sysfs_attribute *attr;
|
||||||
int range;
|
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) {
|
if (!list_empty(&udev->symlink_list)) {
|
||||||
int retval;
|
char symlinks[512] = "";
|
||||||
char linktarget[PATH_SIZE];
|
|
||||||
|
|
||||||
snprintf(filename, sizeof(filename), "%s/%s", udev_root, name_loop->name);
|
list_for_each_entry(name_loop, &udev->symlink_list, node) {
|
||||||
filename[sizeof(filename)-1] = '\0';
|
int retval;
|
||||||
|
char linktarget[PATH_SIZE];
|
||||||
|
|
||||||
dbg("symlink '%s' to node '%s' requested", filename, udev->name);
|
snprintf(filename, sizeof(filename), "%s/%s", udev_root, name_loop->name);
|
||||||
if (!udev->test_run)
|
filename[sizeof(filename)-1] = '\0';
|
||||||
if (strchr(filename, '/'))
|
|
||||||
create_path(filename);
|
|
||||||
|
|
||||||
/* optimize relative link */
|
dbg("symlink '%s' to node '%s' requested", filename, udev->name);
|
||||||
linktarget[0] = '\0';
|
if (!udev->test_run)
|
||||||
i = 0;
|
if (strchr(filename, '/'))
|
||||||
tail = 0;
|
create_path(filename);
|
||||||
while (udev->name[i] && (udev->name[i] == name_loop->name[i])) {
|
|
||||||
if (udev->name[i] == '/')
|
/* optimize relative link */
|
||||||
tail = i+1;
|
linktarget[0] = '\0';
|
||||||
i++;
|
i = 0;
|
||||||
}
|
tail = 0;
|
||||||
while (name_loop->name[i] != '\0') {
|
while (udev->name[i] && (udev->name[i] == name_loop->name[i])) {
|
||||||
if (name_loop->name[i] == '/')
|
if (udev->name[i] == '/')
|
||||||
strlcat(linktarget, "../", sizeof(linktarget));
|
tail = i+1;
|
||||||
i++;
|
i++;
|
||||||
|
}
|
||||||
|
while (name_loop->name[i] != '\0') {
|
||||||
|
if (name_loop->name[i] == '/')
|
||||||
|
strlcat(linktarget, "../", sizeof(linktarget));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
strlcat(symlinks, filename, sizeof(symlinks));
|
||||||
|
strlcat(symlinks, " ", sizeof(symlinks));
|
||||||
}
|
}
|
||||||
|
|
||||||
strlcat(linktarget, &udev->name[tail], sizeof(linktarget));
|
remove_trailing_chars(symlinks, ' ');
|
||||||
|
setenv("DEVLINKS", symlinks, 1);
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
if (udev_db_add_device(udev) != 0)
|
||||||
dbg("udev_db_add_dev failed, remove might not work for custom names");
|
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) {
|
} else if (udev->type == DEV_NET) {
|
||||||
/* look if we want to change the name of the netif */
|
/* look if we want to change the name of the netif */
|
||||||
if (strcmp(udev->name, udev->kernel_name) != 0) {
|
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("DEVPATH", udev->devpath, 1);
|
||||||
setenv("INTERFACE", udev->name, 1);
|
setenv("INTERFACE", udev->name, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* use netif name for the environment */
|
|
||||||
strlcpy(udev->devname, udev->name, sizeof(udev->devname));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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) {
|
} else if (udev->type == DEV_DEVICE && strcmp(udev->action, "add") == 0) {
|
||||||
struct sysfs_device *devices_dev;
|
struct sysfs_device *devices_dev;
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
static int delete_node(struct udevice *udev)
|
static int delete_node(struct udevice *udev)
|
||||||
{
|
{
|
||||||
char filename[PATH_SIZE];
|
char filename[PATH_SIZE];
|
||||||
|
char devname[PATH_SIZE];
|
||||||
char partitionname[PATH_SIZE];
|
char partitionname[PATH_SIZE];
|
||||||
struct name_entry *name_loop;
|
struct name_entry *name_loop;
|
||||||
struct stat stats;
|
struct stat stats;
|
||||||
@ -81,9 +82,9 @@ static int delete_node(struct udevice *udev)
|
|||||||
if (retval)
|
if (retval)
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
/* export DEVNAME to the environment */
|
snprintf(devname, sizeof(devname), "%s/%s", udev_root, udev->name);
|
||||||
snprintf(udev->devname, sizeof(udev->devname), "%s/%s", udev_root, udev->name);
|
devname[sizeof(devname)-1] = '\0';
|
||||||
udev->devname[sizeof(udev->devname)-1] = '\0';
|
setenv("DEVNAME", devname, 1);
|
||||||
|
|
||||||
num = udev->partitions;
|
num = udev->partitions;
|
||||||
if (num > 0) {
|
if (num > 0) {
|
||||||
|
@ -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:
|
run:
|
||||||
if (udev_run && !list_empty(&udev.run_list)) {
|
if (udev_run && !list_empty(&udev.run_list)) {
|
||||||
struct name_entry *name_loop;
|
struct name_entry *name_loop;
|
||||||
|
Loading…
Reference in New Issue
Block a user