chiark / gitweb /
bus: don't calculate kmsg message too large
[elogind.git] / src / shared / unit-name.c
index cfe3133b5ae58fa4538af335f965fbf79d04f53b..a809713595f69b10849f97c9a0e7637c9f77ac59 100644 (file)
@@ -470,7 +470,6 @@ char *unit_dbus_path_from_name(const char *name) {
 char *unit_name_mangle(const char *name) {
         char *r, *t;
         const char *f;
-        bool dot = false;
 
         assert(name);
 
@@ -491,10 +490,6 @@ char *unit_name_mangle(const char *name) {
                 return NULL;
 
         for (f = name, t = r; *f; f++) {
-
-                if (*f == '.')
-                        dot = true;
-
                 if (*f == '/')
                         *(t++) = '-';
                 else if (!strchr("@" VALID_CHARS, *f))
@@ -503,7 +498,7 @@ char *unit_name_mangle(const char *name) {
                         *(t++) = *f;
         }
 
-        if (!dot)
+        if (unit_name_to_type(name) < 0)
                 strcpy(t, ".service");
         else
                 *t = 0;
@@ -511,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;