chiark / gitweb /
[PATCH] remove udev_dbus.h from Makefile
[elogind.git] / udev-remove.c
index e62d1fb1223bcbcd3a27e2ae5f31aa02b54ce8b1..41636b684e265120897e4233658feb4120b3de22 100644 (file)
@@ -29,8 +29,8 @@
 #include <errno.h>
 
 #include "udev.h"
+#include "udev_lib.h"
 #include "udev_version.h"
-#include "udev_dbus.h"
 #include "logging.h"
 #include "namedev.h"
 #include "udevdb.h"
@@ -51,6 +51,8 @@ static int delete_path(char *path)
 
                /* remove if empty */
                retval = rmdir(path);
+               if (errno == ENOENT)
+                       retval = 0;
                if (retval) {
                        if (errno == ENOTEMPTY)
                                return 0;
@@ -65,18 +67,21 @@ static int delete_path(char *path)
 
 static int delete_node(struct udevice *dev)
 {
-       char filename[255];
-       char partitionname[255];
-       char *symlinks;
-       char *linkname;
+       char filename[NAME_SIZE];
+       char linkname[NAME_SIZE];
+       char partitionname[NAME_SIZE];
        int retval;
        int i;
+       char *pos;
+       int len;
 
        strfieldcpy(filename, udev_root);
        strfieldcat(filename, dev->name);
 
        info("removing device node '%s'", filename);
        retval = unlink(filename);
+       if (errno == ENOENT)
+               retval = 0;
        if (retval) {
                dbg("unlink(%s) failed with error '%s'",
                        filename, strerror(errno));
@@ -97,26 +102,22 @@ static int delete_node(struct udevice *dev)
        if (strchr(dev->name, '/'))
                delete_path(filename);
 
-       if (dev->symlink[0] != '\0') {
-               symlinks = dev->symlink;
-               while (1) {
-                       linkname = strsep(&symlinks, " ");
-                       if (linkname == NULL)
-                               break;
-
-                       strfieldcpy(filename, udev_root);
-                       strfieldcat(filename, linkname);
-
-                       dbg("unlinking symlink '%s'", filename);
-                       retval = unlink(filename);
-                       if (retval) {
-                               dbg("unlink(%s) failed with error '%s'",
-                                       filename, strerror(errno));
-                               return retval;
-                       }
-                       if (strchr(dev->symlink, '/')) {
-                               delete_path(filename);
-                       }
+       foreach_strpart(dev->symlink, " ", pos, len) {
+               strfieldcpymax(linkname, pos, len+1);
+               strfieldcpy(filename, udev_root);
+               strfieldcat(filename, linkname);
+
+               dbg("unlinking symlink '%s'", filename);
+               retval = unlink(filename);
+               if (errno == ENOENT)
+                       retval = 0;
+               if (retval) {
+                       dbg("unlink(%s) failed with error '%s'",
+                               filename, strerror(errno));
+                       return retval;
+               }
+               if (strchr(dev->symlink, '/')) {
+                       delete_path(filename);
                }
        }
 
@@ -148,7 +149,7 @@ int udev_remove_device(char *path, char *subsystem)
        dbg("name is '%s'", dev.name);
        udevdb_delete_dev(path);
 
-       sysbus_send_remove(dev.name, path);
+       dev_d_send(&dev, subsystem);
 
        retval = delete_node(&dev);
        return retval;