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 <anchao@xiaomi.com>
This commit is contained in:
parent
08f1dd0093
commit
960e63402e
@ -91,6 +91,10 @@
|
|||||||
int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
|
int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
|
||||||
FAR char **argv, FAR const char *redirfile, int oflags)
|
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;
|
int ret = OK;
|
||||||
|
|
||||||
/* Lock the scheduler in an attempt to prevent the application from
|
/* 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();
|
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
|
/* Try to find and execute the command within the list of builtin
|
||||||
* applications.
|
* 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)
|
#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;
|
struct sched_param param;
|
||||||
sched_getparam(ret, ¶m);
|
sched_getparam(ret, ¶m);
|
||||||
nsh_output(vtbl, "%s [%d:%d]\n", cmd, ret, param.sched_priority);
|
nsh_output(vtbl, "%s [%d:%d]\n", cmd, ret, param.sched_priority);
|
||||||
|
Loading…
Reference in New Issue
Block a user