Skip to content

Commit

Permalink
nsh/builtin: Ignore the child status if run the application on backgr…
Browse files Browse the repository at this point in the history
…ound.

N/A

fix the leak of child status if the background process
exceeds "CONFIG_PREALLOC_CHILDSTATUS".

Signed-off-by: chao.an <anchao@xiaomi.com>
  • Loading branch information
anchao authored and xiaoxiang781216 committed Mar 21, 2021
1 parent 08f1dd0 commit 960e634
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions nshlib/nsh_builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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, &param);
nsh_output(vtbl, "%s [%d:%d]\n", cmd, ret, param.sched_priority);
Expand Down

0 comments on commit 960e634

Please sign in to comment.