revise some of the state handling in the previous commit.
This commit is contained in:
parent
342de81641
commit
9091716419
@ -39,7 +39,6 @@
|
|||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
@ -64,12 +63,6 @@ enum telnetd_state_e
|
|||||||
TELNETD_RUNNING
|
TELNETD_RUNNING
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static enum telnetd_state_e g_telnetd_state;
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -83,9 +76,8 @@ static int nsh_telnetmain(int argc, char *argv[])
|
|||||||
FAR struct console_stdio_s *pstate = nsh_newconsole();
|
FAR struct console_stdio_s *pstate = nsh_newconsole();
|
||||||
FAR struct nsh_vtbl_s *vtbl;
|
FAR struct nsh_vtbl_s *vtbl;
|
||||||
|
|
||||||
DEBUGASSERT(pstate != NULL && g_telnetd_state == TELNETD_STARTED);
|
DEBUGASSERT(pstate != NULL);
|
||||||
vtbl = &pstate->cn_vtbl;
|
vtbl = &pstate->cn_vtbl;
|
||||||
g_telnetd_state = TELNETD_RUNNING;
|
|
||||||
|
|
||||||
_info("Session [%d] Started\n", getpid());
|
_info("Session [%d] Started\n", getpid());
|
||||||
|
|
||||||
@ -95,7 +87,6 @@ static int nsh_telnetmain(int argc, char *argv[])
|
|||||||
if (nsh_telnetlogin(pstate) != OK)
|
if (nsh_telnetlogin(pstate) != OK)
|
||||||
{
|
{
|
||||||
nsh_exit(vtbl, 1);
|
nsh_exit(vtbl, 1);
|
||||||
g_telnetd_state = TELNETD_NOTRUNNING;
|
|
||||||
return -1; /* nsh_exit does not return */
|
return -1; /* nsh_exit does not return */
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_NSH_TELNET_LOGIN */
|
#endif /* CONFIG_NSH_TELNET_LOGIN */
|
||||||
@ -162,14 +153,12 @@ static int nsh_telnetmain(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
fprintf(pstate->cn_outstream, g_fmtcmdfailed, "nsh_telnetmain",
|
fprintf(pstate->cn_outstream, g_fmtcmdfailed, "nsh_telnetmain",
|
||||||
"fgets", NSH_ERRNO);
|
"fgets", NSH_ERRNO);
|
||||||
g_telnetd_state = TELNETD_NOTRUNNING;
|
|
||||||
nsh_exit(vtbl, 1);
|
nsh_exit(vtbl, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clean up */
|
/* Clean up */
|
||||||
|
|
||||||
g_telnetd_state = TELNETD_NOTRUNNING;
|
|
||||||
nsh_exit(vtbl, 0);
|
nsh_exit(vtbl, 0);
|
||||||
|
|
||||||
/* We do not get here, but this is necessary to keep some compilers happy */
|
/* We do not get here, but this is necessary to keep some compilers happy */
|
||||||
@ -201,9 +190,10 @@ static int nsh_telnetmain(int argc, char *argv[])
|
|||||||
|
|
||||||
int nsh_telnetstart(void)
|
int nsh_telnetstart(void)
|
||||||
{
|
{
|
||||||
|
static enum telnetd_state_e state = TELNETD_NOTRUNNING;
|
||||||
int ret = OK;
|
int ret = OK;
|
||||||
|
|
||||||
if (g_telnetd_state == TELNETD_NOTRUNNING)
|
if (state == TELNETD_NOTRUNNING)
|
||||||
{
|
{
|
||||||
struct telnetd_config_s config;
|
struct telnetd_config_s config;
|
||||||
|
|
||||||
@ -211,7 +201,7 @@ int nsh_telnetstart(void)
|
|||||||
* start the Telnet daemon concurrently.
|
* start the Telnet daemon concurrently.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
g_telnetd_state = TELNETD_STARTED;
|
state = TELNETD_STARTED;
|
||||||
|
|
||||||
/* Initialize any USB tracing options that were requested. If
|
/* Initialize any USB tracing options that were requested. If
|
||||||
* standard console is also defined, then we will defer this step to
|
* standard console is also defined, then we will defer this step to
|
||||||
@ -239,7 +229,11 @@ int nsh_telnetstart(void)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
_err("ERROR: Failed to tart the Telnet daemon: %d\n", ret);
|
_err("ERROR: Failed to tart the Telnet daemon: %d\n", ret);
|
||||||
g_telnetd_state = TELNETD_NOTRUNNING;
|
state = TELNETD_NOTRUNNING;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
state = TELNETD_RUNNING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user