summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/unit-name.c30
-rw-r--r--src/shared/unit-name.h1
2 files changed, 31 insertions, 0 deletions
diff --git a/src/shared/unit-name.c b/src/shared/unit-name.c
index 88ca0b8f2c..06bbfacb00 100644
--- a/src/shared/unit-name.c
+++ b/src/shared/unit-name.c
@@ -506,6 +506,36 @@ char *unit_name_mangle(const char *name) {
return r;
}
+char *snapshot_name_mangle(const char *name) {
+ char *r, *t;
+ const char *f;
+
+ assert(name);
+
+ /* Similar to unit_name_mangle(), but is called when we know
+ * that this is about snapshot units. */
+
+ r = new(char, strlen(name) * 4 + 1 + sizeof(".snapshot")-1);
+ if (!r)
+ return NULL;
+
+ for (f = name, t = r; *f; f++) {
+ if (*f == '/')
+ *(t++) = '-';
+ else if (!strchr(VALID_CHARS, *f))
+ t = do_escape_char(*f, t);
+ else
+ *(t++) = *f;
+ }
+
+ if (!endswith(name, ".snapshot"))
+ strcpy(t, ".snapshot");
+ else
+ *t = 0;
+
+ return r;
+}
+
UnitType unit_name_to_type(const char *n) {
const char *e;
diff --git a/src/shared/unit-name.h b/src/shared/unit-name.h
index d7528a3ac7..9150dd0b3f 100644
--- a/src/shared/unit-name.h
+++ b/src/shared/unit-name.h
@@ -94,3 +94,4 @@ char *unit_name_to_path(const char *name);
char *unit_dbus_path_from_name(const char *name);
char *unit_name_mangle(const char *name);
+char *snapshot_name_mangle(const char *name);