xl: constify cmd_table entries
PATCH 1/1 xl: constify cmd_table entries
and cmdtable_len.
The entries in cmd_table don't need to be modified once xl is running.
Signed-off-by Anthony PERARD <[email protected]>
--- tools/xl/xl.c | 4 ++-- tools/xl/xl.h | 6 +++--- tools/xl/xl_cmdtable.c | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-)
tools/xl/xl.c +2 -2
@@ -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] <subcommand> [args]\n\n" );
tools/xl/xl.h +3 -3
@@ -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;
tools/xl/xl_cmdtable.c +4 -4
@@ -18,7 +18,7 @@#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 <filename>" ,
@@ -631,12 +631,12 @@ struct cmd_spec cmd_table[] = { }, }; -int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec ); +const int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec );/* 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 ;
Signature · 1 line
Anthony PERARD
NIT: I would suggest to add "..." so it is clear...
Quoted 1 line · Anthony PERARD
and
cmdtable_len.
... this is a continuation of the title.
Quoted 64 lines
The entries in
cmd_tabledon't need to be modified once xl is running.Signed-off-by Anthony PERARD <[email protected]>--- tools/xl/xl.c | 4 ++-- tools/xl/xl.h | 6 +++--- tools/xl/xl_cmdtable.c | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-)tools/xl/xl.c +2
-2@@ -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] <subcommand> [args]\n\n" );tools/xl/xl.h +3
-3@@ -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;tools/xl/xl_cmdtable.c +1
-1@@ -18,7 +18,7 @@#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 <filename>" ,
tools/xl/xl_cmdtable.c struct cmd_spec cmd_table[] = { · line 634
Quoted 5 lines
tools/xl/xl_cmdtable.c +1
-1@@ -631,12 +631,12 @@ struct cmd_spec cmd_table[] = { }, }; -int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec ); +const int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec );
NIT: This can be replaced with ARRAY_SIZE().
tools/xl/xl_cmdtable.c struct cmd_spec cmd_table[] = {
Quoted 11 lines
tools/xl/xl_cmdtable.c +2
-2/* 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 ;
Reviewed-by Julien Grall <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
Quoted 4 lines · Julien Grall
tools/xl/xl_cmdtable.c struct cmd_spec cmd_table[] = { · line 634
Quoted 2 lines
tools/xl/xl_cmdtable.c +1
-1-int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec ); +const int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec );NIT: This can be replaced with
ARRAY_SIZE().
I've thought of using it but the macro isn't available to "xl". But it's probably a good time to add the macro and start using it.
Quoted 2 lines
Reviewed-by Julien Grall <[email protected]>
Thanks,
Signature · 1 line
Anthony PERARD