mirror of https://github.com/xqemu/xqemu.git
qemu-config: qemu_read_config_file() reads the normal config file
Introduce a new function qemu_read_config_file which reads the VM configuration from a config file. Unlike qemu_config_parse it doesn't take a open file but a filename and reduces code duplication as a side effect. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
6c557ab975
commit
dcfb0939bd
|
@ -488,3 +488,18 @@ out:
|
||||||
loc_pop(&loc);
|
loc_pop(&loc);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int qemu_read_config_file(const char *filename)
|
||||||
|
{
|
||||||
|
FILE *f = fopen(filename, "r");
|
||||||
|
if (f == NULL) {
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qemu_config_parse(f, filename) != 0) {
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -19,4 +19,6 @@ void qemu_add_globals(void);
|
||||||
void qemu_config_write(FILE *fp);
|
void qemu_config_write(FILE *fp);
|
||||||
int qemu_config_parse(FILE *fp, const char *fname);
|
int qemu_config_parse(FILE *fp, const char *fname);
|
||||||
|
|
||||||
|
int qemu_read_config_file(const char *filename);
|
||||||
|
|
||||||
#endif /* QEMU_CONFIG_H */
|
#endif /* QEMU_CONFIG_H */
|
||||||
|
|
35
vl.c
35
vl.c
|
@ -2653,25 +2653,16 @@ int main(int argc, char **argv, char **envp)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defconfig) {
|
if (defconfig) {
|
||||||
const char *fname;
|
int ret;
|
||||||
FILE *fp;
|
|
||||||
|
|
||||||
fname = CONFIG_QEMU_CONFDIR "/qemu.conf";
|
ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf");
|
||||||
fp = fopen(fname, "r");
|
if (ret == -EINVAL) {
|
||||||
if (fp) {
|
exit(1);
|
||||||
if (qemu_config_parse(fp, fname) != 0) {
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
fclose(fp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fname = arch_config_name;
|
ret = qemu_read_config_file(arch_config_name);
|
||||||
fp = fopen(fname, "r");
|
if (ret == -EINVAL) {
|
||||||
if (fp) {
|
exit(1);
|
||||||
if (qemu_config_parse(fp, fname) != 0) {
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
fclose(fp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cpudef_init();
|
cpudef_init();
|
||||||
|
@ -3327,16 +3318,12 @@ int main(int argc, char **argv, char **envp)
|
||||||
break;
|
break;
|
||||||
case QEMU_OPTION_readconfig:
|
case QEMU_OPTION_readconfig:
|
||||||
{
|
{
|
||||||
FILE *fp;
|
int ret = qemu_read_config_file(optarg);
|
||||||
fp = fopen(optarg, "r");
|
if (ret < 0) {
|
||||||
if (fp == NULL) {
|
fprintf(stderr, "read config %s: %s\n", optarg,
|
||||||
fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
|
strerror(-ret));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (qemu_config_parse(fp, optarg) != 0) {
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
fclose(fp);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QEMU_OPTION_writeconfig:
|
case QEMU_OPTION_writeconfig:
|
||||||
|
|
Loading…
Reference in New Issue