mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-07 17:17:44 +03:00
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.
This commit is contained in:
parent
7870de03c5
commit
367a2597c3
@ -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) {
|
||||
|
@ -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. */
|
||||
|
Loading…
Reference in New Issue
Block a user