xiaoxiang781216 commented on code in PR #2522:
URL: https://github.com/apache/nuttx-apps/pull/2522#discussion_r1808513800
##########
nshlib/nsh_parse.c:
##########
@@ -757,108 +598,79 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl,
#ifndef CONFIG_NSH_DISABLEBG
if (vtbl->np.np_bg)
{
- struct sched_param param;
- struct nsh_vtbl_s *bkgvtbl;
- struct cmdarg_s *args;
- pthread_attr_t attr;
- pthread_t thread;
-
- /* Get a cloned copy of the vtbl with reference count=1.
- * after the command has been processed, the nsh_release() call
- * at the end of nsh_child() will destroy the clone.
- */
+ FAR char *spawn_argv[4];
+ FAR char *sh_cmd = "sh";
+ int i;
- bkgvtbl = nsh_clone(vtbl);
- if (!bkgvtbl)
- {
- goto errout_with_redirect;
- }
+ DEBUGASSERT(strncmp(argv[0], sh_cmd, 3) != 0);
- /* Create a container for the command arguments */
-
- args = nsh_cloneargs(bkgvtbl, fd_in, fd_out, argc, argv);
- if (!args)
+ spawn_argv[0] = sh_cmd;
+ spawn_argv[1] = "-c";
+ for (i = 0; i < argc - 1; i++)
{
- nsh_release(bkgvtbl);
- goto errout_with_redirect;
- }
+ char *p_arg = argv[i];
Review Comment:
```suggestion
FAR char *arg = argv[i];
```
##########
nshlib/nsh_parse.c:
##########
@@ -757,108 +598,79 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl,
#ifndef CONFIG_NSH_DISABLEBG
if (vtbl->np.np_bg)
{
- struct sched_param param;
- struct nsh_vtbl_s *bkgvtbl;
- struct cmdarg_s *args;
- pthread_attr_t attr;
- pthread_t thread;
-
- /* Get a cloned copy of the vtbl with reference count=1.
- * after the command has been processed, the nsh_release() call
- * at the end of nsh_child() will destroy the clone.
- */
+ FAR char *spawn_argv[4];
Review Comment:
```suggestion
FAR char *sh_argv[4];
```
##########
nshlib/nsh_parse.c:
##########
@@ -757,108 +598,79 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl,
#ifndef CONFIG_NSH_DISABLEBG
if (vtbl->np.np_bg)
{
- struct sched_param param;
- struct nsh_vtbl_s *bkgvtbl;
- struct cmdarg_s *args;
- pthread_attr_t attr;
- pthread_t thread;
-
- /* Get a cloned copy of the vtbl with reference count=1.
- * after the command has been processed, the nsh_release() call
- * at the end of nsh_child() will destroy the clone.
- */
+ FAR char *spawn_argv[4];
+ FAR char *sh_cmd = "sh";
+ int i;
- bkgvtbl = nsh_clone(vtbl);
- if (!bkgvtbl)
- {
- goto errout_with_redirect;
- }
+ DEBUGASSERT(strncmp(argv[0], sh_cmd, 3) != 0);
- /* Create a container for the command arguments */
-
- args = nsh_cloneargs(bkgvtbl, fd_in, fd_out, argc, argv);
- if (!args)
+ spawn_argv[0] = sh_cmd;
+ spawn_argv[1] = "-c";
+ for (i = 0; i < argc - 1; i++)
{
- nsh_release(bkgvtbl);
- goto errout_with_redirect;
- }
+ char *p_arg = argv[i];
+ size_t len = strlen(p_arg);
- /* Handle redirection of output via a file descriptor */
+ /* Restore from split args to concat args. */
- if (vtbl->np.np_redir_out || vtbl->np.np_redir_in)
- {
- nsh_redirect(bkgvtbl, fd_in, fd_out, NULL);
+ DEBUGASSERT(&p_arg[len + 1] == argv[i + 1]);
+ p_arg[len] = ' ';
}
- /* Get the execution priority of this task */
+ spawn_argv[2] = argv[0];
+ spawn_argv[3] = NULL;
- ret = sched_getparam(0, ¶m);
- if (ret != 0)
- {
- nsh_error(vtbl, g_fmtcmdfailed, argv[0], "sched_getparm",
- NSH_ERRNO);
+ /* np.np_bg still there, try use nsh_builtin or nsh_fileapp to
+ * dispatch the backgroud by sh -c ""
+ */
- /* NOTE: bkgvtbl is released in nsh_relaseargs() */
+ return nsh_execute(vtbl, 3, spawn_argv,
Review Comment:
```suggestion
return nsh_execute(vtbl, 4, spawn_argv,
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]