This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Releasing stdout/stdin/stderr descriptors when a task/process finishes


Hello,

I got some glue. The problem is in function __sinit, when _REENT_SMALL
is define the __sglue._niobs = 0; and   s->__sglue._iobs = NULL.

What about to add to _cleanup_r?
#if defined(_REENT_SMALL) && defined(_STDIO_CLOSE_PER_REENT_STD_STREAMS)
_CAST_VOID cleanup_func(ptr, ptr->_stdin);
_CAST_VOID cleanup_func(ptr, ptr->_stdout);
_CAST_VOID cleanup_func(ptr, ptr->_stderr);
#endif
_CAST_VOID _fwalk_reent (ptr, cleanup_func);


Martin

On Thu, Aug 13, 2015 at 12:58 PM, Martin Velek <martin.velek@gmail.com> wrote:
> Hello,
>
> how are the stdout/stdin/stderr descriptors freed when a task/process
> finishes? I am using FreeRTOS with newlib support and when the task
> finishes its job the _reclaim_reent is called. The stdio cleanup is
> called because ptr->__sdidinit != 0, it will walk it with
> _fwalk_reent (ptr, _fclose_r). However in the for-cycle a function
> pointer to _fclose_r command (_fwalk_reent) is never called because
> the g->_niobs = 0. It leaves stdout/stdin/stderr with flags fp->_flags
> != 0 which means the descriptor is not free.
>
> Manual close by fclose (stdout/stdin/stderr ) before the task finishes
> is possible but I would prefer an implicit(do not care about it) way.
>
> Here is a pseudo example:
>
> #include <rtos support>
> #include <stdio.h>
> Task A
> {
> char buff[20];
> fwrite(buff,1,1,stdout);
> return;
> }
>
>
> BR
> Martin
>
>
> I have compiled the newlib 2.2.0 with these parameters:
>
>  ./configure --target=arm-none-eabi --disable-newlib-supplied-syscalls
> --enable-newlib-io-long-long --enable-newlib-reent-small
> --disable-libgloss --enable-newlib-io-c99-formats
> --disable-newlib-atexit-dynamic-alloc --enable-newlib-global-atexit
> --enable-newlib-reent-small --disable-newlib-wide-orient
> --disable-multilib --enable-newlib-multithread
> --disable-newlib-register-fini --disable-newlib-mb
> --disable-newlib-unbuf-stream-opt --disable-newlib-fvwrite-in-streamio
> --disable-newlib-io-long-double
>
> make CFLAGS_FOR_TARGET="-DMALLOC_PROVIDED -DHAVE_ASSERT_FUNC
> -DREENTRANT_SYSCALLS_PROVIDED -DSIGNAL_PROVIDED -DSTRING_ONLY
> -fstack-usage -ffunction-sections -fdata-sections -Wstack-usage=512
> -mcpu=cortex-m3 -mthumb -std=gnu11 -fno-common -g3"
>
> arm-none-eabi-gcc -v
> gcc version 4.9.3 20150303 (release) [ARM/embedded-4_9-branch revision
> 221220] (GNU Tools for ARM Embedded Processors)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]