示例#1
0
文件: cgmanager.c 项目: skizhak/lxc
/*
 * 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;
}
示例#2
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;
    char *cgroup = NULL;

    if (!cgm_dbus_connect()) {
        ERROR("Error connecting to cgroup manager");
        return false;
    }
    // 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 = try_get_abs_cgroup(name, lxcpath, subsystems[0]);
    if (!cgroup) {
        ERROR("Failed to get cgroup for controller %s", subsystems[0]);
        cgm_dbus_disconnect();
        return false;
    }

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

    free_abs_cgroup(cgroup);
    return pass;
}
示例#3
0
static inline bool cgm_enter(void *hdata, pid_t pid)
{
    struct cgm_data *d = hdata;
    bool ret = false;

    if (!cgm_dbus_connect()) {
        ERROR("Error connecting to cgroup manager");
        return false;
    }
    if (!d || !d->cgroup_path)
        goto out;
    if (do_cgm_enter(pid, d->cgroup_path, false))
        ret = true;
out:
    cgm_dbus_disconnect();
    return ret;
}
示例#4
0
文件: cgmanager.c 项目: skizhak/lxc
static inline bool cgm_enter(struct lxc_handler *handler)
{
	char *cgroup_path = handler->cgroup_info->data;
	return do_cgm_enter(handler->pid, cgroup_path);
}