diff options
author | Kay Sievers <kay.sievers@suse.de> | 2006-04-12 22:08:05 +0200 |
---|---|---|
committer | Kay Sievers <kay.sievers@suse.de> | 2006-04-12 22:08:05 +0200 |
commit | ff9a488d8c559a2ee40e522cdc68b750670711e4 (patch) | |
tree | be773a20aff7ccbae7ef8cc9b6e2cab33d3e27ad | |
parent | 00a074480e4ab15e61f13f8791015fa0befcadce (diff) |
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.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | udev.h | 3 | ||||
-rw-r--r-- | udev_device.c | 18 | ||||
-rw-r--r-- | udev_node.c | 20 |
4 files changed, 34 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore index b9adf69fc6..499e9c4d90 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ udev udevd udevcontrol udevtrigger +udevsettle udevsend udevinfo udevmonitor @@ -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 */ diff --git a/udev_device.c b/udev_device.c index 84d0ab2204..b356f163a5 100644 --- a/udev_device.c +++ b/udev_device.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; diff --git a/udev_node.c b/udev_node.c index 9d6e89cfa1..d2889a329e 100644 --- a/udev_node.c +++ b/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"); |