nshlib:support nsh can redirect
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
parent
2d2e36c5e9
commit
beb9188cee
@ -854,6 +854,12 @@ config NSH_FATMOUNTPT
|
||||
will mount a FAT FS under /tmp. This is the location where the FAT
|
||||
FS will be mounted. Default is "/tmp".
|
||||
|
||||
config NSH_SCRIPT_REDIRECT_PATH
|
||||
string "rcS redirect output"
|
||||
default ""
|
||||
---help---
|
||||
This option can redirect rcS output.such as /dev/log or other.
|
||||
|
||||
endif # NSH_ROMFSETC
|
||||
endmenu # Scripting Support
|
||||
|
||||
|
@ -23,12 +23,49 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "nsh.h"
|
||||
#include "nsh_console.h"
|
||||
|
||||
#if defined(CONFIG_FILE_STREAM) && !defined(CONFIG_NSH_DISABLESCRIPT)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
#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)
|
||||
{
|
||||
uint8_t save[SAVE_SIZE];
|
||||
int fd = -1;
|
||||
int ret;
|
||||
|
||||
if (CONFIG_NSH_SCRIPT_REDIRECT_PATH[0])
|
||||
{
|
||||
fd = open(CONFIG_NSH_SCRIPT_REDIRECT_PATH, 0666);
|
||||
if (fd > 0)
|
||||
{
|
||||
nsh_redirect(vtbl, fd, save);
|
||||
}
|
||||
}
|
||||
|
||||
ret = nsh_script(vtbl, cmd, path);
|
||||
if (CONFIG_NSH_SCRIPT_REDIRECT_PATH[0])
|
||||
{
|
||||
if (fd > 0)
|
||||
{
|
||||
nsh_undirect(vtbl, save);
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@ -157,7 +194,7 @@ int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
|
||||
#ifdef CONFIG_NSH_ROMFSETC
|
||||
int nsh_sysinitscript(FAR struct nsh_vtbl_s *vtbl)
|
||||
{
|
||||
return nsh_script(vtbl, "sysinit", NSH_SYSINITPATH);
|
||||
return nsh_script_redirect(vtbl, "sysinit", NSH_SYSINITPATH);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -190,8 +227,7 @@ int nsh_initscript(FAR struct nsh_vtbl_s *vtbl)
|
||||
|
||||
if (!already)
|
||||
{
|
||||
ret = nsh_script(vtbl, "init", NSH_INITPATH);
|
||||
|
||||
ret = nsh_script_redirect(vtbl, "init", NSH_INITPATH);
|
||||
#ifndef CONFIG_NSH_DISABLESCRIPT
|
||||
/* Reset the option flags */
|
||||
|
||||
@ -214,7 +250,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(vtbl, "login", NSH_RCPATH);
|
||||
return nsh_script_redirect(vtbl, "login", NSH_RCPATH);
|
||||
}
|
||||
#endif
|
||||
#endif /* CONFIG_NSH_ROMFSETC */
|
||||
|
Loading…
Reference in New Issue
Block a user