diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2010-06-21 18:35:10 +0100 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2010-06-21 18:35:10 +0100 |
commit | e862bdf68fdc53d9cee4686b579fd8dd8d31ff32 (patch) | |
tree | 071f320d03d641a169406144a6f010b24dd4f761 /tools/libxl/xl_cmdtable.c | |
parent | 154a413090645bac5ba4587999484e41088f3f89 (diff) | |
download | xen-e862bdf68fdc53d9cee4686b579fd8dd8d31ff32.tar.gz xen-e862bdf68fdc53d9cee4686b579fd8dd8d31ff32.tar.bz2 xen-e862bdf68fdc53d9cee4686b579fd8dd8d31ff32.zip |
xl: fix command truncation
Fix the truncation code so that it always accepts an exact match,
even when one command is a prefix of another one. This fixes,
e.g., "xl list"
Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
Diffstat (limited to 'tools/libxl/xl_cmdtable.c')
-rw-r--r-- | tools/libxl/xl_cmdtable.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c index da00cda663..4d4fb7b330 100644 --- a/tools/libxl/xl_cmdtable.c +++ b/tools/libxl/xl_cmdtable.c @@ -316,18 +316,19 @@ struct cmd_spec *cmdtable_lookup(const char *s) { struct cmd_spec *cmd = NULL; size_t len; - int i; + int i, count = 0; if (!s) return NULL; len = strlen(s); for (i = 0; i < cmdtable_len; i++) { if (!strncmp(s, cmd_table[i].cmd_name, len)) { - if (cmd == NULL) - cmd = &cmd_table[i]; - else - return NULL; + cmd = &cmd_table[i]; + /* Take an exact match, even if it also prefixes another command */ + if (len == strlen(cmd->cmd_name)) + return cmd; + count++; } } - return cmd; + return (count == 1) ? cmd : NULL; } |