66 lines
2.1 KiB
Diff
66 lines
2.1 KiB
Diff
From 1ea74fca3a3c737f3901bc10d879b7830b3528bf Mon Sep 17 00:00:00 2001
|
|
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
|
Date: Tue, 25 Oct 2022 21:41:17 +0900
|
|
Subject: [PATCH] core/device: also serialize/deserialize device syspath
|
|
|
|
The field will be used in later commits.
|
|
---
|
|
src/core/device.c | 13 ++++++++++++-
|
|
src/core/device.h | 2 +-
|
|
2 files changed, 13 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/src/core/device.c b/src/core/device.c
|
|
index 9d694aa..26a6d1f 100644
|
|
--- a/src/core/device.c
|
|
+++ b/src/core/device.c
|
|
@@ -114,6 +114,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);
|
|
}
|
|
|
|
@@ -295,6 +296,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);
|
|
diff --git a/src/core/device.h b/src/core/device.h
|
|
index dfe8a13..99bf134 100644
|
|
--- a/src/core/device.h
|
|
+++ b/src/core/device.h
|
|
@@ -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. */
|
|
--
|
|
2.33.0
|
|
|