]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/device: store the original path
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 29 Apr 2022 17:35:16 +0000 (02:35 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 5 Aug 2022 13:13:47 +0000 (22:13 +0900)
The unit name may be hashed. Hence, we cannot obtain the original path
from the unit name.

The path will be used in the later commits.

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

index e3c9ada23f5022c13aa177f658ce0d8d67baa093..2defc4d128d537b140cea63d8146665e3a887fc1 100644 (file)
@@ -116,6 +116,7 @@ static void device_done(Unit *u) {
 
         device_unset_sysfs(d);
         d->wants_property = strv_free(d->wants_property);
+        d->path = mfree(d->path);
 }
 
 static int device_load(Unit *u) {
@@ -293,6 +294,9 @@ static int device_serialize(Unit *u, FILE *f, FDSet *fds) {
         assert(f);
         assert(fds);
 
+        if (d->path)
+                (void) serialize_item(f, "path", d->path);
+
         (void) serialize_item(f, "state", device_state_to_string(d->state));
 
         if (device_found_to_string_many(d->found, &s) >= 0)
@@ -311,7 +315,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, "path")) {
+                if (!d->path) {
+                        d->path = strdup(value);
+                        if (!d->path)
+                                log_oom_debug();
+                }
+
+        } else if (streq(key, "state")) {
                 DeviceState state;
 
                 state = device_state_from_string(value);
@@ -341,9 +352,11 @@ static void device_dump(Unit *u, FILE *f, const char *prefix) {
 
         fprintf(f,
                 "%sDevice State: %s\n"
+                "%sDevice Path: %s\n"
                 "%sSysfs Path: %s\n"
                 "%sFound: %s\n",
                 prefix, device_state_to_string(d->state),
+                prefix, strna(d->path),
                 prefix, strna(d->sysfs),
                 prefix, strna(s));
 
@@ -566,6 +579,12 @@ static int device_setup_unit(Manager *m, sd_device *dev, const char *path, bool
                 unit_add_to_load_queue(u);
         }
 
+        if (!DEVICE(u)->path) {
+                DEVICE(u)->path = strdup(path);
+                if (!DEVICE(u)->path)
+                        return log_oom();
+        }
+
         /* If this was created via some dependency and has not actually been seen yet ->sysfs will not be
          * initialized. Hence initialize it if necessary. */
         if (sysfs) {
index dfe8a13aff93b8a8afee292d71cc63b209df3f6a..7584bc70c4f609b9d7ca331404fad635dd594c2f 100644 (file)
@@ -21,6 +21,7 @@ struct Device {
         Unit meta;
 
         char *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
          * devices for the same sysfs path. We chain them up here. */