From 960e63402eba0b88212c8bc287e036747a69363d Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Wed, 3 Feb 2021 21:03:01 +0800 Subject: [PATCH] nsh/builtin: Ignore the child status if run the application on background. N/A fix the leak of child status if the background process exceeds "CONFIG_PREALLOC_CHILDSTATUS". Signed-off-by: chao.an --- nshlib/nsh_builtin.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/nshlib/nsh_builtin.c b/nshlib/nsh_builtin.c index d9b33b74d..a40f97888 100644 --- a/nshlib/nsh_builtin.c +++ b/nshlib/nsh_builtin.c @@ -91,6 +91,10 @@ int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, FAR char **argv, FAR const char *redirfile, int oflags) { +#if !defined(CONFIG_NSH_DISABLEBG) && defined(CONFIG_SCHED_CHILD_STATUS) + struct sigaction act; + struct sigaction old; +#endif int ret = OK; /* Lock the scheduler in an attempt to prevent the application from @@ -99,6 +103,20 @@ int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, sched_lock(); +#if !defined(CONFIG_NSH_DISABLEBG) && defined(CONFIG_SCHED_CHILD_STATUS) + /* Ignore the child status if run the application on background. */ + + if (vtbl->np.np_bg == true) + { + act.sa_handler = SIG_DFL; + act.sa_flags = SA_NOCLDWAIT; + sigemptyset(&act.sa_mask); + + sigaction(SIGCHLD, &act, &old); + } + +#endif /* CONFIG_NSH_DISABLEBG */ + /* Try to find and execute the command within the list of builtin * applications. */ @@ -224,6 +242,12 @@ int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, #if !defined(CONFIG_SCHED_WAITPID) || !defined(CONFIG_NSH_DISABLEBG) { +# ifdef CONFIG_SCHED_CHILD_STATUS + + /* Restore the old actions */ + + sigaction(SIGCHLD, &old, NULL); +# endif struct sched_param param; sched_getparam(ret, ¶m); nsh_output(vtbl, "%s [%d:%d]\n", cmd, ret, param.sched_priority);