]> err.no Git - systemd/commitdiff
unit-name: kill redundant slashes in unit_name_from_path()
authorLennart Poettering <lennart@poettering.net>
Fri, 14 May 2010 00:05:57 +0000 (02:05 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 14 May 2010 00:05:57 +0000 (02:05 +0200)
unit-name.c

index 5d428dd446af79e1049846e3491dacf4309c804c..c5901cacfa3bf9c14fd95b91e6a2c8e1a3d42110 100644 (file)
@@ -373,16 +373,27 @@ char *unit_name_template(const char *f) {
 }
 
 char *unit_name_from_path(const char *path, const char *suffix) {
+        char *p, *r;
+
         assert(path);
         assert(suffix);
 
-        if (path[0] == '/')
-                path++;
+        if (!(p = strdup(path)))
+                return NULL;
+
+        path_kill_slashes(p);
+
+        path = p[0] == '/' ? p + 1 : p;
 
-        if (path[0] == 0)
+        if (path[0] == 0) {
+                free(p);
                 return strappend("-", suffix);
+        }
+
+        r = unit_name_build_escape(path, NULL, suffix);
+        free(p);
 
-        return unit_name_build_escape(path, NULL, suffix);
+        return r;
 }
 
 char *unit_name_to_path(const char *name) {