summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-05-14 02:05:57 +0200
committerLennart Poettering <lennart@poettering.net>2010-05-14 02:05:57 +0200
commit5ffceb2feae45b19a39d545468552ff2b7fb8e6d (patch)
treee59c3a19aef1879e4a8e5e065627bee1f407c80c
parent2a1a539789190c2d413710bcd88f1e351400d700 (diff)
unit-name: kill redundant slashes in unit_name_from_path()
-rw-r--r--unit-name.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/unit-name.c b/unit-name.c
index 5d428dd446..c5901cacfa 100644
--- a/unit-name.c
+++ b/unit-name.c
@@ -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) {