mirror of
https://github.com/AuxXxilium/eudev.git
synced 2024-12-14 18:45:48 +07:00
remove old symlinks before creating current ones
This will prevent incorrect symlinks when a filesystem label is changed and the event is triggered again from sysfs.
This commit is contained in:
parent
00a074480e
commit
ff9a488d8c
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,6 +5,7 @@ udev
|
||||
udevd
|
||||
udevcontrol
|
||||
udevtrigger
|
||||
udevsettle
|
||||
udevsend
|
||||
udevinfo
|
||||
udevmonitor
|
||||
|
3
udev.h
3
udev.h
@ -119,7 +119,8 @@ extern char *sysfs_attr_get_value(const char *devpath, const char *attr_name);
|
||||
|
||||
/* udev_node.c */
|
||||
extern int udev_node_mknod(struct udevice *udev, const char *file, dev_t devt, mode_t mode, uid_t uid, gid_t gid);
|
||||
extern int udev_node_add(struct udevice *udev);
|
||||
extern int udev_node_add(struct udevice *udev, struct udevice *udev_old);
|
||||
extern void udev_node_remove_symlinks(struct udevice *udev);
|
||||
extern int udev_node_remove(struct udevice *udev);
|
||||
|
||||
/* udev_db.c */
|
||||
|
@ -114,7 +114,10 @@ int udev_device_event(struct udev_rules *rules, struct udevice *udev)
|
||||
|
||||
/* add device node */
|
||||
if (major(udev->devt) != 0 && strcmp(udev->action, "add") == 0) {
|
||||
struct udevice *udev_old;
|
||||
|
||||
dbg("device node add '%s'", udev->dev->devpath);
|
||||
|
||||
udev_rules_get_name(rules, udev);
|
||||
if (udev->ignore_device) {
|
||||
info("device event will be ignored");
|
||||
@ -124,8 +127,19 @@ int udev_device_event(struct udev_rules *rules, struct udevice *udev)
|
||||
info("device node creation supressed");
|
||||
goto exit;
|
||||
}
|
||||
/* create node, store in db */
|
||||
retval = udev_node_add(udev);
|
||||
|
||||
/* read current database entry, we may want to cleanup symlinks */
|
||||
udev_old = udev_device_init();
|
||||
if (udev_old != NULL) {
|
||||
if (udev_db_get_device(udev_old, udev->dev->devpath) == 0) {
|
||||
info("device '%s' already known, remove possible symlinks", udev->dev->devpath);
|
||||
udev_node_remove_symlinks(udev_old);
|
||||
}
|
||||
udev_device_cleanup(udev_old);
|
||||
}
|
||||
|
||||
/* create node and symlinks, store record in database */
|
||||
retval = udev_node_add(udev, udev_old);
|
||||
if (retval == 0)
|
||||
udev_db_add_device(udev);
|
||||
goto exit;
|
||||
|
20
udev_node.c
20
udev_node.c
@ -90,7 +90,7 @@ exit:
|
||||
return retval;
|
||||
}
|
||||
|
||||
int udev_node_add(struct udevice *udev)
|
||||
int udev_node_add(struct udevice *udev, struct udevice *udev_old)
|
||||
{
|
||||
char filename[PATH_SIZE];
|
||||
struct name_entry *name_loop;
|
||||
@ -226,15 +226,12 @@ exit:
|
||||
return retval;
|
||||
}
|
||||
|
||||
int udev_node_remove(struct udevice *udev)
|
||||
void udev_node_remove_symlinks(struct udevice *udev)
|
||||
{
|
||||
char filename[PATH_SIZE];
|
||||
char partitionname[PATH_SIZE];
|
||||
struct name_entry *name_loop;
|
||||
struct stat stats;
|
||||
int retval;
|
||||
int i;
|
||||
int num;
|
||||
|
||||
if (!list_empty(&udev->symlink_list)) {
|
||||
char symlinks[512] = "";
|
||||
@ -266,6 +263,17 @@ int udev_node_remove(struct udevice *udev)
|
||||
if (symlinks[0] != '\0')
|
||||
setenv("DEVLINKS", symlinks, 1);
|
||||
}
|
||||
}
|
||||
|
||||
int udev_node_remove(struct udevice *udev)
|
||||
{
|
||||
char filename[PATH_SIZE];
|
||||
char partitionname[PATH_SIZE];
|
||||
struct stat stats;
|
||||
int retval;
|
||||
int num;
|
||||
|
||||
udev_node_remove_symlinks(udev);
|
||||
|
||||
snprintf(filename, sizeof(filename), "%s/%s", udev_root, udev->name);
|
||||
filename[sizeof(filename)-1] = '\0';
|
||||
@ -288,6 +296,8 @@ int udev_node_remove(struct udevice *udev)
|
||||
|
||||
num = udev->partitions;
|
||||
if (num > 0) {
|
||||
int i;
|
||||
|
||||
info("removing all_partitions '%s[1-%i]'", filename, num);
|
||||
if (num > 255) {
|
||||
info("garbage from udev database, skip all_partitions removal");
|
||||
|
Loading…
Reference in New Issue
Block a user