nshlib/script: avoid output unnecessary log when missing rc.sysinit file
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
parent
9d1a70af86
commit
542558f2c1
@ -803,7 +803,7 @@ int nsh_usbconsole(void);
|
|||||||
|
|
||||||
#if defined(CONFIG_FILE_STREAM) && !defined(CONFIG_NSH_DISABLESCRIPT)
|
#if defined(CONFIG_FILE_STREAM) && !defined(CONFIG_NSH_DISABLESCRIPT)
|
||||||
int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
|
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
|
#ifdef CONFIG_NSH_ROMFSETC
|
||||||
int nsh_sysinitscript(FAR struct nsh_vtbl_s *vtbl);
|
int nsh_sysinitscript(FAR struct nsh_vtbl_s *vtbl);
|
||||||
int nsh_initscript(FAR struct nsh_vtbl_s *vtbl);
|
int nsh_initscript(FAR struct nsh_vtbl_s *vtbl);
|
||||||
|
@ -1815,7 +1815,7 @@ int cmd_source(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
|||||||
{
|
{
|
||||||
UNUSED(argc);
|
UNUSED(argc);
|
||||||
|
|
||||||
return nsh_script(vtbl, argv[0], argv[1]);
|
return nsh_script(vtbl, argv[0], argv[1], true);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -37,7 +37,8 @@
|
|||||||
#if defined(CONFIG_NSH_ROMFSETC) || defined(CONFIG_NSH_ROMFSRC)
|
#if defined(CONFIG_NSH_ROMFSETC) || defined(CONFIG_NSH_ROMFSRC)
|
||||||
static int nsh_script_redirect(FAR struct nsh_vtbl_s *vtbl,
|
static int nsh_script_redirect(FAR struct nsh_vtbl_s *vtbl,
|
||||||
FAR const char *cmd,
|
FAR const char *cmd,
|
||||||
FAR const char *path)
|
FAR const char *path,
|
||||||
|
bool log)
|
||||||
{
|
{
|
||||||
uint8_t save[SAVE_SIZE];
|
uint8_t save[SAVE_SIZE];
|
||||||
int fd = -1;
|
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 (CONFIG_NSH_SCRIPT_REDIRECT_PATH[0])
|
||||||
{
|
{
|
||||||
if (fd > 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,
|
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 char *fullpath;
|
||||||
FAR FILE *savestream;
|
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");
|
vtbl->np.np_stream = fopen(fullpath, "r");
|
||||||
if (!vtbl->np.np_stream)
|
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 */
|
/* 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_foffs = ftell(vtbl->np.np_stream);
|
||||||
vtbl->np.np_loffs = 0;
|
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);
|
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
|
#ifdef CONFIG_NSH_ROMFSETC
|
||||||
int nsh_sysinitscript(FAR struct nsh_vtbl_s *vtbl)
|
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
|
#endif
|
||||||
|
|
||||||
@ -227,7 +235,7 @@ int nsh_initscript(FAR struct nsh_vtbl_s *vtbl)
|
|||||||
|
|
||||||
if (!already)
|
if (!already)
|
||||||
{
|
{
|
||||||
ret = nsh_script_redirect(vtbl, "init", NSH_INITPATH);
|
ret = nsh_script_redirect(vtbl, "init", NSH_INITPATH, true);
|
||||||
#ifndef CONFIG_NSH_DISABLESCRIPT
|
#ifndef CONFIG_NSH_DISABLESCRIPT
|
||||||
/* Reset the option flags */
|
/* Reset the option flags */
|
||||||
|
|
||||||
@ -250,7 +258,7 @@ int nsh_initscript(FAR struct nsh_vtbl_s *vtbl)
|
|||||||
#ifdef CONFIG_NSH_ROMFSRC
|
#ifdef CONFIG_NSH_ROMFSRC
|
||||||
int nsh_loginscript(FAR struct nsh_vtbl_s *vtbl)
|
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
|
||||||
#endif /* CONFIG_NSH_ROMFSETC */
|
#endif /* CONFIG_NSH_ROMFSETC */
|
||||||
|
@ -165,7 +165,7 @@ int nsh_session(FAR struct console_stdio_s *pstate,
|
|||||||
#ifndef CONFIG_NSH_DISABLESCRIPT
|
#ifndef CONFIG_NSH_DISABLESCRIPT
|
||||||
/* Execute the shell script */
|
/* Execute the shell script */
|
||||||
|
|
||||||
return nsh_script(vtbl, argv[0], argv[1]);
|
return nsh_script(vtbl, argv[0], argv[1], true);
|
||||||
#else
|
#else
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
#endif
|
#endif
|
||||||
|
@ -167,7 +167,7 @@ int nsh_session(FAR struct console_stdio_s *pstate,
|
|||||||
#ifndef CONFIG_NSH_DISABLESCRIPT
|
#ifndef CONFIG_NSH_DISABLESCRIPT
|
||||||
/* Execute the shell script */
|
/* Execute the shell script */
|
||||||
|
|
||||||
return nsh_script(vtbl, argv[0], argv[i]);
|
return nsh_script(vtbl, argv[0], argv[i], true);
|
||||||
#else
|
#else
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user