core/device: also serialize/deserialize device syspath

The field will be used in later commits.
This commit is contained in:
Yu Watanabe
2022-10-26 01:50:23 +09:00
parent 54a4d71509
commit 1ea74fca3a
2 changed files with 13 additions and 2 deletions
+12 -1
View File
@@ -135,6 +135,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);
d->path = mfree(d->path);
}
@@ -392,6 +393,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);
if (d->path)
(void) serialize_item(f, "path", d->path);
@@ -413,7 +417,14 @@ static int device_deserialize_item(Unit *u, const char *key, const char *value,
assert(value);
assert(fds);
if (streq(key, "path")) {
if (streq(key, "sysfs")) {
if (!d->deserialized_sysfs) {
d->deserialized_sysfs = strdup(value);
if (!d->deserialized_sysfs)
log_oom_debug();
}
} else if (streq(key, "path")) {
if (!d->path) {
d->path = strdup(value);
if (!d->path)
+1 -1
View File
@@ -20,7 +20,7 @@ typedef enum DeviceFound {
struct Device {
Unit meta;
char *sysfs;
char *sysfs, *deserialized_sysfs;
char *path; /* syspath, device node, alias, or devlink */
/* In order to be able to distinguish dependencies on different device nodes we might end up creating multiple