diff mbox

[2/4] Load global config files by default

Message ID 1264099733-29666-3-git-send-email-aliguori@us.ibm.com
State New
Headers show

Commit Message

Anthony Liguori Jan. 21, 2010, 6:48 p.m. UTC
A new option, -nodefconfig is introduced to prevent loading from the default
config location.  Otherwise, two configuration files will be searched for,
qemu.conf and target-<TARGET_NAME>.conf.

The ordering is a little troubling.  Command line options are parsed before
loading the default configs which means that the command line configs will be
loaded before the default config.  The effect is that the default config will
override -readconfig directives.

It's unclear the best way to handle this.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 qemu-options.hx |    7 +++++++
 vl.c            |   23 +++++++++++++++++++++++
 2 files changed, 30 insertions(+), 0 deletions(-)

Comments

Gerd Hoffmann Jan. 22, 2010, 10:33 a.m. UTC | #1
On 01/21/10 19:48, Anthony Liguori wrote:
> The ordering is a little troubling.  Command line options are parsed before
> loading the default configs which means that the command line configs will be
> loaded before the default config.  The effect is that the default config will
> override -readconfig directives.
 >
> It's unclear the best way to handle this.

Maybe we need two passes over the command line options?

-confdir and -nodefconfig switches would be handled in the first pass, 
then read the global config files (unless disabled), then the second pass.

I think we could also make the default device handling less messy that 
way by checking -nographic and -nodefaults in the first pass too. 
Having the machine type (-M) read in the first pass could allow some 
cleanups too.

cheers,
   Gerd
diff mbox

Patch

diff --git a/qemu-options.hx b/qemu-options.hx
index ee60d8a..57f453d 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1965,6 +1965,13 @@  STEXI
 @item -writeconfig @var{file}
 Write device configuration to @var{file}.
 ETEXI
+DEF("nodefconfig", 0, QEMU_OPTION_nodefconfig,
+    "-nodefconfig\n"
+    "                do not load default config file\n")
+STEXI
+@item -nodefconfig
+Do not load default config files.
+ETEXI
 
 HXCOMM This is the last statement. Insert new options before this line!
 STEXI
diff --git a/vl.c b/vl.c
index e070ec9..cf12ab0 100644
--- a/vl.c
+++ b/vl.c
@@ -4690,6 +4690,7 @@  int main(int argc, char **argv, char **envp)
 #endif
     CPUState *env;
     int show_vnc_port = 0;
+    int defconfig = 1;
 
     init_clocks();
 
@@ -5457,6 +5458,9 @@  int main(int argc, char **argv, char **envp)
                     fclose(fp);
                     break;
                 }
+            case QEMU_OPTION_nodefconfig:
+                defconfig=0;
+                break;
             }
         }
     }
@@ -5471,6 +5475,25 @@  int main(int argc, char **argv, char **envp)
         data_dir = CONFIG_QEMU_SHAREDIR;
     }
 
+    if (defconfig) {
+        FILE *fp;
+        fp = fopen(CONFIG_QEMU_CONFDIR "/qemu.conf", "r");
+        if (fp) {
+            if (qemu_config_parse(fp) != 0) {
+                exit(1);
+            }
+            fclose(fp);
+        }
+
+        fp = fopen(CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".conf", "r");
+        if (fp) {
+            if (qemu_config_parse(fp) != 0) {
+                exit(1);
+            }
+            fclose(fp);
+        }
+    }
+
     /*
      * Default to max_cpus = smp_cpus, in case the user doesn't
      * specify a max_cpus value.