[PATCH 6/6] shell: Add rtems_shell_run_main_loop()

Sebastian Huber sebastian.huber at embedded-brains.de
Wed Apr 6 07:17:32 UTC 2022


In contrast to rtems_shell_main_loop(), this new function does not
perform all sorts of initialization based on environment settings.  For
example, due to the use of isatty() in rtems_shell_main_loop() it is
impossible to run an interactive shell through a socket connection.
---
 cpukit/include/rtems/shell.h | 25 +++++++++++++++++++++++++
 cpukit/libmisc/shell/shell.c | 25 +++++++++++++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/cpukit/include/rtems/shell.h b/cpukit/include/rtems/shell.h
index 58d0c515b3..f8b677d5cd 100644
--- a/cpukit/include/rtems/shell.h
+++ b/cpukit/include/rtems/shell.h
@@ -254,6 +254,31 @@ bool rtems_shell_main_loop(
   rtems_shell_env_t *rtems_shell_env
 );
 
+/**
+ * @brief Runs the shell main loop.
+ *
+ * The caller shall initialize the shell environment.  It is recommended that
+ * the caller duplicates the current shell environment using
+ * rtems_shell_dup_current_env() and then performs the required customization.
+ * Shell commands will use the stdin, stdout, and stderr file streams set up by
+ * the caller.
+ *
+ * @param interactive indicates if the shell main loop interfaces with an
+ *   interactive user.  For an interactive user, a welcome message using
+ *   "/etc/motd" is presented and command prompt is displayed.
+ *
+ * @param[in, out] line_editor_output is the optional line editor output file
+ *   stream.  It may be NULL, to disable the line editor output.
+ *
+ * @return Returns true, if no error occurred and a shell exit was requested,
+ *   otherwise false.
+ */
+bool rtems_shell_run_main_loop(
+  rtems_shell_env_t *shell_env,
+  bool               interactive,
+  FILE              *line_editor_output
+);
+
 extern const rtems_shell_env_t rtems_global_shell_env;
 
 rtems_shell_env_t *rtems_shell_get_current_env(void);
diff --git a/cpukit/libmisc/shell/shell.c b/cpukit/libmisc/shell/shell.c
index 01336f0a78..f53404f8cb 100644
--- a/cpukit/libmisc/shell/shell.c
+++ b/cpukit/libmisc/shell/shell.c
@@ -1010,6 +1010,31 @@ static bool shell_main_loop(
   return result;
 }
 
+bool rtems_shell_run_main_loop(
+  rtems_shell_env_t *shell_env,
+  bool               interactive,
+  FILE              *line_editor_output
+)
+{
+  bool result;
+
+  if (shell_env->magic != SHELL_MAGIC) {
+    return false;
+  }
+
+  if (!rtems_shell_init_user_env()) {
+    return false;
+  }
+
+  if (!rtems_shell_set_shell_env(shell_env)) {
+    return false;
+  }
+
+  result = shell_main_loop(shell_env, interactive, line_editor_output);
+  rtems_shell_clear_shell_env();
+  return result;
+}
+
 bool rtems_shell_main_loop(
   rtems_shell_env_t *shell_env
 )
-- 
2.34.1



More information about the devel mailing list