Beispiel #1
0
int main(int argc, char **argv)
{
	int *ct_root_pids;
	libct_session_t s;
	ct_handler_t ct;
	ct_process_desc_t p;

	ct_root_pids = mmap(NULL, 4096, PROT_READ | PROT_WRITE,
			MAP_SHARED | MAP_ANON, 0, 0);
	ct_root_pids[0] = 0;
	ct_root_pids[1] = 0;

	s = libct_session_open_local();
	ct = libct_container_create(s, "test");
	p = libct_process_desc_create(s);
	if (libct_container_set_nsmask(ct, CLONE_NEWPID | CLONE_NEWNS))
		return err("No pid & mount NS");

	libct_container_set_option(ct, LIBCT_OPT_AUTO_PROC_MOUNT, NULL);

	libct_container_spawn_cb(ct, p, set_ct_root_pids, ct_root_pids);
	libct_container_wait(ct);
	libct_container_destroy(ct);
	libct_session_close(s);

	/* Should be init */
	if ((ct_root_pids[0] != 1) || (ct_root_pids[1] != 1))
		return fail("Pid mismatch");
	else
		return pass("Pids are OK");
}
Beispiel #2
0
int main(int argc, char **argv)
{
	struct ct_arg cta;
	int pid, p[2], p2[2];
	libct_session_t s;
	ct_handler_t ct;
	int cg_ok = 0;
	char c;

	pipe(p);
	pipe(p2);
	cta.mark = mmap(NULL, 4096, PROT_READ | PROT_WRITE,
			MAP_SHARED | MAP_ANON, 0, 0);
	cta.mark[0] = 0;
	cta.start_fd = p2[1];
	cta.wait_fd = p[0];

	s = libct_session_open_local();
	ct = libct_container_create(s, "test-s");
	if (libct_container_set_option(ct, LIBCT_OPT_KILLABLE, NULL))
		return err("can't set killable");

	if (libct_container_spawn_cb(ct, set_ct_alive, &cta))
		return err("can't start CT");

	read(p2[0], &c, 1);
	if (cta.mark[0])
		cg_ok = check_service_cg(cta.mark[0]);
	write(p[1], &c, 1);

	libct_container_wait(ct);
	libct_container_destroy(ct);
	libct_session_close(s);

	if (!cta.mark[0])
		return fail("CT is not alive");

	if (!cg_ok)
		return fail("Service CG is not there");

	return pass("service CG works OK");
}