From: Lennart Poettering Date: Sun, 14 Feb 2010 00:02:46 +0000 (+0100) Subject: mount,device: drop prefix from unit names to make them easily decodable X-Git-Tag: 0.git+20100605+dfd8ee-1~302 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e478a46c3754ede1a7af57b961056a2a375a799;p=systemd mount,device: drop prefix from unit names to make them easily decodable --- diff --git a/device.c b/device.c index e3814dd9..c5901c95 100644 --- a/device.c +++ b/device.c @@ -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); diff --git a/mount.c b/mount.c index 4d05081d..b656ac2f 100644 --- a/mount.c +++ b/mount.c @@ -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; diff --git a/unit.c b/unit.c index 980c3711..39c9e5e7 100644 --- a/unit.c +++ b/unit.c @@ -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; } diff --git a/unit.h b/unit.h index 9527d192..f5eac291 100644 --- a/unit.h +++ b/unit.h @@ -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);