chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
list: make our list macros a bit easier to use by not requring type spec on each...
[elogind.git]
/
src
/
core
/
device.c
diff --git
a/src/core/device.c
b/src/core/device.c
index 0b01718ad4bc0ada8f79aa56f51b201319ba6c89..05950153d3c531a70ec335278f40da18ca76d630 100644
(file)
--- a/
src/core/device.c
+++ b/
src/core/device.c
@@
-48,7
+48,7
@@
static void device_unset_sysfs(Device *d) {
/* Remove this unit from the chain of devices which share the
* same sysfs path. */
first = hashmap_get(UNIT(d)->manager->devices_by_sysfs, d->sysfs);
/* Remove this unit from the chain of devices which share the
* same sysfs path. */
first = hashmap_get(UNIT(d)->manager->devices_by_sysfs, d->sysfs);
- LIST_REMOVE(
Device,
same_sysfs, first, d);
+ LIST_REMOVE(same_sysfs, first, d);
if (first)
hashmap_remove_and_replace(UNIT(d)->manager->devices_by_sysfs, d->sysfs, first->sysfs, first);
if (first)
hashmap_remove_and_replace(UNIT(d)->manager->devices_by_sysfs, d->sysfs, first->sysfs, first);
@@
-124,13
+124,13
@@
static void device_dump(Unit *u, FILE *f, const char *prefix) {
prefix, strna(d->sysfs));
}
prefix, strna(d->sysfs));
}
-static UnitActiveState device_active_state(Unit *u) {
+
_pure_
static UnitActiveState device_active_state(Unit *u) {
assert(u);
return state_translation_table[DEVICE(u)->state];
}
assert(u);
return state_translation_table[DEVICE(u)->state];
}
-static const char *device_sub_state_to_string(Unit *u) {
+
_pure_
static const char *device_sub_state_to_string(Unit *u) {
assert(u);
return device_state_to_string(DEVICE(u)->state);
assert(u);
return device_state_to_string(DEVICE(u)->state);
@@
-189,10
+189,12
@@
static int device_update_unit(Manager *m, struct udev_device *dev, const char *p
assert(m);
assert(m);
- if (!(sysfs = udev_device_get_syspath(dev)))
+ sysfs = udev_device_get_syspath(dev);
+ if (!sysfs)
return -ENOMEM;
return -ENOMEM;
- if ((r = device_find_escape_name(m, path, &u)) < 0)
+ r = device_find_escape_name(m, path, &u);
+ if (r < 0)
return r;
if (u && DEVICE(u)->sysfs && !path_equal(DEVICE(u)->sysfs, sysfs))
return r;
if (u && DEVICE(u)->sysfs && !path_equal(DEVICE(u)->sysfs, sysfs))
@@
-232,19
+234,23
@@
static int device_update_unit(Manager *m, struct udev_device *dev, const char *p
}
first = hashmap_get(m->devices_by_sysfs, sysfs);
}
first = hashmap_get(m->devices_by_sysfs, sysfs);
- LIST_PREPEND(
Device,
same_sysfs, first, DEVICE(u));
+ LIST_PREPEND(same_sysfs, first, DEVICE(u));
- if ((r = hashmap_replace(m->devices_by_sysfs, DEVICE(u)->sysfs, first)) < 0)
+ r = hashmap_replace(m->devices_by_sysfs, DEVICE(u)->sysfs, first);
+ if (r < 0)
goto fail;
}
if ((model = udev_device_get_property_value(dev, "ID_MODEL_FROM_DATABASE")) ||
(model = udev_device_get_property_value(dev, "ID_MODEL"))) {
goto fail;
}
if ((model = udev_device_get_property_value(dev, "ID_MODEL_FROM_DATABASE")) ||
(model = udev_device_get_property_value(dev, "ID_MODEL"))) {
- if ((r = unit_set_description(u, model)) < 0)
+ r = unit_set_description(u, model);
+ if (r < 0)
goto fail;
goto fail;
- } else
- if ((r = unit_set_description(u, path)) < 0)
+ } else {
+ r = unit_set_description(u, path);
+ if (r < 0)
goto fail;
goto fail;
+ }
if (main) {
/* The additional systemd udev properties we only
if (main) {
/* The additional systemd udev properties we only
@@
-257,7
+263,7
@@
static int device_update_unit(Manager *m, struct udev_device *dev, const char *p
size_t l;
FOREACH_WORD_QUOTED(w, l, alias, state) {
size_t l;
FOREACH_WORD_QUOTED(w, l, alias, state) {
- char *e;
+
_cleanup_free_
char *e;
e = strndup(w, l);
if (!e) {
e = strndup(w, l);
if (!e) {
@@
-265,13
+271,10
@@
static int device_update_unit(Manager *m, struct udev_device *dev, const char *p
goto fail;
}
goto fail;
}
- if (!is_path(e)) {
- log_warning("SYSTEMD_ALIAS for %s is not a path, ignoring: %s", sysfs, e);
- free(e);
- } else {
+ if (is_path(e))
device_update_unit(m, dev, e, false);
device_update_unit(m, dev, e, false);
- free(e);
- }
+ else
+ log_warning("SYSTEMD_ALIAS for %s is not a path, ignoring: %s", sysfs, e);
}
}
}
}
@@
-281,7
+284,7
@@
static int device_update_unit(Manager *m, struct udev_device *dev, const char *p
size_t l;
FOREACH_WORD_QUOTED(w, l, wants, state) {
size_t l;
FOREACH_WORD_QUOTED(w, l, wants, state) {
-
char *e
;
+
_cleanup_free_ char *e, *n = NULL
;
e = strndup(w, l);
if (!e) {
e = strndup(w, l);
if (!e) {
@@
-289,8
+292,13
@@
static int device_update_unit(Manager *m, struct udev_device *dev, const char *p
goto fail;
}
goto fail;
}
- r = unit_add_dependency_by_name(u, UNIT_WANTS, e, NULL, true);
- free(e);
+ n = unit_name_mangle(e);
+ if (!n) {
+ r = -ENOMEM;
+ goto fail;
+ }
+
+ r = unit_add_dependency_by_name(u, UNIT_WANTS, n, NULL, true);
if (r < 0)
goto fail;
}
if (r < 0)
goto fail;
}
@@
-312,6
+320,7
@@
fail:
static int device_process_new_device(Manager *m, struct udev_device *dev, bool update_state) {
const char *sysfs, *dn;
struct udev_list_entry *item = NULL, *first = NULL;
static int device_process_new_device(Manager *m, struct udev_device *dev, bool update_state) {
const char *sysfs, *dn;
struct udev_list_entry *item = NULL, *first = NULL;
+ int r;
assert(m);
assert(m);
@@
-319,7
+328,9
@@
static int device_process_new_device(Manager *m, struct udev_device *dev, bool u
return -ENOMEM;
/* Add the main unit named after the sysfs path */
return -ENOMEM;
/* Add the main unit named after the sysfs path */
- device_update_unit(m, dev, sysfs, true);
+ r = device_update_unit(m, dev, sysfs, true);
+ if (r < 0)
+ return r;
/* Add an additional unit for the device node */
if ((dn = udev_device_get_devnode(dev)))
/* Add an additional unit for the device node */
if ((dn = udev_device_get_devnode(dev)))
@@
-477,7
+488,6
@@
static void device_shutdown(Manager *m) {
}
static int device_enumerate(Manager *m) {
}
static int device_enumerate(Manager *m) {
- struct epoll_event ev;
int r;
struct udev_enumerate *e = NULL;
struct udev_list_entry *item = NULL, *first = NULL;
int r;
struct udev_enumerate *e = NULL;
struct udev_list_entry *item = NULL, *first = NULL;
@@
-485,6
+495,8
@@
static int device_enumerate(Manager *m) {
assert(m);
if (!m->udev) {
assert(m);
if (!m->udev) {
+ struct epoll_event ev;
+
if (!(m->udev = udev_new()))
return -ENOMEM;
if (!(m->udev = udev_new()))
return -ENOMEM;