libudev: device - export properties when values are set

This commit is contained in:
Kay Sievers 2008-10-16 11:37:22 +02:00
parent 5c5cad7966
commit 31f4b036ea
2 changed files with 31 additions and 10 deletions

View File

@ -35,6 +35,7 @@ struct udev_device {
int refcount; int refcount;
struct udev *udev; struct udev *udev;
struct udev_device *parent_device; struct udev_device *parent_device;
int parent_set;
char *syspath; char *syspath;
const char *devpath; const char *devpath;
char *sysname; char *sysname;
@ -518,12 +519,12 @@ struct udev_device *udev_device_get_parent(struct udev_device *udev_device)
{ {
if (udev_device == NULL) if (udev_device == NULL)
return NULL; return NULL;
if (!udev_device->parent_set) {
if (udev_device->parent_device != NULL) { udev_device->parent_set = 1;
info(udev_device->udev, "returning existing parent %p\n", udev_device->parent_device);
return udev_device->parent_device;
}
udev_device->parent_device = device_new_from_parent(udev_device); udev_device->parent_device = device_new_from_parent(udev_device);
}
if (udev_device->parent_device != NULL)
info(udev_device->udev, "returning existing parent %p\n", udev_device->parent_device);
return udev_device->parent_device; return udev_device->parent_device;
} }
@ -1016,7 +1017,7 @@ int udev_device_set_action(struct udev_device *udev_device, const char *action)
udev_device->action = strdup(action); udev_device->action = strdup(action);
if (udev_device->action == NULL) if (udev_device->action == NULL)
return -ENOMEM; return -ENOMEM;
udev_device_add_property(udev_device, "ACTION", action); udev_device_add_property(udev_device, "ACTION", udev_device->action);
return 0; return 0;
} }
@ -1027,6 +1028,7 @@ int udev_device_set_driver(struct udev_device *udev_device, const char *driver)
if (udev_device->driver == NULL) if (udev_device->driver == NULL)
return -ENOMEM; return -ENOMEM;
udev_device->driver_set = 1; udev_device->driver_set = 1;
udev_device_add_property(udev_device, "DRIVER", udev_device->driver);
return 0; return 0;
} }
@ -1040,6 +1042,7 @@ int udev_device_set_devpath_old(struct udev_device *udev_device, const char *dev
udev_device->devpath_old = strdup(devpath_old); udev_device->devpath_old = strdup(devpath_old);
if (udev_device->devpath_old == NULL) if (udev_device->devpath_old == NULL)
return -ENOMEM; return -ENOMEM;
udev_device_add_property(udev_device, "DEVPATH_OLD", udev_device->devpath_old);
return 0; return 0;
} }
@ -1081,13 +1084,24 @@ int udev_device_set_event_timeout(struct udev_device *udev_device, int event_tim
int udev_device_set_seqnum(struct udev_device *udev_device, unsigned long long int seqnum) int udev_device_set_seqnum(struct udev_device *udev_device, unsigned long long int seqnum)
{ {
char num[32];
udev_device->seqnum = seqnum; udev_device->seqnum = seqnum;
snprintf(num, sizeof(num), "%llu", seqnum);
udev_device_add_property(udev_device, "SEQNUM", num);
return 0; return 0;
} }
int udev_device_set_devnum(struct udev_device *udev_device, dev_t devnum) int udev_device_set_devnum(struct udev_device *udev_device, dev_t devnum)
{ {
char num[32];
udev_device->devnum = devnum; udev_device->devnum = devnum;
snprintf(num, sizeof(num), "%u", major(devnum));
udev_device_add_property(udev_device, "MAJOR", num);
snprintf(num, sizeof(num), "%u", minor(devnum));
udev_device_add_property(udev_device, "MINOR", num);
return 0; return 0;
} }

View File

@ -245,6 +245,8 @@ struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monito
char buf[4096]; char buf[4096];
size_t bufpos; size_t bufpos;
int devpath_set = 0; int devpath_set = 0;
int subsystem_set = 0;
int action_set = 0;
int maj = 0; int maj = 0;
int min = 0; int min = 0;
@ -317,6 +319,7 @@ struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monito
devpath_set = 1; devpath_set = 1;
} else if (strncmp(key, "SUBSYSTEM=", 10) == 0) { } else if (strncmp(key, "SUBSYSTEM=", 10) == 0) {
udev_device_set_subsystem(udev_device, &key[10]); udev_device_set_subsystem(udev_device, &key[10]);
subsystem_set = 1;
} else if (strncmp(key, "DEVNAME=", 8) == 0) { } else if (strncmp(key, "DEVNAME=", 8) == 0) {
udev_device_set_devnode(udev_device, &key[8]); udev_device_set_devnode(udev_device, &key[8]);
} else if (strncmp(key, "DEVLINKS=", 9) == 0) { } else if (strncmp(key, "DEVLINKS=", 9) == 0) {
@ -339,6 +342,7 @@ struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monito
udev_device_set_driver(udev_device, &key[7]); udev_device_set_driver(udev_device, &key[7]);
} else if (strncmp(key, "ACTION=", 7) == 0) { } else if (strncmp(key, "ACTION=", 7) == 0) {
udev_device_set_action(udev_device, &key[7]); udev_device_set_action(udev_device, &key[7]);
action_set = 1;
} else if (strncmp(key, "MAJOR=", 6) == 0) { } else if (strncmp(key, "MAJOR=", 6) == 0) {
maj = strtoull(&key[6], NULL, 10); maj = strtoull(&key[6], NULL, 10);
} else if (strncmp(key, "MINOR=", 6) == 0) { } else if (strncmp(key, "MINOR=", 6) == 0) {
@ -351,12 +355,15 @@ struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monito
udev_device_set_seqnum(udev_device, strtoull(&key[7], NULL, 10)); udev_device_set_seqnum(udev_device, strtoull(&key[7], NULL, 10));
} else if (strncmp(key, "TIMEOUT=", 8) == 0) { } else if (strncmp(key, "TIMEOUT=", 8) == 0) {
udev_device_set_timeout(udev_device, strtoull(&key[8], NULL, 10)); udev_device_set_timeout(udev_device, strtoull(&key[8], NULL, 10));
} } else if (strncmp(key, "PHYSDEV", 7) == 0) {
if (strncmp(key, "PHYSDEV", 7) == 0) /* skip deprecated values */
continue; continue;
} else {
udev_device_add_property_from_string(udev_device, key); udev_device_add_property_from_string(udev_device, key);
} }
if (!devpath_set) { }
if (!devpath_set || !subsystem_set || !action_set) {
info(udev_monitor->udev, "missing values, skip\n");
udev_device_unref(udev_device); udev_device_unref(udev_device);
return NULL; return NULL;
} }