#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <syscall.h>
#include <sys/wait.h>
#include <inttypes.h>

static int __NR_sys_vserver= 273;
_syscall3(int, sys_vserver, uint32_t, cmd, uint32_t, id, void *, data);

#define VC_CAT_COMPAT	63
#define VC_CMD(c,i,v)	((((VC_CAT_ ## c) & 0x3F) << 24) \
	| (((i) & 0xFF) << 16) | ((v) & 0xFFF))

#define VCMD_new_s_context	VC_CMD(COMPAT, 1, 1)
#define VCMD_set_ipv4root	VC_CMD(COMPAT, 2, 3)

#define NB_IPV4ROOT	16

struct  vcmd_set_ipv4root_v3 {
	/* number of pairs in id */
	uint32_t broadcast;
	struct {
		uint32_t ip;
		uint32_t mask;
	} ip_mask_pair[NB_IPV4ROOT];
};


struct  vcmd_new_s_context_v1 {
uint32_t remove_cap;
uint32_t flags;
};

//----------------------------------------------------------------------

void start_ctx (int ctx_in) {
	int pid = fork ();
	if (pid==0) {
		int ctx = 0;
		long addr=0;
		struct vcmd_new_s_context_v1 data = {0,0};
		ctx = sys_vserver (VCMD_new_s_context, -1, &data);
		exit (0);
	}
}

//----------------------------------------------------------------------

void loop () {
	int i;
	printf( "loop()\n");
	while (1) {
		start_ctx (0);
	}
	exit(0);
}

//----------------------------------------------------------------------

int main (int argc, char ** argv) {

	signal (SIGCHLD, SIG_IGN);

	int i = 4;

	while (i--) {
		if (!fork()) {
			loop ();
		}
	}

}

//----------------------------------------------------------------------