Beispiel #1
0
static int do_freeze_thaw(bool freeze, const char *name, const char *lxcpath)
{
	int ret;
	char v[100];
	const char *state = freeze ? "FROZEN" : "THAWED";
	size_t state_len = 6;
	lxc_state_t new_state = freeze ? FROZEN : THAWED;

	ret = lxc_cgroup_set("freezer.state", state, name, lxcpath);
	if (ret < 0) {
		ERROR("Failed to freeze %s", name);
		return -1;
	}

	for (;;) {
		ret = lxc_cgroup_get("freezer.state", v, sizeof(v), name, lxcpath);
		if (ret < 0) {
			ERROR("Failed to get freezer state of %s", name);
			return -1;
		}

		v[99] = '\0';
		v[lxc_char_right_gc(v, strlen(v))] = '\0';

		ret = strncmp(v, state, state_len);
		if (ret == 0) {
			lxc_cmd_serve_state_clients(name, lxcpath, new_state);
			lxc_monitor_send_state(name, new_state, lxcpath);
			return 0;
		}

		sleep(1);
	}
}
Beispiel #2
0
/*
 * These are copied from conf.c.  However as conf.c will be moved to using
 * the callback system, they can be pulled from there eventually, so we
 * don't need to pollute utils.c with these low level functions
 */
static int find_fstype_cb(char* buffer, void *data)
{
	struct cbarg {
		const char *rootfs;
		const char *target;
		int mntopt;
	} *cbarg = data;

	char *fstype;

	/* we don't try 'nodev' entries */
	if (strstr(buffer, "nodev"))
		return 0;

	fstype = buffer;
	fstype += lxc_char_left_gc(fstype, strlen(fstype));
	fstype[lxc_char_right_gc(fstype, strlen(fstype))] = '\0';

	DEBUG("trying to mount '%s'->'%s' with fstype '%s'",
	      cbarg->rootfs, cbarg->target, fstype);

	if (mount(cbarg->rootfs, cbarg->target, fstype, cbarg->mntopt, NULL)) {
		DEBUG("mount failed with error: %s", strerror(errno));
		return 0;
	}

	INFO("mounted '%s' on '%s', with fstype '%s'",
	     cbarg->rootfs, cbarg->target, fstype);

	return 1;
}
Beispiel #3
0
lxc_state_t freezer_state(const char *name, const char *lxcpath)
{
	int ret;
	char v[100];

	ret = lxc_cgroup_get("freezer.state", v, sizeof(v), name, lxcpath);
	if (ret < 0)
		return -1;

	v[99] = '\0';
	v[lxc_char_right_gc(v, strlen(v))] = '\0';

	return lxc_str2state(v);
}
Beispiel #4
0
/*
 * These are copied from conf.c.  However as conf.c will be moved to using
 * the callback system, they can be pulled from there eventually, so we
 * don't need to pollute utils.c with these low level functions
 */
int find_fstype_cb(char *buffer, void *data)
{
	struct cbarg {
		const char *rootfs;
		const char *target;
		const char *options;
	} *cbarg = data;

	unsigned long mntflags;
	char *mntdata;
	char *fstype;

	/* we don't try 'nodev' entries */
	if (strstr(buffer, "nodev"))
		return 0;

	fstype = buffer;
	fstype += lxc_char_left_gc(fstype, strlen(fstype));
	fstype[lxc_char_right_gc(fstype, strlen(fstype))] = '\0';

	DEBUG("Trying to mount \"%s\"->\"%s\" with FSType \"%s\"", cbarg->rootfs,
	      cbarg->target, fstype);

	if (parse_mntopts(cbarg->options, &mntflags, &mntdata) < 0) {
		free(mntdata);
		return 0;
	}

	if (mount(cbarg->rootfs, cbarg->target, fstype, mntflags, mntdata)) {
		SYSDEBUG("Failed to mount");
		free(mntdata);
		return 0;
	}

	free(mntdata);

	INFO("Mounted \"%s\" on \"%s\", with FSType \"%s\"", cbarg->rootfs,
	     cbarg->target, fstype);

	return 1;
}