X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=udev%2Flib%2Flibudev-device.c;h=1a9d0a1e69aa9fd4a8454a9b31076366e31f47d5;hb=d7ce7539d327780fba18c8ae8951e1ff50cd0b3e;hp=06227be328c0851a121c7b08463903aba18158d0;hpb=bf8b2ae177fd016d03349b3aa881b72afd7d037d;p=elogind.git diff --git a/udev/lib/libudev-device.c b/udev/lib/libudev-device.c index 06227be32..1a9d0a1e6 100644 --- a/udev/lib/libudev-device.c +++ b/udev/lib/libudev-device.c @@ -58,6 +58,7 @@ struct udev_device { int devlink_priority; int refcount; dev_t devnum; + int watch_handle; unsigned int parent_set:1; unsigned int subsystem_set:1; unsigned int devtype_set:1; @@ -176,6 +177,9 @@ int udev_device_read_db(struct udev_device *udev_device) case 'E': udev_device_add_property_from_string(udev_device, val); break; + case 'W': + udev_device_set_watch_handle(udev_device, atoi(val)); + break; } } fclose(f); @@ -251,6 +255,7 @@ struct udev_device *device_new(struct udev *udev) udev_list_init(&udev_device->properties_list); udev_list_init(&udev_device->sysattr_list); udev_device->event_timeout = -1; + udev_device->watch_handle = -1; /* copy global properties */ udev_list_entry_foreach(list_entry, udev_get_properties_list_entry(udev)) udev_device_add_property(udev_device, @@ -541,33 +546,26 @@ struct udev_device *udev_device_get_parent(struct udev_device *udev_device) return udev_device->parent_device; } -struct udev_device *udev_device_get_parent_with_subsystem(struct udev_device *udev_device, const char *subsystem) +struct udev_device *udev_device_get_parent_with_subsystem_devtype(struct udev_device *udev_device, const char *subsystem, const char *devtype) { struct udev_device *parent; - parent = udev_device_get_parent(udev_device); - while (parent != NULL) { - const char *parent_subsystem; - - parent_subsystem = udev_device_get_subsystem(parent); - if (parent_subsystem != NULL && strcmp(parent_subsystem, subsystem) == 0) - break; - parent = udev_device_get_parent(parent); - } - return parent; -} - -struct udev_device *udev_device_get_parent_with_devtype(struct udev_device *udev_device, const char *devtype) -{ - struct udev_device *parent; + if (subsystem == NULL) + return NULL; parent = udev_device_get_parent(udev_device); while (parent != NULL) { + const char *parent_subsystem; const char *parent_devtype; - parent_devtype = udev_device_get_devtype(parent); - if (parent_devtype != NULL && strcmp(parent_devtype, devtype) == 0) - break; + parent_subsystem = udev_device_get_subsystem(parent); + if (parent_subsystem != NULL && strcmp(parent_subsystem, subsystem) == 0) { + if (devtype == NULL) + break; + parent_devtype = udev_device_get_devtype(parent); + if (parent_devtype != NULL && strcmp(parent_devtype, devtype) == 0) + break; + } parent = udev_device_get_parent(parent); } return parent; @@ -758,7 +756,8 @@ const char *udev_device_get_devtype(struct udev_device *udev_device) return NULL; if (!udev_device->devtype_set) { udev_device->devtype_set = 1; - udev_device_read_uevent_file(udev_device); + if (!udev_device->info_loaded) + udev_device_read_uevent_file(udev_device); } return udev_device->devtype; } @@ -868,7 +867,7 @@ const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const { struct udev_list_entry *list_entry; char path[UTIL_PATH_SIZE]; - char value[UTIL_NAME_SIZE]; + char value[4096]; struct stat statbuf; int fd; ssize_t size; @@ -1065,6 +1064,20 @@ struct udev_list_entry *udev_device_add_property_from_string(struct udev_device return udev_device_add_property(udev_device, name, val); } +const char *udev_device_get_property_value(struct udev_device *udev_device, const char *key) +{ + struct udev_list_entry *list_entry; + + if (udev_device == NULL) + return NULL; + if (key == NULL) + return NULL; + + list_entry = udev_device_get_properties_list_entry(udev_device); + list_entry = udev_list_entry_get_by_name(list_entry, key); + return udev_list_entry_get_value(list_entry); +} + #define ENVP_SIZE 128 #define MONITOR_BUF_SIZE 4096 static int update_envp_monitor_buf(struct udev_device *udev_device) @@ -1283,3 +1296,16 @@ int udev_device_set_ignore_remove(struct udev_device *udev_device, int ignore) udev_device->ignore_remove = ignore; return 0; } + +int udev_device_get_watch_handle(struct udev_device *udev_device) +{ + if (!udev_device->info_loaded) + device_load_info(udev_device); + return udev_device->watch_handle; +} + +int udev_device_set_watch_handle(struct udev_device *udev_device, int handle) +{ + udev_device->watch_handle = handle; + return 0; +}