diff --git a/libs/libc/stdlib/lib_exit.c b/libs/libc/stdlib/lib_exit.c index f7e7b18fdc83a..82f35fff9fe6c 100644 --- a/libs/libc/stdlib/lib_exit.c +++ b/libs/libc/stdlib/lib_exit.c @@ -23,11 +23,18 @@ ****************************************************************************/ #include + #include #include #include "atexit.h" +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +void nxtask_exit_cleanup(int status); + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -38,5 +45,7 @@ void exit(int status) /* REVISIT: Need to flush files and streams */ + nxtask_exit_cleanup(status); + _exit(status); } diff --git a/sched/task/exit.c b/sched/task/exit.c index 97d0b7a05b3bd..e649f895d3969 100644 --- a/sched/task/exit.c +++ b/sched/task/exit.c @@ -53,24 +53,24 @@ void _exit(int status) { - up_exit(status); + up_exit(status & 0xff); } /**************************************************************************** - * Name: exit + * Name: nxtask_exit_cleanup * * Description: - * The exit() function causes normal process termination and the value of - * status & 0377 to be returned to the parent. + * Perform cleanup before task is closed. * - * All functions registered with atexit() and on_exit() are called, in the - * reverse order of their registration. + * If SCHED_ATEXIT or SCHED_ONEXIT are defined, all functions registered + * with atexit() and on_exit() are called, in the reverse order of their + * registration. * * All open streams are flushed and closed. * ****************************************************************************/ -void exit(int status) +void nxtask_exit_cleanup(int status) { FAR struct tcb_s *tcb = this_task(); @@ -101,10 +101,4 @@ void exit(int status) */ nxtask_exithook(tcb, status, false); - - /* Then "really" exit. Only the lower 8 bits of the exit status are - * used. - */ - - _exit(status); }