X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev-remove.c;h=27ff5bc0a2e12d38167ba1db43d85ca78ac3ccf0;hp=02c84371a45a5e1ba6712dc26dfec162fc128dba;hb=9b28a52a0ac9b7993c932bbfe9d86dfc814be218;hpb=7ac0feeb6044470569d7ece5d34a76acdb03fc64 diff --git a/udev-remove.c b/udev-remove.c index 02c84371a..27ff5bc0a 100644 --- a/udev-remove.c +++ b/udev-remove.c @@ -29,11 +29,11 @@ #include #include "udev.h" +#include "udev_lib.h" #include "udev_version.h" -#include "udev_dbus.h" +#include "logging.h" #include "namedev.h" #include "udevdb.h" -#include "libsysfs/libsysfs.h" static int delete_path(char *path) { @@ -51,6 +51,8 @@ static int delete_path(char *path) /* remove if empty */ retval = rmdir(path); + if (errno == ENOENT) + retval = 0; if (retval) { if (errno == ENOTEMPTY) return 0; @@ -65,29 +67,50 @@ static int delete_path(char *path) static int delete_node(struct udevice *dev) { - char filename[255]; + char filename[NAME_SIZE]; + char linkname[NAME_SIZE]; + char partitionname[NAME_SIZE]; int retval; + int i; + char *pos; + int len; - strncpy(filename, udev_root, sizeof(filename)); - strncat(filename, dev->name, sizeof(filename)); + strfieldcpy(filename, udev_root); + strfieldcat(filename, dev->name); - dbg("unlinking node '%s'", filename); + info("removing device node '%s'", filename); retval = unlink(filename); + if (errno == ENOENT) + retval = 0; if (retval) { dbg("unlink(%s) failed with error '%s'", filename, strerror(errno)); return retval; } + /* remove partition nodes */ + if (dev->partitions > 0) { + info("removing partitions '%s[1-%i]'", filename, dev->partitions); + for (i = 1; i <= dev->partitions; i++) { + strfieldcpy(partitionname, filename); + strintcat(partitionname, i); + unlink(partitionname); + } + } + /* remove subdirectories */ if (strchr(dev->name, '/')) delete_path(filename); - if (*dev->symlink) { - strncpy(filename, udev_root, sizeof(filename)); - strncat(filename, dev->symlink, sizeof(filename)); + foreach_strpart(dev->symlink, " ", pos, len) { + strfieldcpymax(linkname, pos, len+1); + strfieldcpy(filename, udev_root); + strfieldcat(filename, linkname); + 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)); @@ -108,23 +131,30 @@ static int delete_node(struct udevice *dev) */ int udev_remove_device(char *path, char *subsystem) { - char name[100]; - struct udevice *dev; + struct udevice dev; char *temp; + int retval; - dev = udevdb_get_dev(path); - if (dev == NULL) { + memset(&dev, 0x00, sizeof(dev)); + + retval = udevdb_get_dev(path, &dev); + if (retval != 0) { dbg("'%s' not found in database, falling back on default name", path); temp = strrchr(path, '/'); if (temp == NULL) return -ENODEV; - strncpy(name, &temp[1], sizeof(name)); + strfieldcpy(dev.name, &temp[1]); } + dbg("name='%s'", dev.name); - dbg("name is '%s'", dev->name); + dev.type = get_device_type(path, subsystem); + dev_d_send(&dev, subsystem, path); udevdb_delete_dev(path); - sysbus_send_remove(name, path); + if (dev.type == 'b' || dev.type == 'c') + retval = delete_node(&dev); + else if (dev.type == 'n') + retval = 0; - return delete_node(dev); + return retval; }