[systemd-commits] 2 commits - man/systemd.unit.xml src/cgroup.c src/unit.c

Lennart Poettering lennart at kemper.freedesktop.org
Thu Jun 30 15:46:37 PDT 2011


 man/systemd.unit.xml |   14 ++++++++++---
 src/cgroup.c         |    2 -
 src/unit.c           |   54 +++++++++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 64 insertions(+), 6 deletions(-)

New commits:
commit 31e54cc807edf5294828233e53ca95e754c5cf80
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jul 1 00:41:41 2011 +0200

    cgroup: kill processes even in cgroups that aren't realized

diff --git a/src/cgroup.c b/src/cgroup.c
index a349158..d16b5f8 100644
--- a/src/cgroup.c
+++ b/src/cgroup.c
@@ -189,7 +189,7 @@ int cgroup_bonding_kill(CGroupBonding *b, int sig, bool sigcont, Set *s) {
         assert(sig >= 0);
 
         /* Don't kill cgroups that aren't ours */
-        if (!b->realized || !b->ours)
+        if (!b->ours)
                 return 0;
 
         return cg_kill_recursive(b->controller, b->path, sig, sigcont, true, false, s);

commit 0aef434548f43ce2635620e7f97073aa3e23cf96
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jul 1 00:41:18 2011 +0200

    unit: add three new specifiers to use in unit files

diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml
index 39da614..dd32e55 100644
--- a/man/systemd.unit.xml
+++ b/man/systemd.unit.xml
@@ -186,16 +186,24 @@
                 configuration options. Other specifiers that may be
                 used are <literal>%n</literal>, <literal>%N</literal>,
                 <literal>%p</literal>, <literal>%P</literal>,
-                <literal>%I</literal> and <literal>%f</literal>, for
+                <literal>%I</literal>, <literal>%f</literal>,
+                <literal>%c</literal>, <literal>%r</literal>,
+                <literal>%R</literal> and <literal>%t</literal> for
                 the full unit name, the unescaped unit name, the
                 prefix name, the unescaped prefix name, the unescaped
-                instance name and the unescaped filename,
+                instance name, the unescaped filename, the control
+                group path of the unit, the root control group path of
+                systemd, and the parent directory of the root control
+                cgroup path of systemd and the runtime socket dir,
                 respectively. The unescaped filename is either the
                 unescaped instance name (if set) with / prepended (if
                 necessary), or the prefix name similarly prepended
                 with /. The prefix name here refers to the string
                 before the @, i.e. "getty" in the example above, where
-                "tty3" is the instance name.</para>
+                "tty3" is the instance name. The runtime socket
+                directory is either <filename>/run</filename> (for the
+                system manager) or <literal>$XDG_RUNTIME_DIR</literal>
+                (for user managers).</para>
 
                 <para>If a unit file is empty (i.e. has the file size
                 0) or is symlinked to <filename>/dev/null</filename>
diff --git a/src/unit.c b/src/unit.c
index e3687d4..a207262 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -2003,6 +2003,47 @@ static char *specifier_filename(char specifier, void *data, void *userdata) {
         return unit_name_to_path(u->meta.instance);
 }
 
+static char *specifier_cgroup(char specifier, void *data, void *userdata) {
+        Unit *u = userdata;
+        assert(u);
+
+        return default_cgroup_path(u);
+}
+
+static char *specifier_cgroup_root(char specifier, void *data, void *userdata) {
+        Unit *u = userdata;
+        char *p;
+        assert(u);
+
+        if (specifier == 'r')
+                return strdup(u->meta.manager->cgroup_hierarchy);
+
+        if (parent_of_path(u->meta.manager->cgroup_hierarchy, &p) < 0)
+                return strdup("");
+
+        if (streq(p, "/")) {
+                free(p);
+                return strdup("");
+        }
+
+        return p;
+}
+
+static char *specifier_runtime(char specifier, void *data, void *userdata) {
+        Unit *u = userdata;
+        assert(u);
+
+        if (u->meta.manager->running_as == MANAGER_USER) {
+                const char *e;
+
+                e = getenv("XDG_RUNTIME_DIR");
+                if (e)
+                        return strdup(e);
+        }
+
+        return strdup("/run");
+}
+
 char *unit_name_printf(Unit *u, const char* format) {
 
         /*
@@ -2032,7 +2073,13 @@ char *unit_name_printf(Unit *u, const char* format) {
 char *unit_full_printf(Unit *u, const char *format) {
 
         /* This is similar to unit_name_printf() but also supports
-         * unescaping */
+         * unescaping. Also, adds a couple of additional codes:
+         *
+         * %c cgroup path of unit
+         * %r root cgroup path of this systemd instance (e.g. "/user/lennart/shared/systemd-4711")
+         * %R parent of root cgroup path (e.g. "/usr/lennart/shared")
+         * %t the runtime directory to place sockets in (e.g. "/run" or $XDG_RUNTIME_DIR)
+         */
 
         const Specifier table[] = {
                 { 'n', specifier_string,              u->meta.id },
@@ -2042,6 +2089,10 @@ char *unit_full_printf(Unit *u, const char *format) {
                 { 'i', specifier_string,              u->meta.instance },
                 { 'I', specifier_instance_unescaped,  NULL },
                 { 'f', specifier_filename,            NULL },
+                { 'c', specifier_cgroup,              NULL },
+                { 'r', specifier_cgroup_root,         NULL },
+                { 'R', specifier_cgroup_root,         NULL },
+                { 't', specifier_runtime,             NULL },
                 { 0, NULL, NULL }
         };
 
@@ -2420,7 +2471,6 @@ int unit_kill(Unit *u, KillWho w, KillMode m, int signo, DBusError *error) {
         return UNIT_VTABLE(u)->kill(u, w, m, signo, error);
 }
 
-
 int unit_following_set(Unit *u, Set **s) {
         assert(u);
         assert(s);



More information about the systemd-commits mailing list