X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=udev_remove.c;h=cf28ff37a9bfb56044e9feb625af239ef2f74582;hb=7c26d9eb432b173ccd61b998ab5a4a8debf51d68;hp=1fd36d24c5f93e5037be42311134c6ba9a1082f7;hpb=63f61c5cf639953aa38e025485919b0aa1c49b59;p=elogind.git diff --git a/udev_remove.c b/udev_remove.c index 1fd36d24c..cf28ff37a 100644 --- a/udev_remove.c +++ b/udev_remove.c @@ -34,7 +34,6 @@ #include "udev.h" #include "udev_utils.h" #include "udev_version.h" -#include "namedev.h" #include "udev_db.h" #include "logging.h" @@ -78,13 +77,33 @@ static int delete_node(struct udevice *udev) int i; int num; + list_for_each_entry(name_loop, &udev->symlink_list, node) { + snprintf(filename, sizeof(filename), "%s/%s", udev_root, name_loop->name); + filename[sizeof(filename)-1] = '\0'; + + if (stat(filename, &stats) != 0) { + dbg("symlink '%s' not found", filename); + continue; + } + if (udev->devt && stats.st_rdev != udev->devt) { + info("symlink '%s' points to a different device, skip removal", filename); + continue;; + } + + dbg("removing symlink '%s'", filename); + unlink(filename); + + if (strchr(filename, '/')) + delete_path(filename); + } + snprintf(filename, sizeof(filename), "%s/%s", udev_root, udev->name); filename[sizeof(filename)-1] = '\0'; - dbg("checking major/minor of device node '%s'", filename); - if (stat(filename, &stats) != 0) + if (stat(filename, &stats) != 0) { + dbg("device node '%s' not found", filename); return -1; - + } if (udev->devt && stats.st_rdev != udev->devt) { info("device node '%s' points to a different device, skip removal", filename); return -1; @@ -95,7 +114,6 @@ static int delete_node(struct udevice *udev) if (retval) return retval; - /* remove all_partitions nodes */ num = udev->partitions; if (num > 0) { info("removing all_partitions '%s[1-%i]'", filename, num); @@ -110,28 +128,9 @@ static int delete_node(struct udevice *udev) } } - /* remove subdirectories */ if (strchr(udev->name, '/')) delete_path(filename); - list_for_each_entry(name_loop, &udev->symlink_list, node) { - snprintf(filename, sizeof(filename), "%s/%s", udev_root, name_loop->name); - filename[sizeof(filename)-1] = '\0'; - - dbg("unlinking symlink '%s'", filename); - retval = unlink(filename); - if (errno == ENOENT) - retval = 0; - if (retval) { - dbg("unlink(%s) failed with error '%s'", - filename, strerror(errno)); - return retval; - } - if (strchr(filename, '/')) { - delete_path(filename); - } - } - return retval; } @@ -141,26 +140,20 @@ static int delete_node(struct udevice *udev) */ int udev_remove_device(struct udevice *udev) { - const char *temp; - - if (udev->type != BLOCK && udev->type != CLASS) + if (udev->type != DEV_BLOCK && udev->type != DEV_CLASS) return 0; - if (udev_db_get_device(udev, udev->devpath) == 0) { - if (udev->ignore_remove) { - dbg("remove event for '%s' requested to be ignored by rule", udev->name); - return 0; - } - dbg("remove name='%s'", udev->name); - udev_db_delete_device(udev); - } else { - /* fall back to kernel name */ - temp = strrchr(udev->devpath, '/'); - if (temp == NULL) - return -ENODEV; - strlcpy(udev->name, &temp[1], sizeof(udev->name)); - dbg("'%s' not found in database, falling back on default name", udev->name); + /* remove node only if we can find it in our database */ + if (udev_db_get_device(udev, udev->devpath) != 0) { + dbg("'%s' not found in database, ignore event", udev->name); + return -1; + } + if (udev->ignore_remove) { + dbg("remove event for '%s' requested to be ignored by rule", udev->name); + return 0; } + dbg("remove name='%s'", udev->name); + udev_db_delete_device(udev); /* use full path to the environment */ snprintf(udev->devname, sizeof(udev->devname), "%s/%s", udev_root, udev->name);