You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/04/19 14:07:19 UTC

[incubator-nuttx-apps] 05/09: nshlib: Add login argument to nsh_session for controling the login process

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

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

commit 9ab5e2ff450314c743e416f914d084d52bb9fd8a
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Apr 18 23:53:32 2020 +0800

    nshlib: Add login argument to nsh_session for controling the login process
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 nshlib/nsh.h             |  2 +-
 nshlib/nsh_altconsole.c  |  2 +-
 nshlib/nsh_consolemain.c |  2 +-
 nshlib/nsh_session.c     | 37 ++++++++++++++++++++-----------------
 nshlib/nsh_stdsession.c  | 31 +++++++++++++++++--------------
 nshlib/nsh_usbconsole.c  |  2 +-
 6 files changed, 41 insertions(+), 35 deletions(-)

diff --git a/nshlib/nsh.h b/nshlib/nsh.h
index feed7bd..96623f3 100644
--- a/nshlib/nsh.h
+++ b/nshlib/nsh.h
@@ -860,7 +860,7 @@ int nsh_loginscript(FAR struct nsh_vtbl_s *vtbl);
 /* Basic session and message handling */
 
 struct console_stdio_s;
-int nsh_session(FAR struct console_stdio_s *pstate);
+int nsh_session(FAR struct console_stdio_s *pstate, bool login);
 int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline);
 
 /****************************************************************************
diff --git a/nshlib/nsh_altconsole.c b/nshlib/nsh_altconsole.c
index ed2fe82..b699634 100644
--- a/nshlib/nsh_altconsole.c
+++ b/nshlib/nsh_altconsole.c
@@ -317,7 +317,7 @@ int nsh_consolemain(int argc, char *argv[])
 
       /* Execute the session */
 
-      nsh_session(pstate);
+      nsh_session(pstate, true);
 
       /* We lost the connection.  Wait for the keyboard to
        * be re-connected.
diff --git a/nshlib/nsh_consolemain.c b/nshlib/nsh_consolemain.c
index e213c4c..84f8275 100644
--- a/nshlib/nsh_consolemain.c
+++ b/nshlib/nsh_consolemain.c
@@ -106,7 +106,7 @@ int nsh_consolemain(int argc, char *argv[])
 
   /* Execute the session */
 
-  ret = nsh_session(pstate);
+  ret = nsh_session(pstate, true);
 
   /* Exit upon return */
 
diff --git a/nshlib/nsh_session.c b/nshlib/nsh_session.c
index 6b5ac55..00aadcd 100644
--- a/nshlib/nsh_session.c
+++ b/nshlib/nsh_session.c
@@ -79,7 +79,7 @@
  *
  ****************************************************************************/
 
-int nsh_session(FAR struct console_stdio_s *pstate)
+int nsh_session(FAR struct console_stdio_s *pstate, bool login)
 {
   FAR struct nsh_vtbl_s *vtbl;
   int ret;
@@ -87,41 +87,44 @@ int nsh_session(FAR struct console_stdio_s *pstate)
   DEBUGASSERT(pstate);
   vtbl = &pstate->cn_vtbl;
 
+  if (login)
+    {
 #ifdef CONFIG_NSH_CONSOLE_LOGIN
-  /* Login User and Password Check */
+      /* Login User and Password Check */
 
-  if (nsh_login(pstate) != OK)
-    {
-      nsh_exit(vtbl, 1);
-      return -1; /* nsh_exit does not return */
-    }
+      if (nsh_login(pstate) != OK)
+        {
+          nsh_exit(vtbl, 1);
+          return -1; /* nsh_exit does not return */
+        }
 #endif /* CONFIG_NSH_CONSOLE_LOGIN */
 
-  /* Present a greeting and possibly a Message of the Day (MOTD) */
+      /* 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 */
+      /* Output the platform message of the day */
 
-  platform_motd(vtbl->iobuffer, IOBUFFERSIZE);
-  fprintf(pstate->cn_outstream, "%s\n", vtbl->iobuffer);
+      platform_motd(vtbl->iobuffer, IOBUFFERSIZE);
+      fprintf(pstate->cn_outstream, "%s\n", vtbl->iobuffer);
 
 #else
-  /* Output the fixed message of the day */
+      /* Output the fixed message of the day */
 
-  fprintf(pstate->cn_outstream, "%s\n", g_nshmotd);
+      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
-  nsh_loginscript(vtbl);
+      nsh_loginscript(vtbl);
 #endif
+    }
 
   /* Then enter the command line parsing loop */
 
diff --git a/nshlib/nsh_stdsession.c b/nshlib/nsh_stdsession.c
index 64353d1..e5f1e03 100644
--- a/nshlib/nsh_stdsession.c
+++ b/nshlib/nsh_stdsession.c
@@ -76,7 +76,7 @@
  *
  ****************************************************************************/
 
-int nsh_session(FAR struct console_stdio_s *pstate)
+int nsh_session(FAR struct console_stdio_s *pstate, bool login)
 {
   FAR struct nsh_vtbl_s *vtbl;
   int ret;
@@ -84,34 +84,37 @@ int nsh_session(FAR struct console_stdio_s *pstate)
   DEBUGASSERT(pstate);
   vtbl = &pstate->cn_vtbl;
 
+  if (login)
+    {
 #ifdef CONFIG_NSH_CONSOLE_LOGIN
-  /* Login User and Password Check */
+      /* Login User and Password Check */
 
-  if (nsh_stdlogin(pstate) != OK)
-    {
-      nsh_exit(vtbl, 1);
-      return -1; /* nsh_exit does not return */
-    }
+      if (nsh_stdlogin(pstate) != OK)
+        {
+          nsh_exit(vtbl, 1);
+          return -1; /* nsh_exit does not return */
+        }
 #endif /* CONFIG_NSH_CONSOLE_LOGIN */
 
-  /* Present a greeting and possibly a Message of the Day (MOTD) */
+      /* 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 */
+      /* Output the platform message of the day */
 
-  platform_motd(vtbl->iobuffer, IOBUFFERSIZE);
-  printf("%s\n", vtbl->iobuffer);
+      platform_motd(vtbl->iobuffer, IOBUFFERSIZE);
+      printf("%s\n", vtbl->iobuffer);
 
 # else
-  /* Output the fixed message of the day */
+      /* Output the fixed message of the day */
 
-  printf("%s\n", g_nshmotd);
+      printf("%s\n", g_nshmotd);
 
 # endif
 #endif
+    }
 
   /* Then enter the command line parsing loop */
 
diff --git a/nshlib/nsh_usbconsole.c b/nshlib/nsh_usbconsole.c
index 60a8815..c60d965 100644
--- a/nshlib/nsh_usbconsole.c
+++ b/nshlib/nsh_usbconsole.c
@@ -339,7 +339,7 @@ int nsh_consolemain(int argc, char *argv[])
 
       /* Execute the session */
 
-      nsh_session(pstate);
+      nsh_session(pstate, true);
 
       /* Switch to /dev/null because we probably no longer have a
        * valid console device.