Beispiel #1
0
/*
 * TODO: this should be re-written to use the get_config_item("lxc.id_map")
 * cmd api instead of getting the idmap from c->lxc_conf.  The reason is
 * that the id_maps may be different if the container was started with a
 * -f or -s argument.
 * The reason I'm punting on that is because we'll need to parse the
 * idmap results.
 */
static bool cgm_attach(const char *name, const char *lxcpath, pid_t pid)
{
	bool pass = false;
	char *cgroup = NULL;
	struct lxc_container *c;

	c = lxc_container_new(name, lxcpath);
	if (!c) {
		ERROR("Could not load container %s:%s", lxcpath, name);
		return false;
	}
	if (!collect_subsytems()) {
		ERROR("Error collecting cgroup subsystems");
		goto out;
	}
	// cgm_create makes sure that we have the same cgroup name for all
	// subsystems, so since this is a slow command over the cmd socket,
	// just get the cgroup name for the first one.
	cgroup = lxc_cmd_get_cgroup_path(name, lxcpath, subsystems[0]);
	if (!cgroup) {
		ERROR("Failed to get cgroup for controller %s", subsystems[0]);
		goto out;
	}

	if (!(pass = do_cgm_enter(pid, cgroup)))
		ERROR("Failed to enter group %s", cgroup);

out:
	free(cgroup);
	lxc_container_put(c);
	return pass;
}
Beispiel #2
0
static inline bool cgm_init(struct lxc_handler *handler)
{
	if (!collect_subsytems())
		return false;
	if (geteuid())
		return true;
	// root;  try to escape to root cgroup
	return lxc_cgmanager_escape();
}
Beispiel #3
0
/*
 * called during cgroup.c:cgroup_ops_init(), at startup.  No threads.
 * We check whether we can talk to cgmanager, escape to root cgroup if
 * we are root, then close the connection.
 */
struct cgroup_ops *cgm_ops_init(void)
{
	check_supports_multiple_controllers(-1);
	if (!collect_subsytems())
		return NULL;

	if (api_version < CGM_SUPPORTS_MULT_CONTROLLERS)
		cgm_supports_multiple_controllers = false;

	// if root, try to escape to root cgroup
	if (geteuid() == 0 && !cgm_escape()) {
		free_subsystems();
		return NULL;
	}

	return &cgmanager_ops;
}
Beispiel #4
0
/*
 * called during cgroup.c:cgroup_ops_init(), at startup.  No threads.
 * We check whether we can talk to cgmanager, escape to root cgroup if
 * we are root, then close the connection.
 */
struct cgroup_ops *cgm_ops_init(void)
{
	if (!collect_subsytems())
		return NULL;
	if (!cgm_dbus_connect())
		goto err1;

	// root;  try to escape to root cgroup
	if (geteuid() == 0 && !lxc_cgmanager_escape())
		goto err2;
	cgm_dbus_disconnect();

	return &cgmanager_ops;

err2:
	cgm_dbus_disconnect();
err1:
	free_subsystems();
	return NULL;
}