From 964747dd36db46428bd767d13aaee6f60f32d0b5 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sat, 15 Oct 2022 17:00:22 +0800 Subject: [PATCH] nshlib: Call nsh_telnetstart in nsh_initialize to avoid the dupliation Signed-off-by: Xiang Xiao --- examples/nxterm/nxterm_main.c | 16 ---------------- graphics/nxwm/src/cnxterm.cxx | 14 -------------- graphics/twm4nx/apps/cnxterm.cxx | 14 -------------- nshlib/nsh_init.c | 14 +++++++++++++- system/nsh/nsh_main.c | 21 --------------------- 5 files changed, 13 insertions(+), 66 deletions(-) diff --git a/examples/nxterm/nxterm_main.c b/examples/nxterm/nxterm_main.c index 57c19576b..8555980c5 100644 --- a/examples/nxterm/nxterm_main.c +++ b/examples/nxterm/nxterm_main.c @@ -223,22 +223,6 @@ int main(int argc, FAR char *argv[]) printf("nxterm_main: Initialize NSH\n"); nsh_initialize(); - /* If the Telnet console is selected as a front-end, then start the - * Telnet daemon. - */ - -#ifdef CONFIG_NSH_TELNET - ret = nsh_telnetstart(AF_UNSPEC); - if (ret < 0) - { - /* The daemon is NOT running. Report the error then fail... - * either with the serial console up or just exiting. - */ - - fprintf(stderr, "ERROR: Failed to start TELNET daemon: %d\n", ret); - } -#endif - /* NX Initialization ******************************************************/ /* Initialize NX */ diff --git a/graphics/nxwm/src/cnxterm.cxx b/graphics/nxwm/src/cnxterm.cxx index 1143f0032..d84fd1b03 100644 --- a/graphics/nxwm/src/cnxterm.cxx +++ b/graphics/nxwm/src/cnxterm.cxx @@ -653,19 +653,5 @@ bool NxWM::nshlibInitialize(void) // Initialize the NSH library nsh_initialize(); - - // If the Telnet console is selected as a front-end, then start the - // Telnet daemon. - -#ifdef CONFIG_NSH_TELNET - int ret = nsh_telnetstart(AF_UNSPEC); - if (ret < 0) - { - // The daemon is NOT running! - - return false; - } -#endif - return true; } diff --git a/graphics/twm4nx/apps/cnxterm.cxx b/graphics/twm4nx/apps/cnxterm.cxx index 3bd9821e6..d3cbd99d0 100644 --- a/graphics/twm4nx/apps/cnxterm.cxx +++ b/graphics/twm4nx/apps/cnxterm.cxx @@ -574,20 +574,6 @@ bool CNxTermFactory::nshlibInitialize(void) // Initialize the NSH library nsh_initialize(); - - // If the Telnet console is selected as a front-end, then start the - // Telnet daemon. - -#ifdef CONFIG_NSH_TELNET - int ret = nsh_telnetstart(AF_UNSPEC); - if (ret < 0) - { - // The daemon is NOT running! - - return false; - } -#endif - return true; } diff --git a/nshlib/nsh_init.c b/nshlib/nsh_init.c index 2cf68035e..251e6c452 100644 --- a/nshlib/nsh_init.c +++ b/nshlib/nsh_init.c @@ -54,7 +54,7 @@ static const struct extmatch_vtable_s g_nsh_extmatch = * Description: * This interface is used to initialize the NuttShell (NSH). * nsh_initialize() should be called once during application start-up prior - * to executing either nsh_consolemain() or nsh_telnetstart(). + * to executing nsh_consolemain(). * * Input Parameters: * None @@ -87,4 +87,16 @@ void nsh_initialize(void) boardctl(BOARDIOC_INIT, 0); #endif + +#if defined(CONFIG_NSH_TELNET) && !defined(CONFIG_NSH_DISABLE_TELNETSTART) && \ + !defined(CONFIG_NETINIT_NETLOCAL) + /* If the Telnet console is selected as a front-end, then start the + * Telnet daemon UNLESS network initialization is deferred via + * CONFIG_NETINIT_NETLOCAL. In that case, the telnet daemon must be + * started manually with the telnetd command after the network has + * been initialized + */ + + nsh_telnetstart(AF_UNSPEC); +#endif } diff --git a/system/nsh/nsh_main.c b/system/nsh/nsh_main.c index 5db22980f..7212fccbe 100644 --- a/system/nsh/nsh_main.c +++ b/system/nsh/nsh_main.c @@ -127,27 +127,6 @@ int main(int argc, FAR char *argv[]) nsh_initialize(); -#if defined(CONFIG_NSH_TELNET) && !defined(CONFIG_NSH_DISABLE_TELNETSTART) && \ - !defined(CONFIG_NETINIT_NETLOCAL) - /* If the Telnet console is selected as a front-end, then start the - * Telnet daemon UNLESS network initialization is deferred via - * CONFIG_NETINIT_NETLOCAL. In that case, the telnet daemon must be - * started manually with the telnetd command after the network has - * been initialized - */ - - ret = nsh_telnetstart(AF_UNSPEC); - if (ret < 0) - { - /* The daemon is NOT running. Report the error then fail... - * either with the serial console up or just exiting. - */ - - fprintf(stderr, "ERROR: Failed to start TELNET daemon: %d\n", ret); - exitval = 1; - } -#endif - #ifdef CONFIG_NSH_CONSOLE /* If the serial console front end is selected, run it on this thread */