diff options
-rw-r--r-- | libudev/libudev-util-private.c | 17 | ||||
-rw-r--r-- | udev/udev-node.c | 11 |
2 files changed, 12 insertions, 16 deletions
diff --git a/libudev/libudev-util-private.c b/libudev/libudev-util-private.c index 2f9f4a74c3..6b68b6a366 100644 --- a/libudev/libudev-util-private.c +++ b/libudev/libudev-util-private.c @@ -74,7 +74,7 @@ int util_delete_path(struct udev *udev, const char *path) { char p[UTIL_PATH_SIZE]; char *pos; - int retval; + int err = 0; if (path[0] == '/') while(path[1] == '/') @@ -92,19 +92,14 @@ int util_delete_path(struct udev *udev, const char *path) if ((pos == p) || (pos == NULL)) break; - /* remove if empty */ - retval = rmdir(p); - if (errno == ENOENT) - retval = 0; - if (retval) { - if (errno == ENOTEMPTY) - return 0; - err(udev, "rmdir(%s) failed: %m\n", p); + err = rmdir(p); + if (err < 0) { + if (errno == ENOENT) + err = 0; break; } - dbg(udev, "removed '%s'\n", p); } - return 0; + return err; } /* Reset permissions on the device node, before unlinking it to make sure, diff --git a/udev/udev-node.c b/udev/udev-node.c index 8339eb732f..228b3ebee4 100644 --- a/udev/udev-node.c +++ b/udev/udev-node.c @@ -298,15 +298,15 @@ static void link_update(struct udev_device *dev, const char *slink, bool add) if (!add) { dbg(udev, "removing index: '%s'\n", filename); - unlink(filename); - util_delete_path(udev, filename); + if (unlink(filename) == 0) + rmdir(dirname); } target = link_find_prioritized(dev, add, dirname, buf, sizeof(buf)); if (target == NULL) { info(udev, "no reference left, remove '%s'\n", slink); - unlink(slink); - util_delete_path(udev, slink); + if (unlink(slink) == 0) + util_delete_path(udev, slink); } else { info(udev, "creating link '%s' to '%s'\n", slink, target); node_symlink(udev, target, slink); @@ -427,7 +427,8 @@ int udev_node_remove(struct udev_device *dev) info(udev, "removing device node '%s'\n", devnode); err = util_unlink_secure(udev, devnode); - util_delete_path(udev, devnode); + if (err == 0) + util_delete_path(udev, devnode); out: return err; } |