diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-04-30 02:35:16 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-08-05 22:13:47 +0900 |
commit | 367a2597c35140fb325e2f94235961257130dfe1 (patch) | |
tree | b11ba366c20188a3c9635166df115fd34cd07e82 /src/core/device.c | |
parent | 7870de03c52982290f9b8ae11eb4d89db66f4be3 (diff) | |
download | systemd-367a2597c35140fb325e2f94235961257130dfe1.tar.gz |
core/device: store the original path
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.
Diffstat (limited to 'src/core/device.c')
-rw-r--r-- | src/core/device.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/core/device.c b/src/core/device.c index e3c9ada23f..2defc4d128 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -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) { |