From: Anthony PERARD Date: Tue, 4 May 2021 16:14:36 +0000 (+0100) Subject: xl: constify cmd_table entries X-Git-Tag: archive/raspbian/4.16.0+51-g0941d6cb-1+rpi1~2^2~42^2~562 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=aaf61c4750d467176cd49323019cd286e35b8688;p=xen.git xl: constify cmd_table entries Also constify cmdtable_len and make use of ARRAY_SIZE, which is available in "xen-tools/libs.h". The entries in cmd_table don't need to be modified once xl is running. Signed-off-by: Anthony PERARD Reviewed-by: Julien Grall --- diff --git a/tools/xl/xl.c b/tools/xl/xl.c index 3a89295802..4107d10fd4 100644 --- a/tools/xl/xl.c +++ b/tools/xl/xl.c @@ -362,7 +362,7 @@ int main(int argc, char **argv) { int opt = 0; char *cmd = 0; - struct cmd_spec *cspec; + const struct cmd_spec *cspec; int ret; void *config_data = 0; int config_len = 0; @@ -462,7 +462,7 @@ int child_report(xlchildnum child) void help(const char *command) { int i; - struct cmd_spec *cmd; + const struct cmd_spec *cmd; if (!command || !strcmp(command, "help")) { printf("Usage xl [-vfNtT] [args]\n\n"); diff --git a/tools/xl/xl.h b/tools/xl/xl.h index 137a29077c..e5a106dfbc 100644 --- a/tools/xl/xl.h +++ b/tools/xl/xl.h @@ -218,10 +218,10 @@ int main_qemu_monitor_command(int argc, char **argv); void help(const char *command); extern const char *common_domname; -extern struct cmd_spec cmd_table[]; -extern int cmdtable_len; +extern const struct cmd_spec cmd_table[]; +extern const int cmdtable_len; /* Look up a command in the table, allowing unambiguous truncation */ -struct cmd_spec *cmdtable_lookup(const char *s); +const struct cmd_spec *cmdtable_lookup(const char *s); extern libxl_ctx *ctx; extern xentoollog_logger_stdiostream *logger; diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 07f54daabe..661323d488 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -15,10 +15,11 @@ #include #include +#include #include "xl.h" -struct cmd_spec cmd_table[] = { +const struct cmd_spec cmd_table[] = { { "create", &main_create, 1, 1, "Create a domain from config file ", @@ -631,12 +632,12 @@ struct cmd_spec cmd_table[] = { }, }; -int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec); +const int cmdtable_len = ARRAY_SIZE(cmd_table); /* Look up a command in the table, allowing unambiguous truncation */ -struct cmd_spec *cmdtable_lookup(const char *s) +const struct cmd_spec *cmdtable_lookup(const char *s) { - struct cmd_spec *cmd = NULL; + const struct cmd_spec *cmd = NULL; size_t len; int i, count = 0;