Exemplo n.º 1
0
int main(){
	//Reserved for the file descriptor
	int fd;
	
	//Reserved to check the failures for the following functions
	int ret;
	
	//Create the "dump" directory if it doesn't exist, only owner has (full) access
	ret = mkdir("dump", 0700);
	if(ret == -1){
		perror("Error: Could not create dump folder.\n");
		return -1;
	}
	
	//Open if "dump" is a directory, or fail
	fd = open("dump", O_DIRECTORY);
	
	//Check if open didn't fail
	if(fd == -1){
		perror("Error: open failed to open the 'dump' directory.\n");
		return -1;	
	}
	
	//Preparation for CRIU:
	//Initial the request options
	ret = criu_init_opts();
	if(ret == -1){
		perror("Error: criu_init_opts failed to inital the request options.\n");
		return -1;
	}
	
	//Set the images directory, where they will be stored
	criu_set_images_dir_fd(fd);
	
	//Specify the CRIU service socket
	criu_set_service_address("criu_service.socket");
	
	//Specify how to connnect to service socket
	criu_set_service_comm(CRIU_COMM_SK);
	
	//To test whether the kernel support is up-to-dater
	ret = criu_check();
	if(ret < 0){
		perror("Error: criu_check failed.\n");
		return -1;
	}

	return 0;	
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
	int ret, fd;

	criu_set_service_address("criu_service.socket");

	puts("--- Check ---");
	ret = criu_check();
	if (ret < 0) {
		what_err_ret_mean(ret);
		return -1;
	} else
		puts("Success");

	puts("--- Dump loop ---");
	criu_init_opts();
	criu_set_pid(atoi(argv[1]));
	criu_set_log_file("dump.log");
	criu_set_log_level(4);
	fd = open("imgs_loop", O_DIRECTORY);
	criu_set_images_dir_fd(fd);

	ret = criu_dump();
	if (ret < 0) {
		what_err_ret_mean(ret);
		return -1;
	} else if (ret == 0)
		puts("Success");

	puts("--- Restore loop ---");
	criu_init_opts();
	criu_set_log_level(4);
	criu_set_log_file("restore.log");
	criu_set_images_dir_fd(fd);

	ret = criu_restore();
	if (ret < 0) {
		what_err_ret_mean(ret);
		return -1;
	} else if (ret > 0) {
		puts("Success");
		printf("pid %d\n", ret);
	}

	puts("--- Dump myself ---");
	criu_init_opts();
	criu_set_leave_running(true);
	criu_set_shell_job(true);
	criu_set_images_dir_fd(open("imgs_test", O_DIRECTORY));

	ret = criu_dump();
	if (ret < 0) {
		what_err_ret_mean(ret);
		return -1;
	} else {
		puts("Success");
		if (ret == 1)
			puts("Restored");
	}

	return 0;
}