X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=udev_event.c;h=0b4b9dc4957188c9c877487db91fc710aedaec46;hb=aab4c0eebef44c5b67d4c9537f1c5149de3ca9c2;hp=b50fbf4c1dd61df4f0fcf8cceeb74975bfa22651;hpb=271c2d7d26132858a3302208dfe1572aa9cbbd12;p=elogind.git diff --git a/udev_event.c b/udev_event.c index b50fbf4c1..0b4b9dc49 100644 --- a/udev_event.c +++ b/udev_event.c @@ -28,38 +28,62 @@ #include #include #include +#include +#include "libsysfs/sysfs/libsysfs.h" #include "udev_libc_wrapper.h" #include "udev.h" #include "logging.h" #include "udev_rules.h" #include "udev_utils.h" -#include "udev_sysfs.h" #include "list.h" +dev_t get_devt(struct sysfs_class_device *class_dev) +{ + struct sysfs_attribute *attr = NULL; + unsigned int major, minor; + char *maj, *min; + + maj = getenv("MAJOR"); + min = getenv("MINOR"); + + if (maj && min) { + major = atoi(maj); + minor = atoi(min); + } else { + attr = sysfs_get_classdev_attr(class_dev, "dev"); + if (attr == NULL) + return 0; + dbg("dev='%s'", attr->value); + + if (sscanf(attr->value, "%u:%u", &major, &minor) != 2) + return 0; + } + + dbg("found major=%d, minor=%d", major, minor); + return makedev(major, minor); +} + int udev_process_event(struct udev_rules *rules, struct udevice *udev) { int retval; char path[PATH_SIZE]; - const char *error; if (udev->type == DEV_BLOCK || udev->type == DEV_CLASS || udev->type == DEV_NET) { /* handle device node */ if (strcmp(udev->action, "add") == 0) { struct sysfs_class_device *class_dev; - /* wait for sysfs of /sys/class /sys/block */ dbg("node add"); snprintf(path, sizeof(path), "%s%s", sysfs_path, udev->devpath); path[sizeof(path)-1] = '\0'; - class_dev = wait_class_device_open(path); + class_dev = sysfs_open_class_device_path(path); if (class_dev == NULL) { dbg("open class device failed"); return 0; } dbg("opened class_dev->name='%s'", class_dev->name); - wait_for_class_device(class_dev, &error); /* get major/minor */ if (udev->type == DEV_BLOCK || udev->type == DEV_CLASS) @@ -71,7 +95,7 @@ int udev_process_event(struct udev_rules *rules, struct udevice *udev) if (udev->ignore_device) { info("device event will be ignored"); sysfs_close_class_device(class_dev); - return -1; + return 0; } if (udev->name[0] != '\0') { /* create node, store in db */ @@ -85,7 +109,7 @@ int udev_process_event(struct udev_rules *rules, struct udevice *udev) if (udev->ignore_device) { info("device event will be ignored"); sysfs_close_class_device(class_dev); - return -1; + return 0; } } sysfs_close_class_device(class_dev); @@ -103,7 +127,7 @@ int udev_process_event(struct udev_rules *rules, struct udevice *udev) udev_rules_get_run(rules, udev, NULL, NULL); if (udev->ignore_device) { dbg("device event will be ignored"); - return -1; + return 0; } } @@ -113,29 +137,28 @@ int udev_process_event(struct udev_rules *rules, struct udevice *udev) } else if (udev->type == DEV_DEVICE && strcmp(udev->action, "add") == 0) { struct sysfs_device *devices_dev; - /* wait for sysfs of /sys/devices/ */ dbg("devices add"); snprintf(path, sizeof(path), "%s%s", sysfs_path, udev->devpath); path[sizeof(path)-1] = '\0'; - devices_dev = wait_devices_device_open(path); + devices_dev = sysfs_open_device_path(path); if (!devices_dev) { dbg("devices device unavailable (probably remove has beaten us)"); return 0; } + dbg("devices device opened '%s'", path); - wait_for_devices_device(devices_dev, &error); udev_rules_get_run(rules, udev, NULL, devices_dev); sysfs_close_device(devices_dev); if (udev->ignore_device) { info("device event will be ignored"); - return -1; + return 0; } } else { dbg("default handling"); udev_rules_get_run(rules, udev, NULL, NULL); if (udev->ignore_device) { info("device event will be ignored"); - return -1; + return 0; } } return 0;