mirror of
https://github.com/systemd/systemd.git
synced 2024-11-01 17:51:22 +03:00
udev: use sd_device for udev_event.dev_db
Also, this adds sd_device_unref for the object in udev_event_free() for safety and readability of code.
This commit is contained in:
parent
e0bb2ff94b
commit
480ecb7d28
@ -67,6 +67,8 @@ struct udev_event *udev_event_free(struct udev_event *event) {
|
|||||||
if (!event)
|
if (!event)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
udev_device_unref(event->dev);
|
||||||
|
sd_device_unref(event->dev_db_clone);
|
||||||
sd_netlink_unref(event->rtnl);
|
sd_netlink_unref(event->rtnl);
|
||||||
while ((p = hashmap_steal_first_key(event->run_list)))
|
while ((p = hashmap_steal_first_key(event->run_list)))
|
||||||
free(p);
|
free(p);
|
||||||
@ -739,8 +741,8 @@ static int update_devnode(struct udev_event *event) {
|
|||||||
return log_device_error_errno(dev, r, "Failed to get devnum: %m");
|
return log_device_error_errno(dev, r, "Failed to get devnum: %m");
|
||||||
|
|
||||||
/* remove/update possible left-over symlinks from old database entry */
|
/* remove/update possible left-over symlinks from old database entry */
|
||||||
if (event->dev_db)
|
if (event->dev_db_clone)
|
||||||
(void) udev_node_update_old_links(dev, event->dev_db->device);
|
(void) udev_node_update_old_links(dev, event->dev_db_clone);
|
||||||
|
|
||||||
if (!event->owner_set) {
|
if (!event->owner_set) {
|
||||||
r = device_get_devnode_uid(dev, &event->uid);
|
r = device_get_devnode_uid(dev, &event->uid);
|
||||||
@ -812,7 +814,6 @@ int udev_event_execute_rules(struct udev_event *event,
|
|||||||
usec_t timeout_usec, usec_t timeout_warn_usec,
|
usec_t timeout_usec, usec_t timeout_warn_usec,
|
||||||
Hashmap *properties_list,
|
Hashmap *properties_list,
|
||||||
struct udev_rules *rules) {
|
struct udev_rules *rules) {
|
||||||
_cleanup_(sd_device_unrefp) sd_device *clone = NULL;
|
|
||||||
sd_device *dev = event->dev->device;
|
sd_device *dev = event->dev->device;
|
||||||
const char *subsystem, *action;
|
const char *subsystem, *action;
|
||||||
int r;
|
int r;
|
||||||
@ -833,28 +834,24 @@ int udev_event_execute_rules(struct udev_event *event,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = device_clone_with_db(dev, &clone);
|
r = device_clone_with_db(dev, &event->dev_db_clone);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_device_debug_errno(dev, r, "Failed to clone sd_device object, ignoring: %m");
|
log_device_debug_errno(dev, r, "Failed to clone sd_device object, ignoring: %m");
|
||||||
|
|
||||||
if (clone) {
|
if (event->dev_db_clone) {
|
||||||
event->dev_db = udev_device_new(NULL, clone);
|
|
||||||
if (!event->dev_db)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
r = sd_device_get_devnum(dev, NULL);
|
r = sd_device_get_devnum(dev, NULL);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
if (r != -ENOENT)
|
if (r != -ENOENT)
|
||||||
log_device_debug_errno(dev, r, "Failed to get devnum, ignoring: %m");
|
log_device_debug_errno(dev, r, "Failed to get devnum, ignoring: %m");
|
||||||
|
|
||||||
if (streq(action, "move")) {
|
if (streq(action, "move")) {
|
||||||
r = device_copy_properties(dev, clone);
|
r = device_copy_properties(dev, event->dev_db_clone);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_device_debug_errno(dev, r, "Failed to copy properties from cloned device, ignoring: %m");
|
log_device_debug_errno(dev, r, "Failed to copy properties from cloned device, ignoring: %m");
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
/* Disable watch during event processing. */
|
/* Disable watch during event processing. */
|
||||||
(void) udev_watch_end(clone);
|
(void) udev_watch_end(event->dev_db_clone);
|
||||||
}
|
}
|
||||||
|
|
||||||
(void) udev_rules_apply_to_event(rules, event,
|
(void) udev_rules_apply_to_event(rules, event,
|
||||||
@ -865,12 +862,12 @@ int udev_event_execute_rules(struct udev_event *event,
|
|||||||
(void) update_devnode(event);
|
(void) update_devnode(event);
|
||||||
|
|
||||||
/* preserve old, or get new initialization timestamp */
|
/* preserve old, or get new initialization timestamp */
|
||||||
r = device_ensure_usec_initialized(dev, clone);
|
r = device_ensure_usec_initialized(dev, event->dev_db_clone);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_device_debug_errno(dev, r, "Failed to set initialization timestamp, ignoring: %m");
|
log_device_debug_errno(dev, r, "Failed to set initialization timestamp, ignoring: %m");
|
||||||
|
|
||||||
/* (re)write database file */
|
/* (re)write database file */
|
||||||
r = device_tag_index(dev, clone, true);
|
r = device_tag_index(dev, event->dev_db_clone, true);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_device_debug_errno(dev, r, "Failed to update tags under /run/udev/tag/, ignoring: %m");
|
log_device_debug_errno(dev, r, "Failed to update tags under /run/udev/tag/, ignoring: %m");
|
||||||
|
|
||||||
@ -880,7 +877,7 @@ int udev_event_execute_rules(struct udev_event *event,
|
|||||||
|
|
||||||
device_set_is_initialized(dev);
|
device_set_is_initialized(dev);
|
||||||
|
|
||||||
event->dev_db = udev_device_unref(event->dev_db);
|
event->dev_db_clone = sd_device_unref(event->dev_db_clone);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "alloc-util.h"
|
#include "alloc-util.h"
|
||||||
#include "conf-files.h"
|
#include "conf-files.h"
|
||||||
#include "def.h"
|
#include "def.h"
|
||||||
|
#include "device-util.h"
|
||||||
#include "dirent-util.h"
|
#include "dirent-util.h"
|
||||||
#include "escape.h"
|
#include "escape.h"
|
||||||
#include "fd-util.h"
|
#include "fd-util.h"
|
||||||
@ -2030,13 +2031,10 @@ int udev_rules_apply_to_event(
|
|||||||
const char *key = rules_str(rules, cur->key.value_off);
|
const char *key = rules_str(rules, cur->key.value_off);
|
||||||
const char *value;
|
const char *value;
|
||||||
|
|
||||||
value = udev_device_get_property_value(event->dev_db, key);
|
if (sd_device_get_property_value(event->dev_db_clone, key, &value) >= 0)
|
||||||
if (value != NULL)
|
|
||||||
udev_device_add_property(event->dev, key, value);
|
udev_device_add_property(event->dev, key, value);
|
||||||
else {
|
else if (cur->key.op != OP_NOMATCH)
|
||||||
if (cur->key.op != OP_NOMATCH)
|
goto nomatch;
|
||||||
goto nomatch;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TK_M_IMPORT_CMDLINE: {
|
case TK_M_IMPORT_CMDLINE: {
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
struct udev_event {
|
struct udev_event {
|
||||||
struct udev_device *dev;
|
struct udev_device *dev;
|
||||||
struct udev_device *dev_parent;
|
struct udev_device *dev_parent;
|
||||||
struct udev_device *dev_db;
|
sd_device *dev_db_clone;
|
||||||
char *name;
|
char *name;
|
||||||
char *program_result;
|
char *program_result;
|
||||||
mode_t mode;
|
mode_t mode;
|
||||||
|
Loading…
Reference in New Issue
Block a user