[PATCH 14/22] shell: Add initial commands and aliases only once

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Nov 18 14:37:20 UTC 2014


Make tables read-only.
---
 cpukit/libmisc/shell/internal.h     |  1 -
 cpukit/libmisc/shell/shell.c        | 22 ++++++++++++++++++----
 cpukit/libmisc/shell/shell_cmdset.c | 17 -----------------
 cpukit/libmisc/shell/shellconfig.h  |  8 ++++----
 4 files changed, 22 insertions(+), 26 deletions(-)

diff --git a/cpukit/libmisc/shell/internal.h b/cpukit/libmisc/shell/internal.h
index cf999a8..1884117 100644
--- a/cpukit/libmisc/shell/internal.h
+++ b/cpukit/libmisc/shell/internal.h
@@ -27,7 +27,6 @@ rtems_shell_topic_t * rtems_shell_lookup_topic(const char *topic);
 
 
 extern void rtems_shell_register_monitor_commands(void);
-extern void rtems_shell_initialize_command_set(void);
 
 extern void rtems_shell_print_heap_info(
   const char       *c,
diff --git a/cpukit/libmisc/shell/shell.c b/cpukit/libmisc/shell/shell.c
index 9a5ffb5..6030ecc 100644
--- a/cpukit/libmisc/shell/shell.c
+++ b/cpukit/libmisc/shell/shell.c
@@ -112,6 +112,20 @@ static void rtems_shell_create_file(const char *name, const char *content)
   }
 }
 
+static void rtems_shell_init_commands(void)
+{
+  rtems_shell_cmd_t * const *c;
+  rtems_shell_alias_t * const *a;
+
+  for ( c = rtems_shell_Initial_commands ; *c  ; c++ ) {
+    rtems_shell_add_cmd_struct( *c );
+  }
+
+  for ( a = rtems_shell_Initial_aliases ; *a  ; a++ ) {
+    rtems_shell_alias_cmd( (*a)->name, (*a)->alias );
+  }
+}
+
 static void rtems_shell_init_once(void)
 {
   struct passwd pwd;
@@ -131,6 +145,8 @@ static void rtems_shell_init_once(void)
                           "\n"
                           "Welcome to %v\n"
                           "running on %m\n");
+
+  rtems_shell_init_commands();
 }
 
 /*
@@ -706,11 +722,11 @@ bool rtems_shell_main_loop(
   FILE              *stdinToClose = NULL;
   FILE              *stdoutToClose = NULL;
 
-  rtems_shell_initialize_command_set();
-
   eno = pthread_once(&rtems_shell_once, rtems_shell_init_once);
   assert(eno == 0);
 
+  rtems_shell_register_monitor_commands();
+
   shell_env = rtems_shell_init_env(shell_env_arg);
   if (shell_env == NULL) {
     rtems_error(0, "rtems_shell_init_env");
@@ -790,8 +806,6 @@ bool rtems_shell_main_loop(
   setvbuf(stdin,NULL,_IONBF,0); /* Not buffered*/
   setvbuf(stdout,NULL,_IONBF,0); /* Not buffered*/
 
-  rtems_shell_initialize_command_set();
-
   /*
    * Allocate the command line buffers.
    */
diff --git a/cpukit/libmisc/shell/shell_cmdset.c b/cpukit/libmisc/shell/shell_cmdset.c
index e291e74..2f2c246 100644
--- a/cpukit/libmisc/shell/shell_cmdset.c
+++ b/cpukit/libmisc/shell/shell_cmdset.c
@@ -183,23 +183,6 @@ rtems_shell_cmd_t * rtems_shell_add_cmd(
   return shell_cmd;
 }
 
-
-void rtems_shell_initialize_command_set(void)
-{
-  rtems_shell_cmd_t **c;
-  rtems_shell_alias_t **a;
-
-  for ( c = rtems_shell_Initial_commands ; *c  ; c++ ) {
-    rtems_shell_add_cmd_struct( *c );
-  }
-
-  for ( a = rtems_shell_Initial_aliases ; *a  ; a++ ) {
-    rtems_shell_alias_cmd( (*a)->name, (*a)->alias );
-  }
-
-  rtems_shell_register_monitor_commands();
-}
-
 /* ----------------------------------------------- *
  * you can make an alias for every command.
  * ----------------------------------------------- */
diff --git a/cpukit/libmisc/shell/shellconfig.h b/cpukit/libmisc/shell/shellconfig.h
index d9d6078..c5fced3 100644
--- a/cpukit/libmisc/shell/shellconfig.h
+++ b/cpukit/libmisc/shell/shellconfig.h
@@ -90,7 +90,7 @@ extern rtems_shell_cmd_t rtems_shell_MALLOC_INFO_Command;
   extern rtems_shell_cmd_t rtems_shell_PING_Command;
 #endif
 
-extern rtems_shell_cmd_t *rtems_shell_Initial_commands[];
+extern rtems_shell_cmd_t * const rtems_shell_Initial_commands[];
 
 /*
  *  Extern for alias commands
@@ -99,7 +99,7 @@ extern rtems_shell_alias_t rtems_shell_DIR_Alias;
 extern rtems_shell_alias_t rtems_shell_CD_Alias;
 extern rtems_shell_alias_t rtems_shell_EXIT_Alias;
 
-extern rtems_shell_alias_t *rtems_shell_Initial_aliases[];
+extern rtems_shell_alias_t * const rtems_shell_Initial_aliases[];
 
 /*
  *  If we are configured to alias a command, then make sure the underlying
@@ -124,7 +124,7 @@ extern rtems_shell_alias_t *rtems_shell_Initial_aliases[];
 #endif
 
 #if defined(CONFIGURE_SHELL_COMMANDS_INIT)
-  rtems_shell_alias_t *rtems_shell_Initial_aliases[] = {
+  rtems_shell_alias_t * const rtems_shell_Initial_aliases[] = {
     #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
          !defined(CONFIGURE_SHELL_NO_COMMAND_DIR)) || \
         defined(CONFIGURE_SHELL_COMMAND_DIR)
@@ -150,7 +150,7 @@ extern rtems_shell_alias_t *rtems_shell_Initial_aliases[];
     NULL
   };
 
-  rtems_shell_cmd_t *rtems_shell_Initial_commands[] = {
+  rtems_shell_cmd_t * const rtems_shell_Initial_commands[] = {
     /*
      *  General comamnds that should be present
      */
-- 
1.8.4.5




More information about the devel mailing list