]> err.no Git - systemd/commitdiff
mount,device: drop prefix from unit names to make them easily decodable
authorLennart Poettering <lennart@poettering.net>
Sun, 14 Feb 2010 00:02:46 +0000 (01:02 +0100)
committerLennart Poettering <lennart@poettering.net>
Sun, 14 Feb 2010 00:02:46 +0000 (01:02 +0100)
device.c
mount.c
unit.c
unit.h

index e3814dd933ee7158fe20fc3aded6fe918d38b667..c5901c95ff67697973ed4d22bc7bb65ddb1f5a9b 100644 (file)
--- 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 4d05081d11aa82d96f922bd375d4dfd225dd1146..b656ac2f74a7a8a1017fdbca45c886bf28dad774 100644 (file)
--- 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 980c3711eb147d60075c416643d54e74bd57f69a..39c9e5e7e83d86156ca6440a67bbf8ddae706c97 100644 (file)
--- 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 9527d192d1c45cb03c87b10b1f4c96fdd45aeb1a..f5eac2916d712aadf4613d7173abae71239f9180 100644 (file)
--- 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);