Example #1
0
exception_t
skyeye_read_config (char* skyeye_conf_filename)
{
	FILE *config_fd;
	char *ret;
	char line[MAX_STR];

	//chy 2005-07-30
	//char *config_file = DEFAULT_CONFIG_FILE;
	/*if (skyeye_config_filename == NULL)
		skyeye_config_filename = DEFAULT_CONFIG_FILE;
	*/
	//char *skyeye_config_filename = get_conf_filename();
	/* FIXME, maybe we should reset memmap in another place */
	reset_global_memmap();

	if (config_fd = fopen (skyeye_conf_filename, "r")) {
		int retval = 0;
		int len = 0;

		do {
			ret = fgets (line, sizeof (line) - 1, config_fd);
			line[sizeof (line) - 1] = '\0';
			len = strlen (line);
			if (len > 0)
				line[len - 1] = '\0';
			if ((ret != NULL) && strlen (line)) {
				if (parse_line_unformatted (line) < 0) {
					retval = -1;
					//break;	// quit parsing after first error
				}
			}
		}
		while (!feof (config_fd));
#if 0
		/* 2007-01-18 added by Anthony Lee: for new uart device frame */
		if(skyeye_config.uart.count == 0)
		{
#ifndef SKYEYE4ECLIPSE
			char tmp[] = "uart: mod=stdio";
#else
			char tmp[1024];
			snprintf(tmp, sizeof(tmp), "uart: mod=pipe, desc=%s",
				 inferior_io_terminal, inferior_io_terminal);
#endif
			if(parse_line_unformatted(tmp) < 0) retval = -1;
		}
#endif
		if (retval < 0) {
			/*
			fprintf (stderr,
				 "skyeye_read_config: config file %s have errors!\n",
				 skyeye_config.config_file);
			*/
			skyeye_log(Error_log, __FUNCTION__, "Config format is wrong.\n ");
			return Conf_format_exp;
		}
	}
	else {
		/* fprintf (stderr,
			 "Failed to open skyeye config file %s in the same directory\n",
			 skyeye_config.config_file);
		*/
		skyeye_log(Debug_log, __FUNCTION__, "filename=%s\n",  skyeye_conf_filename);
		return File_open_exp;
		/*
		perror ("error");
		usage ();
		display_all_support();
		return -1;
		*/
	}

	/* compatiable with the old config file that is no arch option available. */

	skyeye_config_t* config = get_current_config();
	if(config->arch == NULL){
		config->arch = get_default_arch();
	}

	return No_exp;
}
Example #2
0
int main(int argc, char **argv)
{
        int c;
        char *domain = NULL;
        char *uri = "xen";
        char *file = NULL;
        bool xml = false;
        bool cap = false;
        struct domain *dominfo = NULL;
        struct capabilities *capsinfo = NULL;
        struct cap_domain_info *capgdinfo = NULL;
        int ret;

        static struct option lopts[] = {
                {"domain", 1, 0, 'd'},
                {"uri",    1, 0, 'u'},
                {"xml",    0, 0, 'x'},
                {"file",   1, 0, 'f'},
                {"cap",    0, 0, 'c'},
                {"help",   0, 0, 'h'},
                {0,        0, 0, 0}};

        while (1) {
                int optidx = 0;

                c = getopt_long(argc, argv, "d:u:f:xch", lopts, &optidx);
                if (c == -1)
                        break;

                switch (c) {
                case 'd':
                        domain = optarg;
                        break;

                case 'u':
                        uri = optarg;
                        break;

                case 'f':
                        file = optarg;
                        break;

                case 'x':
                        xml = true;
                        break;

                case 'c':
                        cap = true;
                        break;

                case '?':
                case 'h':
                        usage();
                        return c == '?';
                };
        }

        if (file != NULL)
                ret = dominfo_from_file(file, &dominfo);
        else if (domain != NULL)
                ret = dominfo_from_dom(uri, domain, &dominfo);
        else {
                printf("Need a data source (--domain or --file)\n");
                return 1;
        }

        if (ret == 0) {
                printf("Unable to get dominfo\n");
                return 2;
        }

        if (xml)
                print_domxml(dominfo, stdout);
        else {
                print_dominfo(dominfo, stdout);
                print_devices(dominfo, stdout);
        }

        if (cap && file == NULL) {
                ret = capinfo_for_dom(uri, dominfo, &capsinfo);
                if (ret == 0) {
                        printf("Unable to get capsinfo\n");
                        return 3;
                } else {
                        print_capabilities(capsinfo, stdout);
                        const char *os_type = get_ostype(dominfo);
                        const char *dom_type = get_domaintype(dominfo);
                        const char *def_arch = get_default_arch(capsinfo, os_type);

                        fprintf(stdout, "-- KVM is used: %s\n\n", (use_kvm(capsinfo)?"true":"false"));
                        fprintf(stdout, "-- For all following default OS type=%s\n", os_type);
                        fprintf(stdout, "-- Default Arch : %s\n", def_arch);

                        fprintf(stdout,
                                "-- Default Machine for arch=NULL : %s\n",
                                get_default_machine(capsinfo, os_type, NULL, NULL));
                        fprintf(stdout,
                                "-- Default Machine for arch=%s and domain type=NULL : %s\n",
                                def_arch,
                                get_default_machine(capsinfo, os_type, def_arch, NULL));
                        fprintf(stdout,
                                "-- Default Machine for arch=%s and domain type=%s : %s\n",
                                def_arch, dom_type,
                                get_default_machine(capsinfo, os_type, def_arch, dom_type));
                        fprintf(stdout,
                                "-- Default Machine for arch=NULL and domain type=%s : %s\n",
                                dom_type,
                                get_default_machine(capsinfo, os_type, NULL, dom_type));

                        fprintf(stdout,
                                "-- Default Emulator for arch=NULL : %s\n",
                                get_default_emulator(capsinfo, os_type, NULL, NULL));
                        fprintf(stdout,
                                "-- Default Emulator for arch=%s and domain type=NULL : %s\n",
                                def_arch,
                                get_default_emulator(capsinfo, os_type, def_arch, NULL));
                        fprintf(stdout,
                                "-- Default Emulator for arch=%s and domain type=%s : %s\n",
                                def_arch, dom_type,
                                get_default_emulator(capsinfo, os_type, def_arch, dom_type));
                        fprintf(stdout,
                                "-- Default Emulator for arch=NULL and domain type=%s : %s\n",
                                dom_type,
                                get_default_emulator(capsinfo, os_type, NULL, dom_type));

                        fprintf(stdout, "\n-- Default Domain Search for: \n"
                                "guest type=hvm - guest arch=* - guest domain type=kvm\n");
                        capgdinfo = findDomainInfo(capsinfo, "hvm", NULL, "kvm");
                        print_cap_domain_info(capgdinfo, stdout);

                        fprintf(stdout, "-- Default Domain Search for: \n"
                                "guest type=* - guest arch=* - guest domain type=*\n");
                        capgdinfo = findDomainInfo(capsinfo, NULL, NULL, NULL);
                        print_cap_domain_info(capgdinfo, stdout);

                        cleanup_capabilities(&capsinfo);
                }
        } else if (cap) {
                printf("Need a data source (--domain) to get default capabilities\n");
                return 4;
        }

        cleanup_dominfo(&dominfo);

        return 0;
}