chiark / gitweb /
bus: don't calculate kmsg message too large
[elogind.git] / src / shared / unit-name.c
index 50031e608e066b299b216dd4c8878167cafde49f..a809713595f69b10849f97c9a0e7637c9f77ac59 100644 (file)
@@ -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;