[PATCH] parsing virsh options is wrong

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>

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) {


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]