[lxc-devel] [Lxc-devel] [PATCH 1/5] Add pids of lxc-attach to the cgroup of container

"Axel Schöner" axel.schoener at gmx.de
Sun Oct 2 18:14:19 UTC 2011


The patchset adds the pids of the lxc-attach process to the cgroup of the corresponding container.

Because this is my first patch for lxc, someone should analyze it.
If you agree with the solution then integrate it.
If there is anything i should do better in future tell me please.

Axel Schöner

--- lxc_roh/src/lxc/namespace.c	2011-10-02 18:57:40.000000000 +0200
+++ lxc/src/lxc/namespace.c	2011-10-02 19:33:22.000000000 +0200
@@ -82,7 +82,7 @@
 	return ret;
 }
 
-int lxc_attach(pid_t pid)
+int lxc_attach(pid_t pid, const char* cgname)
 {
 	char path[MAXPATHLEN];
 	char *ns[] = { "pid", "mnt", "net", "ipc", "uts" };
@@ -104,6 +104,13 @@
 			return -1;
 		}
 	}
+	pid_t cpid = getpid();
+
+	/* Let's add the pid to the 'tasks' file */
+	if (lxc_cgroup_append_task(cgname, cpid)) {
+		SYSERROR("failed to attach pid '%d' to '%s'", cpid, cgname);
+		return -1;
+	}
 
 	for (i = 0; i < size; i++) {
 		if (setns(fd[i], 0)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch_attach_cgroup_1of5_namespace.c
Type: text/x-csrc
Size: 630 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20111002/3b988988/attachment.c>


More information about the lxc-devel mailing list