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;
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);
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))) {
}
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) {
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);
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);
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;
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);
* 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)) {
*(t++) = *f;
}
- memcpy(t, suffix, c+1);
+ memcpy(t, suffix, b+1);
return r;
}
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);