[Libvir] [PATCH] parsing virsh options is wrong

Hi, When I specified -t (or -q) option with virsh command, the result is something wrong. It is likely to be caused by the way to parse the virsh options. (example) I would like to know the node information with timing information. So, I try some cases. 1) virsh with "-t nodeinfo" ran virsh interactive terminal. Hmm, I didn't expect that... # virsh -t nodeinfo Welcome to virsh, the virtualization interactive terminal. Type: 'help' for help with commands 'quit' to quit virsh # 2) virsh with "-t aa nodeinfo" I got the node information with timing information. But what does "aa" option mean?? (Of course no meaning.) # virsh -t aa nodeinfo CPU model: i686 CPU(s): 2 CPU frequency: 1828 MHz CPU socket(s): 1 Core(s) per socket: 2 Thread(s) per core: 1 NUMA cell(s): 1 Memory size: 1037312 kB (Time: 2.821 ms) 3) virsh with "-t tt nodeinfo" ran virsh interactive terminal. What's the difference with "aa"? # virsh -t tt nodeinfo Welcome to virsh, the virtualization interactive terminal. Type: 'help' for help with commands 'quit' to quit virsh # I think the cause is missing a conditional before getopt_long at vshParseArgv and add to check whether "o->has_arg" is 1 or not. After the fix, I can use virsh options normally. (example) 1) virsh with "-t nodeinfo" # ./virsh -t nodeinfo CPU model: i686 CPU(s): 2 CPU frequency: 1828 MHz CPU socket(s): 1 Core(s) per socket: 2 Thread(s) per core: 1 NUMA cell(s): 1 Memory size: 1037312 kB (Time: 2.626 ms) 2) virsh with "-t aa nodeinfo" # ./virsh -t aa nodeinfo error: unknown command: 'aa' 3) virsh with "-t tt nodeinfo" # ./virsh -t tt nodeinfo error: unknown command: 'tt' Signed-off-by: Saori Fukuta <fukuta.saori@jp.fujitsu.com> Thanks, Saori Fukuta. Index: virsh.c =================================================================== RCS file: /data/cvs/libvirt/src/virsh.c,v retrieving revision 1.55 diff -u -p -r1.55 virsh.c --- virsh.c 23 Feb 2007 10:27:53 -0000 1.55 +++ virsh.c 27 Feb 2007 07:35:28 -0000 @@ -3344,12 +3344,14 @@ vshParseArgv(vshControl * ctl, int argc, int sz = strlen(last); for (o = opt; o->name; o++) { - if (sz == 2 && *(last + 1) == o->val) - /* valid virsh short option */ - valid = TRUE; - else if (sz > 2 && strcmp(o->name, last + 2) == 0) - /* valid virsh long option */ - valid = TRUE; + if (o->has_arg == 1){ + if (sz == 2 && *(last + 1) == o->val) + /* valid virsh short option */ + valid = TRUE; + else if (sz > 2 && strcmp(o->name, last + 2) == 0) + /* valid virsh long option */ + valid = TRUE; + } } } if (!valid) {

On Tue, Feb 27, 2007 at 07:45:45PM +0900, Saori Fukuta wrote:
When I specified -t (or -q) option with virsh command, the result is something wrong.
I think the cause is missing a conditional before getopt_long at vshParseArgv and add to check whether "o->has_arg" is 1 or not.
Yes, your patch below does look like it is doing the correct thing. I'll apply it to CVS shortly.
Index: virsh.c =================================================================== RCS file: /data/cvs/libvirt/src/virsh.c,v retrieving revision 1.55 diff -u -p -r1.55 virsh.c --- virsh.c 23 Feb 2007 10:27:53 -0000 1.55 +++ virsh.c 27 Feb 2007 07:35:28 -0000 @@ -3344,12 +3344,14 @@ vshParseArgv(vshControl * ctl, int argc, int sz = strlen(last);
for (o = opt; o->name; o++) { - if (sz == 2 && *(last + 1) == o->val) - /* valid virsh short option */ - valid = TRUE; - else if (sz > 2 && strcmp(o->name, last + 2) == 0) - /* valid virsh long option */ - valid = TRUE; + if (o->has_arg == 1){ + if (sz == 2 && *(last + 1) == o->val) + /* valid virsh short option */ + valid = TRUE; + else if (sz > 2 && strcmp(o->name, last + 2) == 0) + /* valid virsh long option */ + valid = TRUE; + }
Regards, Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
participants (2)
-
Daniel P. Berrange
-
Saori Fukuta