chiark / gitweb /
[PATCH] update the tests to handle block devices too.
[elogind.git] / udev.c
diff --git a/udev.c b/udev.c
index 5aa9b43d43134d1092c38036e526d4079baa99c7..dc5f5b8d8944006125b6d941d3c0e8da467df3aa 100644 (file)
--- a/udev.c
+++ b/udev.c
@@ -30,6 +30,7 @@
 
 #include "udev.h"
 #include "udev_version.h"
+#include "namedev.h"
 
 
 static char *get_action(void)
@@ -49,7 +50,8 @@ static char *get_device(void)
        temp = getenv("DEVPATH");
        if (temp == NULL)
                return NULL;
-       strcpy(device, SYSFS_ROOT);
+       strcpy(device, "");
+//     strcpy(device, SYSFS_ROOT);
        strcat(device, temp);
 
        return device;
@@ -197,14 +199,14 @@ static int delete_node(char *name)
        return unlink(filename);
 }
 
-static int add_device(char *device, char type)
+static int add_device(char *device, char type, struct device_attr *attr)
 {
        char *name;
        int major;
        int minor;
        int mode;
        int retval = -EINVAL;
-
+#if 0
        retval = get_major_minor(device, &major, &minor);
        if (retval) {
                dbg ("get_major_minor failed");
@@ -224,8 +226,8 @@ static int add_device(char *device, char type)
                retval = -EINVAL;
                goto exit;
        }
-
-       return create_node(name, type, major, minor, mode);
+#endif
+       return create_node(attr->name, type, attr->major, attr->minor, attr->mode);
 
 exit:
        return retval;
@@ -251,6 +253,7 @@ exit:
 
 int main(int argc, char *argv[])
 {
+       struct device_attr attr;
        char *subsystem;
        char *action;
        char *device;
@@ -262,6 +265,13 @@ int main(int argc, char *argv[])
                goto exit;
        }
 
+       namedev_init();
+
+       /* sleep for a second or two to give the kernel a chance to
+        * create the dev file
+        */
+       sleep(2);
+
        /* for now, the block layer is the only place where block devices are */
        subsystem = argv[1];
        if (strcmp(subsystem, "block") == 0)
@@ -282,8 +292,12 @@ int main(int argc, char *argv[])
        }
        dbg("looking at %s", device);
 
+       retval = namedev_name_device(device, &attr);
+       if (retval)
+               return retval;
+
        if (strcmp(action, "add") == 0)
-               return add_device(device, type);
+               return add_device(device, type, &attr);
 
        if (strcmp(action, "remove") == 0)
                return remove_device(device);