chiark / gitweb /
Add mounting of a name=elogind cgroup if no init controller is found.
[elogind.git] / src / basic / unit-name.c
index f8965262c1130c806250532d44160554214fa247..de168353643077af9fd41324d61bacfe1fe2d5da 100644 (file)
@@ -118,6 +118,8 @@ bool unit_suffix_is_valid(const char *s) {
         return true;
 }
 
+/// UNNEEDED by elogind
+#if 0
 int unit_name_to_prefix(const char *n, char **ret) {
         const char *p;
         char *s;
@@ -142,8 +144,6 @@ int unit_name_to_prefix(const char *n, char **ret) {
         return 0;
 }
 
-/// UNNEEDED by elogind
-#if 0
 int unit_name_to_instance(const char *n, char **instance) {
         const char *p, *d;
         char *i;
@@ -196,7 +196,6 @@ int unit_name_to_prefix_and_instance(const char *n, char **ret) {
         *ret = s;
         return 0;
 }
-#endif // 0
 
 UnitType unit_name_to_type(const char *n) {
         const char *e;
@@ -211,8 +210,6 @@ UnitType unit_name_to_type(const char *n) {
         return unit_type_from_string(e + 1);
 }
 
-/// UNNEEDED by elogind
-#if 0
 int unit_name_change_suffix(const char *n, const char *suffix, char **ret) {
         char *e, *s;
         size_t a, b;
@@ -270,6 +267,8 @@ int unit_name_build(const char *prefix, const char *instance, const char *suffix
         return 0;
 }
 
+/// UNNEEDED by elogind
+#if 0
 static char *do_escape_char(char c, char *t) {
         assert(t);
 
@@ -443,8 +442,6 @@ int unit_name_path_unescape(const char *f, char **ret) {
         return 0;
 }
 
-/// UNNEEDED by elogind
-#if 0
 int unit_name_replace_instance(const char *f, const char *i, char **ret) {
         const char *p, *e;
         char *s;
@@ -500,7 +497,6 @@ int unit_name_template(const char *f, char **ret) {
         *ret = s;
         return 0;
 }
-#endif // 0
 
 int unit_name_from_path(const char *path, const char *suffix, char **ret) {
         _cleanup_free_ char *p = NULL;
@@ -526,8 +522,6 @@ int unit_name_from_path(const char *path, const char *suffix, char **ret) {
         return 0;
 }
 
-/// UNNEEDED by elogind
-#if 0
 int unit_name_from_path_instance(const char *prefix, const char *path, const char *suffix, char **ret) {
         _cleanup_free_ char *p = NULL;
         char *s;
@@ -568,7 +562,6 @@ int unit_name_to_path(const char *name, char **ret) {
 
         return unit_name_path_unescape(prefix, ret);
 }
-#endif // 0
 
 char *unit_dbus_path_from_name(const char *name) {
         _cleanup_free_ char *e = NULL;
@@ -598,6 +591,42 @@ int unit_name_from_dbus_path(const char *path, char **name) {
         return 0;
 }
 
+const char* unit_dbus_interface_from_type(UnitType t) {
+
+        static const char *const table[_UNIT_TYPE_MAX] = {
+                [UNIT_SERVICE] = "org.freedesktop.systemd1.Service",
+                [UNIT_SOCKET] = "org.freedesktop.systemd1.Socket",
+                [UNIT_BUSNAME] = "org.freedesktop.systemd1.BusName",
+                [UNIT_TARGET] = "org.freedesktop.systemd1.Target",
+                [UNIT_SNAPSHOT] = "org.freedesktop.systemd1.Snapshot",
+                [UNIT_DEVICE] = "org.freedesktop.systemd1.Device",
+                [UNIT_MOUNT] = "org.freedesktop.systemd1.Mount",
+                [UNIT_AUTOMOUNT] = "org.freedesktop.systemd1.Automount",
+                [UNIT_SWAP] = "org.freedesktop.systemd1.Swap",
+                [UNIT_TIMER] = "org.freedesktop.systemd1.Timer",
+                [UNIT_PATH] = "org.freedesktop.systemd1.Path",
+                [UNIT_SLICE] = "org.freedesktop.systemd1.Slice",
+                [UNIT_SCOPE] = "org.freedesktop.systemd1.Scope",
+        };
+
+        if (t < 0)
+                return NULL;
+        if (t >= _UNIT_TYPE_MAX)
+                return NULL;
+
+        return table[t];
+}
+
+const char *unit_dbus_interface_from_name(const char *name) {
+        UnitType t;
+
+        t = unit_name_to_type(name);
+        if (t < 0)
+                return NULL;
+
+        return unit_dbus_interface_from_type(t);
+}
+
 static char *do_escape_mangle(const char *f, UnitNameMangle allow_globs, char *t) {
         const char *valid_chars;
 
@@ -683,8 +712,6 @@ int unit_name_mangle_with_suffix(const char *name, UnitNameMangle allow_globs, c
         return 1;
 }
 
-/// UNNEEDED by elogind
-#if 0
 int slice_build_parent_slice(const char *slice, char **ret) {
         char *s, *dash;
         int r;
@@ -802,11 +829,13 @@ static const char* const unit_type_table[_UNIT_TYPE_MAX] = {
         [UNIT_TIMER] = "timer",
         [UNIT_PATH] = "path",
         [UNIT_SLICE] = "slice",
-        [UNIT_SCOPE] = "scope"
+        [UNIT_SCOPE] = "scope",
 };
 
 DEFINE_STRING_TABLE_LOOKUP(unit_type, UnitType);
 
+/// UNNEEDED by elogind
+#if 0
 static const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = {
         [UNIT_STUB] = "stub",
         [UNIT_LOADED] = "loaded",
@@ -848,3 +877,4 @@ static const char* const unit_dependency_table[_UNIT_DEPENDENCY_MAX] = {
 };
 
 DEFINE_STRING_TABLE_LOOKUP(unit_dependency, UnitDependency);
+#endif // 0