summaryrefslogtreecommitdiff
path: root/src/login/sd-login.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-04-16 04:36:06 +0200
committerLennart Poettering <lennart@poettering.net>2013-04-16 04:41:21 +0200
commit7027ff61a34a12487712b382a061c654acc3a679 (patch)
tree05e9374a566d6accdd962dd4dc6d7076b9304122 /src/login/sd-login.c
parentcec4ead904978b07db2154c618eeb48d3102da66 (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/sd-login.c')
-rw-r--r--src/login/sd-login.c47
1 files changed, 12 insertions, 35 deletions
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;