nshlib/script: avoid output unnecessary log when missing rc.sysinit file

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1 2022-12-28 17:59:08 +08:00 committed by Xiang Xiao
parent 9d1a70af86
commit 542558f2c1
5 changed files with 20 additions and 12 deletions

View File

@ -803,7 +803,7 @@ int nsh_usbconsole(void);
#if defined(CONFIG_FILE_STREAM) && !defined(CONFIG_NSH_DISABLESCRIPT)
int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
FAR const char *path);
FAR const char *path, bool log);
#ifdef CONFIG_NSH_ROMFSETC
int nsh_sysinitscript(FAR struct nsh_vtbl_s *vtbl);
int nsh_initscript(FAR struct nsh_vtbl_s *vtbl);

View File

@ -1815,7 +1815,7 @@ int cmd_source(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
{
UNUSED(argc);
return nsh_script(vtbl, argv[0], argv[1]);
return nsh_script(vtbl, argv[0], argv[1], true);
}
#endif
#endif

View File

@ -37,7 +37,8 @@
#if defined(CONFIG_NSH_ROMFSETC) || defined(CONFIG_NSH_ROMFSRC)
static int nsh_script_redirect(FAR struct nsh_vtbl_s *vtbl,
FAR const char *cmd,
FAR const char *path)
FAR const char *path,
bool log)
{
uint8_t save[SAVE_SIZE];
int fd = -1;
@ -52,7 +53,7 @@ static int nsh_script_redirect(FAR struct nsh_vtbl_s *vtbl,
}
}
ret = nsh_script(vtbl, cmd, path);
ret = nsh_script(vtbl, cmd, path, log);
if (CONFIG_NSH_SCRIPT_REDIRECT_PATH[0])
{
if (fd > 0)
@ -79,7 +80,7 @@ static int nsh_script_redirect(FAR struct nsh_vtbl_s *vtbl,
****************************************************************************/
int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const FAR char *cmd,
FAR const char *path)
FAR const char *path, bool log)
{
FAR char *fullpath;
FAR FILE *savestream;
@ -109,7 +110,10 @@ int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const FAR char *cmd,
vtbl->np.np_stream = fopen(fullpath, "r");
if (!vtbl->np.np_stream)
{
nsh_error(vtbl, g_fmtcmdfailed, cmd, "fopen", NSH_ERRNO);
if (log)
{
nsh_error(vtbl, g_fmtcmdfailed, cmd, "fopen", NSH_ERRNO);
}
/* Free the allocated path */
@ -141,7 +145,7 @@ int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const FAR char *cmd,
vtbl->np.np_foffs = ftell(vtbl->np.np_stream);
vtbl->np.np_loffs = 0;
if (vtbl->np.np_foffs < 0)
if (vtbl->np.np_foffs < 0 && log)
{
nsh_error(vtbl, g_fmtcmdfailed, "loop", "ftell", NSH_ERRNO);
}
@ -194,7 +198,11 @@ int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const FAR char *cmd,
#ifdef CONFIG_NSH_ROMFSETC
int nsh_sysinitscript(FAR struct nsh_vtbl_s *vtbl)
{
return nsh_script_redirect(vtbl, "sysinit", NSH_SYSINITPATH);
/* Since most existing systems only use the NSH_INITPATH script file.
* Do not log error output for a missing NSH_SYSINITPATH script file.
*/
return nsh_script_redirect(vtbl, "sysinit", NSH_SYSINITPATH, false);
}
#endif
@ -227,7 +235,7 @@ int nsh_initscript(FAR struct nsh_vtbl_s *vtbl)
if (!already)
{
ret = nsh_script_redirect(vtbl, "init", NSH_INITPATH);
ret = nsh_script_redirect(vtbl, "init", NSH_INITPATH, true);
#ifndef CONFIG_NSH_DISABLESCRIPT
/* Reset the option flags */
@ -250,7 +258,7 @@ int nsh_initscript(FAR struct nsh_vtbl_s *vtbl)
#ifdef CONFIG_NSH_ROMFSRC
int nsh_loginscript(FAR struct nsh_vtbl_s *vtbl)
{
return nsh_script_redirect(vtbl, "login", NSH_RCPATH);
return nsh_script_redirect(vtbl, "login", NSH_RCPATH, true);
}
#endif
#endif /* CONFIG_NSH_ROMFSETC */

View File

@ -165,7 +165,7 @@ int nsh_session(FAR struct console_stdio_s *pstate,
#ifndef CONFIG_NSH_DISABLESCRIPT
/* Execute the shell script */
return nsh_script(vtbl, argv[0], argv[1]);
return nsh_script(vtbl, argv[0], argv[1], true);
#else
return EXIT_FAILURE;
#endif

View File

@ -167,7 +167,7 @@ int nsh_session(FAR struct console_stdio_s *pstate,
#ifndef CONFIG_NSH_DISABLESCRIPT
/* Execute the shell script */
return nsh_script(vtbl, argv[0], argv[i]);
return nsh_script(vtbl, argv[0], argv[i], true);
#else
return EXIT_FAILURE;
#endif