From 8e5a620b17c08b0b6277236203ee559b7dadd1d4 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Tue, 3 Aug 2010 12:13:53 +0200 Subject: [PATCH] call util_delete_path() only when we actually deleted stuff --- libudev/libudev-util-private.c | 17 ++++++----------- 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 2f9f4a74..6b68b6a3 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 8339eb73..228b3ebe 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; } -- 2.39.5