chiark / gitweb /
libudev: util - drop util_delete_path()
authorTom Gundersen <teg@jklm.no>
Mon, 15 Sep 2014 12:20:32 +0000 (14:20 +0200)
committerTom Gundersen <teg@jklm.no>
Tue, 16 Sep 2014 10:12:56 +0000 (12:12 +0200)
Use rmdir_parents() from src/shared instead.

src/libudev/libudev-private.h
src/libudev/libudev-util.c
src/test/test-udev.c
src/udev/udev-node.c

index 1c060d9..2f74bc0 100644 (file)
@@ -167,7 +167,6 @@ unsigned int util_string_hash32(const char *key);
 uint64_t util_string_bloom64(const char *str);
 
 /* libudev-util-private.c */
 uint64_t util_string_bloom64(const char *str);
 
 /* libudev-util-private.c */
-int util_delete_path(struct udev *udev, const char *path);
 int util_resolve_subsys_kernel(struct udev *udev, const char *string, char *result, size_t maxsize, int read_value);
 
 #endif
 int util_resolve_subsys_kernel(struct udev *udev, const char *string, char *result, size_t maxsize, int read_value);
 
 #endif
index 3bc9c67..a7125fa 100644 (file)
  * Utilities useful when dealing with devices and device node names.
  */
 
  * Utilities useful when dealing with devices and device node names.
  */
 
-int util_delete_path(struct udev *udev, const char *path)
-{
-        char p[UTIL_PATH_SIZE];
-        char *pos;
-        int err = 0;
-
-        if (path[0] == '/')
-                while(path[1] == '/')
-                        path++;
-        strscpy(p, sizeof(p), path);
-        pos = strrchr(p, '/');
-        if (pos == p || pos == NULL)
-                return 0;
-
-        for (;;) {
-                *pos = '\0';
-                pos = strrchr(p, '/');
-
-                /* don't remove the last one */
-                if ((pos == p) || (pos == NULL))
-                        break;
-
-                err = rmdir(p);
-                if (err < 0) {
-                        if (errno == ENOENT)
-                                err = 0;
-                        break;
-                }
-        }
-        return err;
-}
-
 /* handle "[<SUBSYSTEM>/<KERNEL>]<attribute>" format */
 int util_resolve_subsys_kernel(struct udev *udev, const char *string,
                                char *result, size_t maxsize, int read_value)
 /* handle "[<SUBSYSTEM>/<KERNEL>]<attribute>" format */
 int util_resolve_subsys_kernel(struct udev *udev, const char *string,
                                char *result, size_t maxsize, int read_value)
index f085262..f368c3f 100644 (file)
@@ -149,7 +149,7 @@ int main(int argc, char *argv[]) {
                         mknod(udev_device_get_devnode(dev), mode, udev_device_get_devnum(dev));
                 } else {
                         unlink(udev_device_get_devnode(dev));
                         mknod(udev_device_get_devnode(dev), mode, udev_device_get_devnum(dev));
                 } else {
                         unlink(udev_device_get_devnode(dev));
-                        util_delete_path(udev, udev_device_get_devnode(dev));
+                        rmdir_parents(udev_device_get_devnode(dev), "/");
                 }
         }
 
                 }
         }
 
index d42af9a..c164603 100644 (file)
@@ -179,7 +179,6 @@ static const char *link_find_prioritized(struct udev_device *dev, bool add, cons
 
 /* manage "stack of names" with possibly specified device priorities */
 static void link_update(struct udev_device *dev, const char *slink, bool add) {
 
 /* manage "stack of names" with possibly specified device priorities */
 static void link_update(struct udev_device *dev, const char *slink, bool add) {
-        struct udev *udev = udev_device_get_udev(dev);
         char name_enc[UTIL_PATH_SIZE];
         char filename[UTIL_PATH_SIZE * 2];
         char dirname[UTIL_PATH_SIZE];
         char name_enc[UTIL_PATH_SIZE];
         char filename[UTIL_PATH_SIZE * 2];
         char dirname[UTIL_PATH_SIZE];
@@ -197,7 +196,7 @@ static void link_update(struct udev_device *dev, const char *slink, bool add) {
         if (target == NULL) {
                 log_debug("no reference left, remove '%s'", slink);
                 if (unlink(slink) == 0)
         if (target == NULL) {
                 log_debug("no reference left, remove '%s'", slink);
                 if (unlink(slink) == 0)
-                        util_delete_path(udev, slink);
+                        rmdir_parents(slink, "/");
         } else {
                 log_debug("creating link '%s' to '%s'", slink, target);
                 node_symlink(dev, target, slink);
         } else {
                 log_debug("creating link '%s' to '%s'", slink, target);
                 node_symlink(dev, target, slink);