chiark / gitweb /
call util_delete_path() only when we actually deleted stuff
authorKay Sievers <kay.sievers@vrfy.org>
Tue, 3 Aug 2010 10:13:53 +0000 (12:13 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Tue, 3 Aug 2010 10:13:53 +0000 (12:13 +0200)
libudev/libudev-util-private.c
udev/udev-node.c

index 2f9f4a7..6b68b6a 100644 (file)
@@ -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,
index 8339eb7..228b3eb 100644 (file)
@@ -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;
 }