chiark / gitweb /
[PATCH] reduce syslog noise of udevsend if multiple instances try to start udevd
[elogind.git] / udev_remove.c
index d4be8bd6f9cd6c8e5ed214964339e21032df90df..cd9d27f8dce2836f5576be021f732f0880e66b13 100644 (file)
 
 #include <stdlib.h>
 #include <string.h>
+#include <stddef.h>
 #include <stdio.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <errno.h>
+#include <sys/stat.h>
 
 #include "udev.h"
 #include "udev_lib.h"
@@ -35,7 +37,7 @@
 #include "namedev.h"
 #include "udevdb.h"
 
-static int delete_path(char *path)
+static int delete_path(const char *path)
 {
        char *pos;
        int retval;
@@ -161,36 +163,36 @@ static int delete_node(struct udevice *dev)
 }
 
 /*
- * Look up the sysfs path in the database to see if we have named this device
- * something different from the kernel name.  If we have, us it.  If not, use
- * the default kernel name for lack of anything else to know to do.
+ * look up the sysfs path in the database to get the node name to remove
+ * If we can't find it, use kernel name for lack of anything else to know to do
  */
-int udev_remove_device(const char *path, const char *subsystem)
+int udev_remove_device(struct udevice *udev)
 {
-       struct udevice dev;
-       char *temp;
+       struct udevice db_dev;
+       const char *temp;
        int retval;
 
-       memset(&dev, 0x00, sizeof(dev));
+       if (udev->type != 'b' && udev->type != 'c')
+               return 0;
 
-       retval = udevdb_get_dev(path, &dev);
-       if (retval != 0) {
-               dbg("'%s' not found in database, falling back on default name", path);
-               temp = strrchr(path, '/');
+       retval = udevdb_get_dev(udev->devpath, &db_dev);
+       if (retval == 0) {
+               /* copy over the stored values to our device */
+               memcpy(udev, &db_dev, UDEVICE_DB_LEN);
+       } else {
+               /* fall back to kernel name */
+               temp = strrchr(udev->devpath, '/');
                if (temp == NULL)
                        return -ENODEV;
-               strfieldcpy(dev.name, &temp[1]);
+               strfieldcpy(udev->name, &temp[1]);
+               dbg("'%s' not found in database, falling back on default name", udev->name);
        }
-       dbg("name='%s'", dev.name);
 
-       dev.type = get_device_type(path, subsystem);
-       dev_d_send(&dev, subsystem, path);
-       udevdb_delete_dev(path);
+       dbg("remove name='%s'", udev->name);
+       udevdb_delete_dev(udev->devpath);
 
-       if (dev.type == 'b' || dev.type == 'c')
-               retval = delete_node(&dev);
-       else if (dev.type == 'n')
-               retval = 0;
+       /* use full path to the environment */
+       snprintf(udev->devname, NAME_SIZE-1, "%s%s", udev_root, udev->name);
 
-       return retval;
+       return delete_node(udev);
 }