diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-04-16 04:36:06 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-04-16 04:41:21 +0200 |
commit | 7027ff61a34a12487712b382a061c654acc3a679 (patch) | |
tree | 05e9374a566d6accdd962dd4dc6d7076b9304122 /src/login | |
parent | cec4ead904978b07db2154c618eeb48d3102da66 (diff) |
nspawn: introduce the new /machine/ tree in the cgroup tree and move containers there
Containers will now carry a label (normally derived from the root
directory name, but configurable by the user), and the container's root
cgroup is /machine/<label>. This label is called "machine name", and can
cover both containers and VMs (as soon as libvirt also makes use of
/machine/).
libsystemd-login can be used to query the machine name from a process.
This patch also includes numerous clean-ups for the cgroup code.
Diffstat (limited to 'src/login')
-rw-r--r-- | src/login/libsystemd-login.sym | 1 | ||||
-rw-r--r-- | src/login/logind-dbus.c | 2 | ||||
-rw-r--r-- | src/login/logind-session.c | 1 | ||||
-rw-r--r-- | src/login/logind.c | 9 | ||||
-rw-r--r-- | src/login/sd-login.c | 47 |
5 files changed, 17 insertions, 43 deletions
diff --git a/src/login/libsystemd-login.sym b/src/login/libsystemd-login.sym index 9048de86a9..f4cd209700 100644 --- a/src/login/libsystemd-login.sym +++ b/src/login/libsystemd-login.sym @@ -68,4 +68,5 @@ global: LIBSYSTEMD_LOGIN_202 { global: sd_pid_get_user_unit; + sd_pid_get_machine_name; } LIBSYSTEMD_LOGIN_201; diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index d957bd7de5..228a8389ee 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -506,7 +506,7 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess dbus_message_iter_get_basic(&iter, &kill_processes); - r = cg_pid_get_cgroup(leader, NULL, &cgroup); + r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, leader, &cgroup); if (r < 0) goto fail; diff --git a/src/login/logind-session.c b/src/login/logind-session.c index da7ce42015..2f7ab3451f 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -436,7 +436,6 @@ static int session_create_one_group(Session *s, const char *controller, const ch int r; assert(s); - assert(controller); assert(path); if (s->leader > 0) { diff --git a/src/login/logind.c b/src/login/logind.c index aa3e5f0914..caed149ad6 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -1100,21 +1100,18 @@ int manager_get_user_by_cgroup(Manager *m, const char *cgroup, User **user) { } int manager_get_session_by_pid(Manager *m, pid_t pid, Session **session) { - char *p; + _cleanup_free_ char *p = NULL; int r; assert(m); assert(pid >= 1); assert(session); - r = cg_get_by_pid(SYSTEMD_CGROUP_CONTROLLER, pid, &p); + r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, pid, &p); if (r < 0) return r; - r = manager_get_session_by_cgroup(m, p, session); - free(p); - - return r; + return manager_get_session_by_cgroup(m, p, session); } void manager_cgroup_notify_empty(Manager *m, const char *cgroup) { diff --git a/src/login/sd-login.c b/src/login/sd-login.c index 4c918f2105..c97d75c000 100644 --- a/src/login/sd-login.c +++ b/src/login/sd-login.c @@ -33,51 +33,19 @@ #include "fileio.h" _public_ int sd_pid_get_session(pid_t pid, char **session) { - int r; - char *cgroup, *p; - if (pid < 0) return -EINVAL; if (!session) return -EINVAL; - r = cg_pid_get_cgroup(pid, NULL, &cgroup); - if (r < 0) - return r; - - if (!startswith(cgroup, "/user/")) { - free(cgroup); - return -ENOENT; - } - - p = strchr(cgroup + 6, '/'); - if (!p) { - free(cgroup); - return -ENOENT; - } - - p++; - if (startswith(p, "shared/") || streq(p, "shared")) { - free(cgroup); - return -ENOENT; - } - - p = strndup(p, strcspn(p, "/")); - free(cgroup); - - if (!p) - return -ENOMEM; - - *session = p; - return 0; + return cg_pid_get_session(pid, session); } _public_ int sd_pid_get_unit(pid_t pid, char **unit) { if (pid < 0) return -EINVAL; - if (!unit) return -EINVAL; @@ -88,13 +56,22 @@ _public_ int sd_pid_get_user_unit(pid_t pid, char **unit) { if (pid < 0) return -EINVAL; - if (!unit) return -EINVAL; return cg_pid_get_user_unit(pid, unit); } +_public_ int sd_pid_get_machine_name(pid_t pid, char **name) { + + if (pid < 0) + return -EINVAL; + if (!name) + return -EINVAL; + + return cg_pid_get_machine_name(pid, name); +} + _public_ int sd_pid_get_owner_uid(pid_t pid, uid_t *uid) { int r; char *root, *cgroup, *p, *cc; @@ -106,7 +83,7 @@ _public_ int sd_pid_get_owner_uid(pid_t pid, uid_t *uid) { if (!uid) return -EINVAL; - r = cg_pid_get_cgroup(pid, &root, &cgroup); + r = cg_pid_get_path_shifted(pid, &root, &cgroup); if (r < 0) return r; |