]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/device: also serialize/deserialize device syspath
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 25 Oct 2022 12:41:17 +0000 (21:41 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 25 Oct 2022 16:50:23 +0000 (01:50 +0900)
The field will be used in later commits.

src/core/device.c
src/core/device.h

index c79fd08bbb4b61211ffa4888dca88e9e8484545d..7e354b2b4a73fbd7e3c0f90801cb0b2a60a92456 100644 (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)
index 7584bc70c4f609b9d7ca331404fad635dd594c2f..9dd6fb57c234738a48d464815abf4c9c46b695ec 100644 (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