mirror of
https://github.com/apache/nuttx-apps.git
synced 2025-10-18 17:32:09 +08:00
NSH now supports an MOTD string that will be presented after the greeting
This commit is contained in:
@@ -1514,4 +1514,6 @@
|
|||||||
file like /etc/passwd (2016-01-19).
|
file like /etc/passwd (2016-01-19).
|
||||||
* apps/nshlib/nsh_passwdcmds.c: Add useradd, userdel, and passwd
|
* apps/nshlib/nsh_passwdcmds.c: Add useradd, userdel, and passwd
|
||||||
commands (2019-01-20).
|
commands (2019-01-20).
|
||||||
|
* apps/nshlib: Now supports a Message of the Day (MOTD) that will
|
||||||
|
be presented after the NSH greeting (2015-01-20).
|
||||||
|
|
||||||
|
@@ -17,6 +17,44 @@ config NSH_LIBRARY
|
|||||||
|
|
||||||
if NSH_LIBRARY
|
if NSH_LIBRARY
|
||||||
|
|
||||||
|
menuconfig NSH_MOTD
|
||||||
|
bool "Message of the Day (MOTD)"
|
||||||
|
default n
|
||||||
|
---help---
|
||||||
|
Support a user-provided Message of the Day (MOTD) that will be
|
||||||
|
presented each time new NSH session is opened.
|
||||||
|
|
||||||
|
if NSH_MOTD
|
||||||
|
|
||||||
|
config NSH_PLATFORM_MOTD
|
||||||
|
bool "Platform MOTD"
|
||||||
|
default n
|
||||||
|
---help---
|
||||||
|
If this option is selected, the NSH will call into platform-specific
|
||||||
|
logic in order to get the MOTD. The function prototype for this
|
||||||
|
call is:
|
||||||
|
|
||||||
|
void platform_motd(FAR char *buffer, size_t buflen);
|
||||||
|
|
||||||
|
Where buffer is the location to return the MOTD and buflen is the
|
||||||
|
length of that buffer. The maximum size of the buffer is detemined
|
||||||
|
by NSH_FILEIOSIZE. An appopriate location for the
|
||||||
|
implementation of platform_motd would be within apps/platform/<board>.
|
||||||
|
|
||||||
|
One newline will be inserted after the platform-supplied message.
|
||||||
|
|
||||||
|
config NSH_MOTD_STRING
|
||||||
|
string "MOTD String"
|
||||||
|
default "No MOTD string provided"
|
||||||
|
depends on !NSH_PLATFORM_MOTD
|
||||||
|
---help---
|
||||||
|
If NSH_MOTD is selected, but NSH_PLATFORM_MOTD is not, then a fixed
|
||||||
|
MOTD string will be used. That string is provided by this selection.
|
||||||
|
|
||||||
|
One newline will be inserted after supplied MOTD message.
|
||||||
|
|
||||||
|
endif # NSH_MOTD
|
||||||
|
|
||||||
menu "Command Line Configuration"
|
menu "Command Line Configuration"
|
||||||
|
|
||||||
choice
|
choice
|
||||||
|
@@ -573,10 +573,12 @@
|
|||||||
# undef NSH_HAVE_IOBUFFER
|
# undef NSH_HAVE_IOBUFFER
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* The I/O buffer is needed for the ls, cp, and ps commands */
|
/* The I/O buffer is needed for the ls, cp, and ps commands. It is also
|
||||||
|
* needed if the platform supplied MOTD is configured.
|
||||||
|
*/
|
||||||
|
|
||||||
#if defined(CONFIG_NSH_DISABLE_LS) && defined(CONFIG_NSH_DISABLE_CP) && \
|
#if defined(CONFIG_NSH_DISABLE_LS) && defined(CONFIG_NSH_DISABLE_CP) && \
|
||||||
defined(CONFIG_NSH_DISABLE_PS)
|
defined(CONFIG_NSH_DISABLE_PS) && !defined(CONFIG_NSH_PLATFORM_MOTD)
|
||||||
# undef NSH_HAVE_IOBUFFER
|
# undef NSH_HAVE_IOBUFFER
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -798,6 +800,9 @@ typedef CODE int (*nsh_direntry_handler_t)(FAR struct nsh_vtbl_s *vtbl,
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
extern const char g_nshgreeting[];
|
extern const char g_nshgreeting[];
|
||||||
|
#if defined(CONFIG_NSH_MOTD) && !defined(CONFIG_NSH_PLATFORM_MOTD)
|
||||||
|
extern const char g_nshmotd[];
|
||||||
|
#endif
|
||||||
#if defined(CONFIG_NSH_TELNET_LOGIN) && defined(CONFIG_NSH_TELNET)
|
#if defined(CONFIG_NSH_TELNET_LOGIN) && defined(CONFIG_NSH_TELNET)
|
||||||
extern const char g_telnetgreeting[];
|
extern const char g_telnetgreeting[];
|
||||||
extern const char g_userprompt[];
|
extern const char g_userprompt[];
|
||||||
|
@@ -224,6 +224,12 @@ const char g_nshgreeting[] = "\nNuttShell (NSH) NuttX-" CONFIG_VERSION_STR
|
|||||||
const char g_nshgreeting[] = "\nNuttShell (NSH)\n";
|
const char g_nshgreeting[] = "\nNuttShell (NSH)\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Fixed Message of the Day (MOTD) */
|
||||||
|
|
||||||
|
#if defined(CONFIG_NSH_MOTD) && !defined(CONFIG_NSH_PLATFORM_MOTD)
|
||||||
|
const char g_nshmotd[] = CONFIG_NSH_MOTD_STRING;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Telnet login prompts */
|
/* Telnet login prompts */
|
||||||
|
|
||||||
#if defined(CONFIG_NSH_TELNET_LOGIN) && defined(CONFIG_NSH_TELNET)
|
#if defined(CONFIG_NSH_TELNET_LOGIN) && defined(CONFIG_NSH_TELNET)
|
||||||
|
@@ -103,19 +103,36 @@
|
|||||||
|
|
||||||
int nsh_session(FAR struct console_stdio_s *pstate)
|
int nsh_session(FAR struct console_stdio_s *pstate)
|
||||||
{
|
{
|
||||||
|
FAR struct nsh_vtbl_s *vtbl;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
DEBUGASSERT(pstate);
|
DEBUGASSERT(pstate);
|
||||||
|
vtbl = &pstate->cn_vtbl;
|
||||||
|
|
||||||
/* Present a greeting */
|
/* Present a greeting and possibly a Message of the Day (MOTD) */
|
||||||
|
|
||||||
fputs(g_nshgreeting, pstate->cn_outstream);
|
fputs(g_nshgreeting, pstate->cn_outstream);
|
||||||
|
|
||||||
|
#ifdef CONFIG_NSH_MOTD
|
||||||
|
# ifdef CONFIG_NSH_PLATFORM_MOTD
|
||||||
|
/* Output the platform message of the day */
|
||||||
|
|
||||||
|
platform_motd(vtbl->iobuffer, IOBUFFERSIZE);
|
||||||
|
fprintf(pstate->cn_outstream, "%s\n", vtbl->iobuffer);
|
||||||
|
|
||||||
|
# else
|
||||||
|
/* Output the fixed message of the day */
|
||||||
|
|
||||||
|
fprintf(pstate->cn_outstream, "%s\n", g_nshmotd);
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
fflush(pstate->cn_outstream);
|
fflush(pstate->cn_outstream);
|
||||||
|
|
||||||
/* Execute the login script */
|
/* Execute the login script */
|
||||||
|
|
||||||
#ifdef CONFIG_NSH_ROMFSRC
|
#ifdef CONFIG_NSH_ROMFSRC
|
||||||
(void)nsh_loginscript(&pstate->cn_vtbl);
|
(void)nsh_loginscript(vtbl);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Then enter the command line parsing loop */
|
/* Then enter the command line parsing loop */
|
||||||
@@ -148,7 +165,7 @@ int nsh_session(FAR struct console_stdio_s *pstate)
|
|||||||
{
|
{
|
||||||
/* Parse process the command */
|
/* Parse process the command */
|
||||||
|
|
||||||
(void)nsh_parse(&pstate->cn_vtbl, pstate->cn_line);
|
(void)nsh_parse(vtbl, pstate->cn_line);
|
||||||
fflush(pstate->cn_outstream);
|
fflush(pstate->cn_outstream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -102,14 +102,30 @@
|
|||||||
|
|
||||||
int nsh_session(FAR struct console_stdio_s *pstate)
|
int nsh_session(FAR struct console_stdio_s *pstate)
|
||||||
{
|
{
|
||||||
|
FAR struct nsh_vtbl_s *vtbl;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
DEBUGASSERT(pstate);
|
DEBUGASSERT(pstate);
|
||||||
|
vtbl = &pstate->cn_vtbl;
|
||||||
|
|
||||||
/* Present a greeting */
|
/* Present a greeting and possibly a Message of the Day (MOTD) */
|
||||||
|
|
||||||
printf("%s", g_nshgreeting);
|
printf("%s", g_nshgreeting);
|
||||||
|
|
||||||
|
#ifdef CONFIG_NSH_MOTD
|
||||||
|
# ifdef CONFIG_NSH_PLATFORM_MOTD
|
||||||
|
/* Output the platform message of the day */
|
||||||
|
|
||||||
|
platform_motd(vtbl->iobuffer, IOBUFFERSIZE);
|
||||||
|
printf("%s\n", vtbl->iobuffer);
|
||||||
|
|
||||||
|
# else
|
||||||
|
/* Output the fixed message of the day */
|
||||||
|
|
||||||
|
printf("%s\n", g_nshmotd);
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Then enter the command line parsing loop */
|
/* Then enter the command line parsing loop */
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
@@ -138,7 +154,7 @@ int nsh_session(FAR struct console_stdio_s *pstate)
|
|||||||
{
|
{
|
||||||
/* Parse process the command */
|
/* Parse process the command */
|
||||||
|
|
||||||
(void)nsh_parse(&pstate->cn_vtbl, pstate->cn_line);
|
(void)nsh_parse(vtbl, pstate->cn_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Readline normally returns the number of characters read,
|
/* Readline normally returns the number of characters read,
|
||||||
|
@@ -274,7 +274,10 @@ static int nsh_telnetlogin(FAR struct console_stdio_s *pstate)
|
|||||||
int nsh_telnetmain(int argc, char *argv[])
|
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;
|
||||||
|
|
||||||
DEBUGASSERT(pstate != NULL);
|
DEBUGASSERT(pstate != NULL);
|
||||||
|
vtbl = &pstate->cn_vtbl;
|
||||||
|
|
||||||
dbg("Session [%d] Started\n", getpid());
|
dbg("Session [%d] Started\n", getpid());
|
||||||
|
|
||||||
@@ -283,7 +286,7 @@ int nsh_telnetmain(int argc, char *argv[])
|
|||||||
#ifdef CONFIG_NSH_TELNET_LOGIN
|
#ifdef CONFIG_NSH_TELNET_LOGIN
|
||||||
if (nsh_telnetlogin(pstate) != OK)
|
if (nsh_telnetlogin(pstate) != OK)
|
||||||
{
|
{
|
||||||
nsh_exit(&pstate->cn_vtbl, 1);
|
nsh_exit(vtbl, 1);
|
||||||
return -1; /* nsh_exit does not return */
|
return -1; /* nsh_exit does not return */
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_NSH_TELNET_LOGIN */
|
#endif /* CONFIG_NSH_TELNET_LOGIN */
|
||||||
@@ -293,9 +296,24 @@ int nsh_telnetmain(int argc, char *argv[])
|
|||||||
* readline().
|
* readline().
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Present the NSH greeting */
|
/* Present a greeting and possibly a Message of the Day (MOTD) */
|
||||||
|
|
||||||
fputs(g_nshgreeting, pstate->cn_outstream);
|
fputs(g_nshgreeting, pstate->cn_outstream);
|
||||||
|
|
||||||
|
#ifdef CONFIG_NSH_MOTD
|
||||||
|
# ifdef CONFIG_NSH_PLATFORM_MOTD
|
||||||
|
/* Output the platform message of the day */
|
||||||
|
|
||||||
|
platform_motd(vtbl->iobuffer, IOBUFFERSIZE);
|
||||||
|
fprintf(pstate->cn_outstream, "%s/n", vtbl->iobuffer);
|
||||||
|
|
||||||
|
# else
|
||||||
|
/* Output the fixed message of the day */
|
||||||
|
|
||||||
|
fprintf(pstate->cn_outstream, "%s/n", g_nshmotd);
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
fflush(pstate->cn_outstream);
|
fflush(pstate->cn_outstream);
|
||||||
|
|
||||||
/* Execute the startup script. If standard console is also defined, then
|
/* Execute the startup script. If standard console is also defined, then
|
||||||
@@ -304,13 +322,13 @@ int nsh_telnetmain(int argc, char *argv[])
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(CONFIG_NSH_ROMFSETC) && !defined(CONFIG_NSH_CONSOLE)
|
#if defined(CONFIG_NSH_ROMFSETC) && !defined(CONFIG_NSH_CONSOLE)
|
||||||
(void)nsh_initscript(&pstate->cn_vtbl);
|
(void)nsh_initscript(vtbl);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Execute the login script */
|
/* Execute the login script */
|
||||||
|
|
||||||
#ifdef CONFIG_NSH_ROMFSRC
|
#ifdef CONFIG_NSH_ROMFSRC
|
||||||
(void)nsh_loginscript(&pstate->cn_vtbl);
|
(void)nsh_loginscript(vtbl);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Then enter the command line parsing loop */
|
/* Then enter the command line parsing loop */
|
||||||
@@ -328,20 +346,20 @@ int nsh_telnetmain(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
/* Parse process the received Telnet command */
|
/* Parse process the received Telnet command */
|
||||||
|
|
||||||
(void)nsh_parse(&pstate->cn_vtbl, pstate->cn_line);
|
(void)nsh_parse(vtbl, pstate->cn_line);
|
||||||
fflush(pstate->cn_outstream);
|
fflush(pstate->cn_outstream);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(pstate->cn_outstream, g_fmtcmdfailed, "nsh_telnetmain",
|
fprintf(pstate->cn_outstream, g_fmtcmdfailed, "nsh_telnetmain",
|
||||||
"fgets", NSH_ERRNO);
|
"fgets", NSH_ERRNO);
|
||||||
nsh_exit(&pstate->cn_vtbl, 1);
|
nsh_exit(vtbl, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clean up */
|
/* Clean up */
|
||||||
|
|
||||||
nsh_exit(&pstate->cn_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 */
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user