From: Tim Deegan Subject: [PATCH] xl: fix command truncation Date: Mon, 21 Jun 2010 13:18:39 +0100 Message-ID: <20100621121839.GF14598@whitby.uk.xensource.com> References: <20100617155323.GK15976@whitby.uk.xensource.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="OwLcNYc0lM97+oe1" Return-path: Content-Disposition: inline In-Reply-To: <20100617155323.GK15976@whitby.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org --OwLcNYc0lM97+oe1 Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: inline 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 --OwLcNYc0lM97+oe1 Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: attachment; filename="xl_truncate2" diff -r 31708477f0a9 tools/libxl/xl_cmdtable.c --- a/tools/libxl/xl_cmdtable.c Mon Jun 21 09:59:10 2010 +0100 +++ b/tools/libxl/xl_cmdtable.c Mon Jun 21 13:13:19 2010 +0100 @@ -316,18 +316,19 @@ { 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; } --OwLcNYc0lM97+oe1 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --OwLcNYc0lM97+oe1--