diff --git a/nshlib/nsh.h b/nshlib/nsh.h index 12aeb4604..4bd8ae974 100644 --- a/nshlib/nsh.h +++ b/nshlib/nsh.h @@ -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); diff --git a/nshlib/nsh_fscmds.c b/nshlib/nsh_fscmds.c index 4f161a37b..68419faeb 100644 --- a/nshlib/nsh_fscmds.c +++ b/nshlib/nsh_fscmds.c @@ -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 diff --git a/nshlib/nsh_script.c b/nshlib/nsh_script.c index c28f8d2d3..56a821bbd 100644 --- a/nshlib/nsh_script.c +++ b/nshlib/nsh_script.c @@ -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 */ diff --git a/nshlib/nsh_session.c b/nshlib/nsh_session.c index 20b5ba2af..5fe67f2db 100644 --- a/nshlib/nsh_session.c +++ b/nshlib/nsh_session.c @@ -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 diff --git a/nshlib/nsh_stdsession.c b/nshlib/nsh_stdsession.c index f33832960..17b56e7b5 100644 --- a/nshlib/nsh_stdsession.c +++ b/nshlib/nsh_stdsession.c @@ -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