nsh: Add pipeline support for nsh commandline

And nested pipeline supported.

Test
  1. Redirect in
    cat < /etc/init.d/rc.sysinit

  2. Simple pipeline
    ls | cat

  3. Nested pipeline
    ls | dd | cat | dd | cat

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
This commit is contained in:
wangjianyu3 2024-10-14 20:44:27 +08:00 committed by Xiang Xiao
parent 3da204c23e
commit c052bd8377
4 changed files with 186 additions and 1 deletions

View file

@ -158,6 +158,19 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv,
goto errout_with_actions;
}
}
#ifdef CONFIG_NSH_PIPELINE
else if (param->fd_in != -1)
{
ret = posix_spawn_file_actions_adddup2(&file_actions,
param->fd_in, 0);
if (ret != 0)
{
serr("ERROR: posix_spawn_file_actions_adddup2 failed: %d\n",
ret);
goto errout_with_actions;
}
}
#endif
/* Is output being redirected? */
@ -175,6 +188,19 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv,
goto errout_with_actions;
}
}
#ifdef CONFIG_NSH_PIPELINE
else if (param->fd_out != -1)
{
ret = posix_spawn_file_actions_adddup2(&file_actions,
param->fd_out, 1);
if (ret != 0)
{
serr("ERROR: posix_spawn_file_actions_adddup2 failed: %d\n",
ret);
goto errout_with_actions;
}
}
#endif
}
#ifdef CONFIG_LIBC_EXECFUNCS