1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-21 18:03:41 +03:00

core/device: also serialize/deserialize device syspath

The field will be used in later commits.

(cherry picked from commit 1ea74fca3a3c737f3901bc10d879b7830b3528bf)
(cherry picked from commit 9523f85b2ecb5088a08ff9a3037459623bf774f5)
This commit is contained in:
Yu Watanabe 2022-10-25 21:41:17 +09:00 committed by Zbigniew Jędrzejewski-Szmek
parent 118e550c88
commit 3cc039108b
2 changed files with 13 additions and 2 deletions

View File

@ -115,6 +115,7 @@ static void device_done(Unit *u) {
assert(d);
device_unset_sysfs(d);
d->deserialized_sysfs = mfree(d->deserialized_sysfs);
d->wants_property = strv_free(d->wants_property);
}
@ -294,6 +295,9 @@ static int device_serialize(Unit *u, FILE *f, FDSet *fds) {
assert(f);
assert(fds);
if (d->sysfs)
(void) serialize_item(f, "sysfs", d->sysfs);
(void) serialize_item(f, "state", device_state_to_string(d->state));
if (device_found_to_string_many(d->found, &s) >= 0)
@ -312,7 +316,14 @@ static int device_deserialize_item(Unit *u, const char *key, const char *value,
assert(value);
assert(fds);
if (streq(key, "state")) {
if (streq(key, "sysfs")) {
if (!d->deserialized_sysfs) {
d->deserialized_sysfs = strdup(value);
if (!d->deserialized_sysfs)
log_oom_debug();
}
} else if (streq(key, "state")) {
DeviceState state;
state = device_state_from_string(value);

View File

@ -20,7 +20,7 @@ typedef enum DeviceFound {
struct Device {
Unit meta;
char *sysfs;
char *sysfs, *deserialized_sysfs;
/* In order to be able to distinguish dependencies on different device nodes we might end up creating multiple
* devices for the same sysfs path. We chain them up here. */