Skip to contentSkip to conversation

Fix 'name' option to work with -readconfig

PATCH Applied Dr. David Alan Gilbert (git) 4 participants 7 messages May 6, 2014 – May 27, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix 'name' option to work with -readconfig

From: "Dr. David Alan Gilbert" <[email protected]>

The 'name' option silently failed when used in config files ( http://lists.gnu.org/archive/html/qemu-devel/2014-04/msg00378.html )

---
 vl.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
vl.c +7 -2
index 8411a4a..47c199a 100644
@@ -965,7 +965,7 @@ static int parse_sandbox(QemuOpts *opts, void *opaque)
     return 0;
 }
 
-static void parse_name(QemuOpts *opts)
+static int parse_name(QemuOpts *opts, void *opaque)
 {
     const char *proc_name;
 
@@ -978,6 +978,8 @@ static void parse_name(QemuOpts *opts)
     if (proc_name) {
         os_set_proc_name(proc_name);
     }
+
+    return 0;
 }
 
 bool usb_enabled(bool default_usb)
@@ -3780,7 +3782,6 @@ int main(int argc, char **argv, char **envp)
                 if (!opts) {
                     exit(1);
                 }
-                parse_name(opts);
                 break;
             case QEMU_OPTION_prom_env:
                 if (nb_prom_envs >= MAX_PROM_ENVS) {
@@ -3955,6 +3956,10 @@ int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
+    if (qemu_opts_foreach(qemu_find_opts("name"), parse_name, NULL, 1)) {
+        exit(1);
+    }
+
 #ifndef _WIN32
     if (qemu_opts_foreach(qemu_find_opts("add-fd"), parse_add_fd, NULL, 1)) {
         exit(1);
Signature · 1 line
1.9.0
Tested-by on v1 1/1
#1 lore raw
Quoted 7 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

The 'name' option silently failed when used in config files ( http://lists.gnu.org/archive/html/qemu-devel/2014-04/msg00378.html )

Please use:

I have also successfully tested the patch

Thanks,

Signature · 1 line
William
Reviewed-by on v1 1/1
#2 lore raw
In reply to Dr. David Alan Gilbert (git)
Quoted 42 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

The 'name' option silently failed when used in config files ( http://lists.gnu.org/archive/html/qemu-devel/2014-04/msg00378.html )

---
 vl.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
vl.c +3 -2
index 8411a4a..47c199a 100644
@@ -965,7 +965,7 @@ static int parse_sandbox(QemuOpts *opts, void *opaque)
     return 0;
 }
 
-static void parse_name(QemuOpts *opts)
+static int parse_name(QemuOpts *opts, void *opaque)
 {
     const char *proc_name;
 
@@ -978,6 +978,8 @@ static void parse_name(QemuOpts *opts)
     if (proc_name) {
         os_set_proc_name(proc_name);
     }
+
+    return 0;
 }
 
 bool usb_enabled(bool default_usb)
@@ -3780,7 +3782,6 @@ int main(int argc, char **argv, char **envp)
                 if (!opts) {
                     exit(1);
                 }
-                parse_name(opts);
                 break;
             case QEMU_OPTION_prom_env:
                 if (nb_prom_envs >= MAX_PROM_ENVS) {

vl.c int main(int argc, char **argv, char **envp) · line 3962

Quoted 7 lines
vl.c +4 -0
@@ -3955,6 +3956,10 @@ int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
+    if (qemu_opts_foreach(qemu_find_opts("name"), parse_name, NULL, 1)) {
+        exit(1);
+    }
+

This will never exit, but that's okay.

vl.c int main(int argc, char **argv, char **envp) · line 3965

Quoted 3 lines
vl.c +0 -0
 #ifndef _WIN32
     if (qemu_opts_foreach(qemu_find_opts("add-fd"), parse_add_fd, NULL, 1)) {
         exit(1);

-readconfig stores the configuration read in QemuOpts. Command line option parsing should do the same, and no more. In particular it should not act upon the option. That needs to be done separately, where both command line and -readconfig settings are visible in QemuOpts.

Your patch does exactly that. I think amending the commit message with the previous paragraph would improve it.

Have you checked command line option parsing (the big switch) for similar problems?

#3 lore raw
Quoted 47 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 45 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

The 'name' option silently failed when used in config files ( http://lists.gnu.org/archive/html/qemu-devel/2014-04/msg00378.html )

---
 vl.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
vl.c +3 -2
index 8411a4a..47c199a 100644
@@ -965,7 +965,7 @@ static int parse_sandbox(QemuOpts *opts, void *opaque)
     return 0;
 }
 
-static void parse_name(QemuOpts *opts)
+static int parse_name(QemuOpts *opts, void *opaque)
 {
     const char *proc_name;
 
@@ -978,6 +978,8 @@ static void parse_name(QemuOpts *opts)
     if (proc_name) {
         os_set_proc_name(proc_name);
     }
+
+    return 0;
 }
 
 bool usb_enabled(bool default_usb)
@@ -3780,7 +3782,6 @@ int main(int argc, char **argv, char **envp)
                 if (!opts) {
                     exit(1);
                 }
-                parse_name(opts);
                 break;
             case QEMU_OPTION_prom_env:
                 if (nb_prom_envs >= MAX_PROM_ENVS) {
@@ -3955,6 +3956,10 @@ int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
Quoted 6 lines

vl.c int main(int argc, char **argv, char **envp) · line 3962

Quoted 4 lines
vl.c +4 -0
+    if (qemu_opts_foreach(qemu_find_opts("name"), parse_name, NULL, 1)) {
+        exit(1);
+    }
+

This will never exit, but that's okay.

Ah, because my parse_name currently never fails?

Quoted 9 lines

vl.c int main(int argc, char **argv, char **envp) · line 3965

Quoted 3 lines
vl.c +0 -0
 #ifndef _WIN32
     if (qemu_opts_foreach(qemu_find_opts("add-fd"), parse_add_fd, NULL, 1)) {
         exit(1);

-readconfig stores the configuration read in QemuOpts. Command line option parsing should do the same, and no more. In particular it should not act upon the option. That needs to be done separately, where both command line and -readconfig settings are visible in QemuOpts.

Quoted 5 lines

Your patch does exactly that. I think amending the commit message with the previous paragraph would improve it.

Have you checked command line option parsing (the big switch) for similar problems?

I hadn't, other than fixing up -name; tbh It's taken me a while to understand how QemuOpts is supposed to work (and hence why I didn't get this in the 1st patch); I'd seen the qemu_opts_foreach uses at the bottom of the switch, but since they looked like a loop, I'd assumed they were only for options with multiple sets of values and not looked any further.

The big switch seems to be a mix of a lot of different ways of doing things; A quick scan shows rtc, option_rom, usb_device, and others all use qemu_opts_parse in the big switch but also taking an action in the switch.

Quoted 1 line

Thanks.

Dave
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#4 lore raw
Quoted 48 lines · Dr. David Alan Gilbert
Quoted 47 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 45 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

The 'name' option silently failed when used in config files ( http://lists.gnu.org/archive/html/qemu-devel/2014-04/msg00378.html )

---
 vl.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
vl.c +3 -2
index 8411a4a..47c199a 100644
@@ -965,7 +965,7 @@ static int parse_sandbox(QemuOpts *opts, void *opaque)
     return 0;
 }
 
-static void parse_name(QemuOpts *opts)
+static int parse_name(QemuOpts *opts, void *opaque)
 {
     const char *proc_name;
 
@@ -978,6 +978,8 @@ static void parse_name(QemuOpts *opts)
     if (proc_name) {
         os_set_proc_name(proc_name);
     }
+
+    return 0;
 }
 
 bool usb_enabled(bool default_usb)
@@ -3780,7 +3782,6 @@ int main(int argc, char **argv, char **envp)
                 if (!opts) {
                     exit(1);
                 }
-                parse_name(opts);
                 break;
             case QEMU_OPTION_prom_env:
                 if (nb_prom_envs >= MAX_PROM_ENVS) {
@@ -3955,6 +3956,10 @@ int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
Quoted 8 lines
Quoted 6 lines

vl.c int main(int argc, char **argv, char **envp) · line 3962

Quoted 4 lines
vl.c +4 -0
+    if (qemu_opts_foreach(qemu_find_opts("name"), parse_name, NULL, 1)) {
+        exit(1);
+    }
+

This will never exit, but that's okay.

Ah, because my parse_name currently never fails?

Yes. But that's a non-local argument, and handling the impossible failure here doesn't hurt.

Quoted 21 lines
Quoted 9 lines

vl.c int main(int argc, char **argv, char **envp) · line 3965

Quoted 3 lines
vl.c +0 -0
 #ifndef _WIN32
     if (qemu_opts_foreach(qemu_find_opts("add-fd"), parse_add_fd, NULL, 1)) {
         exit(1);

-readconfig stores the configuration read in QemuOpts. Command line option parsing should do the same, and no more. In particular it should not act upon the option. That needs to be done separately, where both command line and -readconfig settings are visible in QemuOpts.

Quoted 5 lines

Your patch does exactly that. I think amending the commit message with the previous paragraph would improve it.

Have you checked command line option parsing (the big switch) for similar problems?

I hadn't, other than fixing up -name; tbh It's taken me a while to understand how QemuOpts is supposed to work (and hence why I didn't get this in the 1st patch); I'd seen the qemu_opts_foreach uses at the bottom of the switch, but since they looked like a loop, I'd assumed they were only for options with multiple sets of values and not looked any further.

Quoted 4 lines

The big switch seems to be a mix of a lot of different ways of doing things; A quick scan shows rtc, option_rom, usb_device, and others all use qemu_opts_parse
in the big switch but also taking an action in the switch.

Okay. Looks like we better audit this some time.

Quoted 3 lines
Quoted 1 line

Thanks.

My pleasure :)

#5 lore raw
In reply to Dr. David Alan Gilbert (git)
Quoted 7 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

The 'name' option silently failed when used in config files ( http://lists.gnu.org/archive/html/qemu-devel/2014-04/msg00378.html )

Applied to -trivial, after:

1. Changing Reported/Tested-by as asked by William Dauchy
2. Adding a subject prefix (vl)
3. Adding commit message as suggested by Marcus
4. Adding Marcus's Reviewed-by.

Oh ma... ;)

Thank you! And please excuse me for it took so long. It'd be faster if I hadn't do all th e above ;)

/mjt

#6 lore raw
Quoted 16 lines · * Michael Tokarev ([email protected]) wrote:
Quoted 7 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

The 'name' option silently failed when used in config files ( http://lists.gnu.org/archive/html/qemu-devel/2014-04/msg00378.html )

Applied to -trivial, after:

1. Changing Reported/Tested-by as asked by William Dauchy
2. Adding a subject prefix (vl)
3. Adding commit message as suggested by Marcus
4. Adding Marcus's Reviewed-by.

Quoted 4 lines

Oh ma... ;)

Thank you! And please excuse me for it took so long. It'd be faster if I hadn't do all th e above ;)

Thanks, and apologies for not fixing those up.

Dave
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK