X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=udev-remove.c;h=98c45d6c333650ff4ebb381ad6508e49568cad7b;hb=0536819cca9468cf383807037dbaa5ad0d48b60f;hp=8794429635bd0caec5f53b294dcd713464f720b2;hpb=c472e3c89b9aaad90ad6398c0d2ff5dcf5a9d238;p=elogind.git diff --git a/udev-remove.c b/udev-remove.c index 879442963..98c45d6c3 100644 --- a/udev-remove.c +++ b/udev-remove.c @@ -29,8 +29,8 @@ #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" @@ -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,18 +67,21 @@ static int delete_path(char *path) static int delete_node(struct udevice *dev) { - char filename[255]; - char partitionname[255]; - char *symlinks; - char *linkname; + char filename[NAME_SIZE]; + char linkname[NAME_SIZE]; + char partitionname[NAME_SIZE]; int retval; int i; + char *pos; + int len; strfieldcpy(filename, udev_root); strfieldcat(filename, dev->name); 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)); @@ -87,7 +92,8 @@ static int delete_node(struct udevice *dev) if (dev->partitions > 0) { info("removing partitions '%s[1-%i]'", filename, dev->partitions); for (i = 1; i <= dev->partitions; i++) { - sprintf(partitionname, "%s%i", filename, i); + strfieldcpy(partitionname, filename); + strintcat(partitionname, i); unlink(partitionname); } } @@ -96,26 +102,22 @@ static int delete_node(struct udevice *dev) if (strchr(dev->name, '/')) delete_path(filename); - if (dev->symlink[0] != '\0') { - symlinks = dev->symlink; - while (1) { - linkname = strsep(&symlinks, " "); - if (linkname == NULL) - break; - - strfieldcpy(filename, udev_root); - strfieldcat(filename, linkname); - - dbg("unlinking symlink '%s'", filename); - retval = unlink(filename); - if (retval) { - dbg("unlink(%s) failed with error '%s'", - filename, strerror(errno)); - return retval; - } - if (strchr(dev->symlink, '/')) { - delete_path(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)); + return retval; + } + if (strchr(dev->symlink, '/')) { + delete_path(filename); } } @@ -133,22 +135,38 @@ int udev_remove_device(char *path, char *subsystem) char *temp; int retval; - memset(&dev, 0, sizeof(dev)); + memset(&dev, 0x00, sizeof(dev)); - retval = udevdb_get_dev(path, &dev); - if (retval) { - dbg("'%s' not found in database, falling back on default name", path); - temp = strrchr(path, '/'); - if (temp == NULL) - return -ENODEV; - strfieldcpy(dev.name, &temp[1]); - } + dev.type = get_device_type(path, subsystem); - dbg("name is '%s'", dev.name); - udevdb_delete_dev(path); + switch (dev.type) { + case 'b': + case 'c': + retval = udevdb_get_dev(path, &dev); + if (retval) { + dbg("'%s' not found in database, falling back on default name", path); + temp = strrchr(path, '/'); + if (temp == NULL) + return -ENODEV; + strfieldcpy(dev.name, &temp[1]); + } + + dbg("name='%s'", dev.name); + udevdb_delete_dev(path); + + dev_d_send(&dev, subsystem); - sysbus_send_remove(dev.name, path); + retval = delete_node(&dev); + break; + + case 'n': + retval = 0; + break; + + default: + dbg("unknown device type '%c'", dev.type); + retval = -EINVAL; + } - retval = delete_node(&dev); return retval; }