/* * Escape to the root cgroup if we are root, so that the container will * be in "/lxc/c1" rather than "/user/..../c1" * called internally with connection already open */ static bool lxc_cgmanager_escape(void) { bool ret = true; pid_t me = getpid(); char **slist = subsystems; int i; if (cgm_all_controllers_same) slist = subsystems_inone; for (i = 0; slist[i]; i++) { if (cgmanager_move_pid_abs_sync(NULL, cgroup_manager, slist[i], "/", me) != 0) { NihError *nerr; nerr = nih_error_get(); ERROR("call to cgmanager_move_pid_abs_sync(%s) failed: %s", slist[i], nerr->message); nih_free(nerr); ret = false; break; } } return ret; }
void cgm_escape(void) { if ( cgmanager_move_pid_abs_sync(NULL, cgroup_manager, ctrl_list, "/", (int32_t) getpid()) != 0) { NihError *nerr; nerr = nih_error_get(); fprintf(stderr, "warning: attempt to escape to root cgroup failed: %s\n", nerr->message); nih_free(nerr); } }
bool cgm_escape_cgroup(void) { if (!cgm_dbus_connect()) { return false; } if ( cgmanager_move_pid_abs_sync(NULL, cgroup_manager, "all", "/", (int32_t) getpid()) != 0 ) { NihError *nerr; nerr = nih_error_get(); fprintf(stderr, "call to move_pid_abs (all:/) failed: %s\n", nerr->message); nih_free(nerr); cgm_dbus_disconnect(); return false; } cgm_dbus_disconnect(); return true; }
static bool lxc_cgmanager_escape(void) { pid_t me = getpid(); int i; for (i = 0; i < nr_subsystems; i++) { if (cgmanager_move_pid_abs_sync(NULL, cgroup_manager, subsystems[i], "/", me) != 0) { NihError *nerr; nerr = nih_error_get(); ERROR("call to cgmanager_move_pid_abs_sync(%s) failed: %s", subsystems[i], nerr->message); nih_free(nerr); return false; } } return true; }
/* * Use the cgmanager to move a task into a cgroup for a particular * hierarchy. * All the subsystems in this hierarchy are co-mounted, so we only * need to transition the task into one of the cgroups * * Internal helper, must be called with cgmanager dbus socket open */ static bool lxc_cgmanager_enter(pid_t pid, const char *controller, const char *cgroup_path, bool abs) { int ret; if (abs) ret = cgmanager_move_pid_abs_sync(NULL, cgroup_manager, controller, cgroup_path, pid); else ret = cgmanager_move_pid_sync(NULL, cgroup_manager, controller, cgroup_path, pid); if (ret != 0) { NihError *nerr; nerr = nih_error_get(); ERROR("call to cgmanager_move_pid_%ssync failed: %s", abs ? "abs_" : "", nerr->message); nih_free(nerr); return false; } return true; }
/* * Escape to the root cgroup if we are root, so that the container will * be in "/lxc/c1" rather than "/user/..../c1" * called internally with connection already open */ static bool cgm_escape(void *hdata) { bool ret = true, cgm_needs_disconnect = false; pid_t me = getpid(); char **slist = subsystems; int i; if (!cgroup_manager) { if (!cgm_dbus_connect()) { ERROR("Error connecting to cgroup manager"); return false; } cgm_needs_disconnect = true; } if (cgm_all_controllers_same) slist = subsystems_inone; for (i = 0; slist[i]; i++) { if (cgmanager_move_pid_abs_sync(NULL, cgroup_manager, slist[i], "/", me) != 0) { NihError *nerr; nerr = nih_error_get(); ERROR("call to cgmanager_move_pid_abs_sync(%s) failed: %s", slist[i], nerr->message); nih_free(nerr); ret = false; break; } } if (cgm_needs_disconnect) cgm_dbus_disconnect(); return ret; }