+void associate_vserver_cgroup(char *slice_name, int pid)
+{
+ char cgroup_dir[4096], fn[4096];
+ struct stat st;
+ int result;
+ FILE *f;
+
+ sprintf(cgroup_dir, "/dev/cgroup/%s", slice_name);
+
+ result = stat(cgroup_dir, &st);
+ if (result != 0) {
+ // doesn't exist
+ return;
+ }
+
+ if (!S_ISDIR(st.st_mode)) {
+ // not a directory
+ return;
+ }
+
+ /* Write the pid to the cgroup tasks file, so the SSH process is associated
+ * with the correct cgroup
+ */
+
+ sprintf(fn, "%s/tasks", cgroup_dir);
+ f = fopen(fn, "wt");
+ if (f==NULL) {
+ // failed to open
+ return;
+ }
+
+ fprintf(f, "%d\n", pid);
+ fclose(f);
+}
+