summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-01-14 02:11:57 +0100
committerLennart Poettering <lennart@poettering.net>2013-01-14 21:24:58 +0100
commit1dcf60656cc68cf0182703d77e31f24f05b0c8cc (patch)
tree32f46201784103ae013c03dd5b9b0b0ffa7293ad /src/shared
parentf84190d8cad66f36eef1d851213711244ca297be (diff)
systemctl: be smarter when mangling snapshot names
For "systemctl snapshot" it makes no sense to complete an incomplete name with ".service" as we previously did, use ".snapshot" instead. Also, don't bother with mount units or suchlike, we know that this must be a snapshot and hence is the only sane way for completion.
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);