chiark / gitweb /
label: if the selinux policy knows no label, then silently don't do anything
[elogind.git] / src / unit-name.c
index 0e86b554c2eee4382c742fdd2f107b2e8ce01aed..dbaa4a7b12c3acdf5b02b323e236477e0336d8cb 100644 (file)
@@ -32,7 +32,7 @@
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ"            \
         ":-_.\\"
 
-bool unit_name_is_valid_no_type(const char *n) {
+bool unit_name_is_valid_no_type(const char *n, bool template_ok) {
         const char *e, *i, *at;
 
         /* Valid formats:
@@ -63,7 +63,7 @@ bool unit_name_is_valid_no_type(const char *n) {
                 if (at == n)
                         return false;
 
-                if (at[1] == '.')
+                if (!template_ok && at+1 == e)
                         return false;
         }
 
@@ -150,7 +150,7 @@ char *unit_name_change_suffix(const char *n, const char *suffix) {
         size_t a, b;
 
         assert(n);
-        assert(unit_name_is_valid_no_type(n));
+        assert(unit_name_is_valid_no_type(n, true));
         assert(suffix);
 
         assert_se(e = strrchr(n, '.'));
@@ -377,6 +377,30 @@ char *unit_name_from_path(const char *path, const char *suffix) {
         return r;
 }
 
+char *unit_name_from_path_instance(const char *prefix, const char *path, const char *suffix) {
+        char *p, *r;
+
+        assert(path);
+        assert(suffix);
+
+        if (!(p = strdup(path)))
+                return NULL;
+
+        path_kill_slashes(p);
+
+        path = p[0] == '/' ? p + 1 : p;
+
+        if (path[0] == 0) {
+                free(p);
+                return unit_name_build_escape(prefix, "-", suffix);
+        }
+
+        r = unit_name_build_escape(prefix, path, suffix);
+        free(p);
+
+        return r;
+}
+
 char *unit_name_to_path(const char *name) {
         char *w, *e;