"ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
":-_.\\"
-static const char* const unit_type_table[_UNIT_TYPE_MAX] = {
+const char* const unit_type_table[_UNIT_TYPE_MAX] = {
[UNIT_SERVICE] = "service",
[UNIT_SOCKET] = "socket",
[UNIT_TARGET] = "target",
DEFINE_STRING_TABLE_LOOKUP(unit_type, UnitType);
-static const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = {
+const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = {
[UNIT_STUB] = "stub",
[UNIT_LOADED] = "loaded",
[UNIT_ERROR] = "error",
char *unit_name_mangle(const char *name) {
char *r, *t;
const char *f;
- bool dot = false;
assert(name);
return NULL;
for (f = name, t = r; *f; f++) {
-
- if (*f == '.')
- dot = true;
-
if (*f == '/')
*(t++) = '-';
else if (!strchr("@" VALID_CHARS, *f))
*(t++) = *f;
}
- if (!dot)
+ if (unit_name_to_type(name) < 0)
strcpy(t, ".service");
else
*t = 0;
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;