X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=udev-remove.c;h=0f14a3d685f7745e3afa8c05ea2443c8e640138a;hb=f7b4eca455c7dbf850d984892756f22dbd9ddc3d;hp=c61a948fa0b179ba987063d922995f703b5cc3c5;hpb=5840bc63e2029d22682d8de77dc8fcc4da1b436c;p=elogind.git diff --git a/udev-remove.c b/udev-remove.c index c61a948fa..0f14a3d68 100644 --- a/udev-remove.c +++ b/udev-remove.c @@ -52,14 +52,14 @@ static char *get_name(char *path, int major, int minor) goto exit; } - dbg("%s not found in database, falling back on default name", path); + dbg("'%s' not found in database, falling back on default name", path); temp = strrchr(path, '/'); if (temp == NULL) return NULL; strncpy(name, &temp[1], sizeof(name)); exit: - dbg("name is %s", name); + dbg("name is '%s'", name); return &name[0]; } @@ -69,12 +69,45 @@ exit: static int delete_node(char *name) { char filename[255]; + int retval; - strncpy(filename, UDEV_ROOT, sizeof(filename)); + strncpy(filename, udev_root, sizeof(filename)); strncat(filename, name, sizeof(filename)); - dbg("unlinking %s", filename); - return unlink(filename); + dbg("unlinking '%s'", filename); + retval = unlink(filename); + if (retval) { + dbg("unlink(%s) failed with error '%s'", + filename, strerror(errno)); + return retval; + } + + /* remove subdirectories */ + if (strchr(name, '/')) { + char *pos; + + pos = strrchr(filename, '/'); + while (1) { + *pos = 0x00; + pos = strrchr(filename, '/'); + + /* don't remove the last one */ + if ((pos == filename) || (pos == NULL)) + break; + + /* remove if empty */ + retval = rmdir(filename); + if (retval) { + if (errno == ENOTEMPTY) + return 0; + dbg("rmdir(%s) failed with error '%s'", + filename, strerror(errno)); + break; + } + dbg("removed '%s'", filename); + } + } + return retval; } int udev_remove_device(char *device, char *subsystem)