This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit 3f70a78dd3684035a1ac16002eafa49db7204a5f
Author: Masayuki Ishikawa <[email protected]>
AuthorDate: Fri Aug 5 14:37:28 2022 +0900

    nshlib: Make nsh_telnetmain() in public
    
    Summary:
    - This commit makes nsh_telnetmain() in public so that we can
      call it from applications.
    - Also, CONFIG_NSH_DISABLE_TELNETSTART is introduced so that
      we can disable nsh_telnetstart()
    
    Impact:
    - nsh with telnet daemon
    
    Testing:
    - Tested with sabre-6quad:netknsh (will be updated later)
    
    Signed-off-by: Masayuki Ishikawa <[email protected]>
---
 include/nshlib/nshlib.h | 21 +++++++++++++++++++++
 nshlib/Kconfig          |  6 ++++++
 nshlib/nsh_telnetd.c    | 10 ++++------
 3 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/include/nshlib/nshlib.h b/include/nshlib/nshlib.h
index cea122b5e..5d1157141 100644
--- a/include/nshlib/nshlib.h
+++ b/include/nshlib/nshlib.h
@@ -126,6 +126,27 @@ void nsh_initialize(void);
 
 int nsh_consolemain(int argc, FAR char *argv[]);
 
+/****************************************************************************
+ * Name: nsh_telnetmain
+ *
+ * Description:
+ *   This interface may be called or started with task_start to start a
+ *   single NSH instance that operates on stdin and stdout for telnet daemon.
+ *   This function does not return.
+ *
+ * Input Parameters:
+ *   Standard task start-up arguments.  These are not used.  argc may be
+ *   zero and argv may be NULL.
+ *
+ * Returned Values:
+ *   This function does not normally return.  exit() is usually called to
+ *   terminate the NSH session.  This function will return in the event of
+ *   an error.  In that case, a non-zero value is returned (EXIT_FAILURE=1).
+
+ ****************************************************************************/
+
+int nsh_telnetmain(int argc, FAR char *argv[]);
+
 /****************************************************************************
  * Name: nsh_telnetstart
  *
diff --git a/nshlib/Kconfig b/nshlib/Kconfig
index b75e95245..f584e9fc3 100644
--- a/nshlib/Kconfig
+++ b/nshlib/Kconfig
@@ -1157,6 +1157,12 @@ config NSH_IOBUFFER_SIZE
                Determines the size of the I/O buffer to use for sending/
                receiving TELNET commands/responses.  Default: 512
 
+config NSH_DISABLE_TELNETSTART
+       bool "Disable to start telnetd"
+       default false
+       ---help---
+               Determines if the nsh starts telnetd automatically
+
 endif # NSH_TELNET
 endmenu # Telnet Configuration
 
diff --git a/nshlib/nsh_telnetd.c b/nshlib/nsh_telnetd.c
index 76ba97b50..19b701b8d 100644
--- a/nshlib/nsh_telnetd.c
+++ b/nshlib/nsh_telnetd.c
@@ -59,14 +59,14 @@ enum telnetd_state_e
 };
 
 /****************************************************************************
- * Private Functions
+ * Public Functions
  ****************************************************************************/
 
 /****************************************************************************
  * Name: nsh_telnetmain
  ****************************************************************************/
 
-static int nsh_telnetmain(int argc, char *argv[])
+int nsh_telnetmain(int argc, FAR char *argv[])
 {
   FAR struct console_stdio_s *pstate = nsh_newconsole(true);
   FAR struct nsh_vtbl_s *vtbl;
@@ -192,10 +192,6 @@ static int nsh_telnetmain(int argc, char *argv[])
   return OK;
 }
 
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
 /****************************************************************************
  * Name: nsh_telnetstart
  *
@@ -218,6 +214,7 @@ static int nsh_telnetmain(int argc, char *argv[])
  *
  ****************************************************************************/
 
+#ifndef CONFIG_NSH_DISABLE_TELNETSTART
 int nsh_telnetstart(sa_family_t family)
 {
   static enum telnetd_state_e state = TELNETD_NOTRUNNING;
@@ -325,6 +322,7 @@ int nsh_telnetstart(sa_family_t family)
 
   return ret;
 }
+#endif
 
 /****************************************************************************
  * Name: cmd_telnetd

Reply via email to