1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-25 18:50:18 +03:00

mount,device: drop prefix from unit names to make them easily decodable

This commit is contained in:
Lennart Poettering 2010-02-14 01:02:46 +01:00
parent 6be1e7d538
commit 2e478a46c3
4 changed files with 17 additions and 23 deletions

View File

@ -87,7 +87,7 @@ static UnitActiveState device_active_state(Unit *u) {
return state_translation_table[DEVICE(u)->state];
}
static int device_add_escaped_name(Unit *u, const char *prefix, const char *dn, bool make_id) {
static int device_add_escaped_name(Unit *u, const char *dn, bool make_id) {
char *e;
int r;
@ -95,7 +95,7 @@ static int device_add_escaped_name(Unit *u, const char *prefix, const char *dn,
assert(dn);
assert(dn[0] == '/');
if (!(e = unit_name_escape_path(prefix, dn+1, ".device")))
if (!(e = unit_name_escape_path(dn+1, ".device")))
return -ENOMEM;
r = unit_add_name(u, e);
@ -137,7 +137,7 @@ static int device_process_new_device(Manager *m, struct udev_device *dev, bool u
return -ENOMEM;
assert(sysfs[0] == '/');
if (!(e = unit_name_escape_path("sysfs-", sysfs+1, ".device")))
if (!(e = unit_name_escape_path(sysfs+1, ".device")))
return -ENOMEM;
if (!(u = manager_get_unit(m, e))) {
@ -173,12 +173,12 @@ static int device_process_new_device(Manager *m, struct udev_device *dev, bool u
}
if (dn)
if ((r = device_add_escaped_name(u, "node-", dn, true)) < 0)
if ((r = device_add_escaped_name(u, dn, true)) < 0)
goto fail;
first = udev_device_get_devlinks_list_entry(dev);
udev_list_entry_foreach(item, first)
if ((r = device_add_escaped_name(u, "node-", udev_list_entry_get_name(item), false)) < 0)
if ((r = device_add_escaped_name(u, udev_list_entry_get_name(item), false)) < 0)
goto fail;
if (names) {
@ -252,7 +252,7 @@ static int device_process_removed_device(Manager *m, struct udev_device *dev) {
return -ENOMEM;
assert(sysfs[0] == '/');
if (!(e = unit_name_escape_path("sysfs-", sysfs+1, ".device")))
if (!(e = unit_name_escape_path(sysfs+1, ".device")))
return -ENOMEM;
u = manager_get_unit(m, e);

View File

@ -125,7 +125,7 @@ static int mount_add_node_links(Mount *m) {
if (!path_startswith(m->what, "/dev/"))
return 0;
if (!(e = unit_name_escape_path("node-", m->what+1, ".device")))
if (!(e = unit_name_escape_path(m->what+1, ".device")))
return -ENOMEM;
r = manager_load_unit(UNIT(m)->meta.manager, e, &device);
@ -197,9 +197,9 @@ static int mount_add_one(Manager *m, const char *what, const char *where, bool l
return 0;
if (streq(where, "/"))
e = strdup("rootfs.mount");
e = strdup("-.mount");
else
e = unit_name_escape_path("fs-", where+1, ".mount");
e = unit_name_escape_path(where+1, ".mount");
if (!e)
return -ENOMEM;

20
unit.c
View File

@ -1001,10 +1001,10 @@ int set_unit_path(const char *p) {
return 0;
}
char *unit_name_escape_path(const char *prefix, const char *path, const char *suffix) {
char *unit_name_escape_path(const char *path, const char *suffix) {
char *r, *t;
const char *f;
size_t a, b, c;
size_t a, b;
assert(path);
@ -1017,22 +1017,16 @@ char *unit_name_escape_path(const char *prefix, const char *path, const char *su
* escaping is hence reversible.
*/
if (!prefix)
prefix = "";
if (!suffix)
suffix = "";
a = strlen(prefix);
b = strlen(path);
c = strlen(suffix);
a = strlen(path);
b = strlen(suffix);
if (!(r = new(char, a+b*4+c+1)))
if (!(r = new(char, a*4+b+1)))
return NULL;
memcpy(r, prefix, a);
for (f = path, t = r+a; *f; f++) {
for (f = path, t = r; *f; f++) {
if (*f == '/')
*(t++) = '.';
else if (*f == '.' || *f == '\\' || !strchr(VALID_CHARS, *f)) {
@ -1044,7 +1038,7 @@ char *unit_name_escape_path(const char *prefix, const char *path, const char *su
*(t++) = *f;
}
memcpy(t, suffix, c+1);
memcpy(t, suffix, b+1);
return r;
}

2
unit.h
View File

@ -284,7 +284,7 @@ bool unit_job_is_applicable(Unit *u, JobType j);
int set_unit_path(const char *p);
char *unit_name_escape_path(const char *prefix, const char *path, const char *suffix);
char *unit_name_escape_path(const char *path, const char *suffix);
const char *unit_type_to_string(UnitType i);
UnitType unit_type_from_string(const char *s);