You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by wei peng <al...@gmail.com> on 2019/12/23 07:41:40 UTC

[PATCH] doubt about fwrite

hi~
  I connected the target board to terminal via "telnet" ,  in some cases
the terminal will be frozen. Here are detailed steps:

   1. Enable "CONFIG_IOB_DEBUG"[necessary].
   2. New two terminals and connect to target board via "telnet".
   3. Input "dmesg" command,and the terminal will show information
   *continuously*.[two terminals are same][necessary]
   4. Close one of  the terminals,and the other one will be frozen.but the
   system is work on.

I debug the system and repaired the bug,the file named commit.txt is
detailed steps.
BR,

wei peng

Re: [PATCH] doubt about fwrite

Posted by Gregory Nutt <sp...@gmail.com>.
> see the size_t is unsigned cannot be negative. that is the problem.
> i think if the terminal is close,the "size_t fwrite()"function should
> return a negative number,and the nsh_catfile should be broken.

That is not the way that fwrite returns errors.  If an error occurs 
fwrite returns fewer item than you requested to send.  That is required 
by the specification: 
https://pubs.opengroup.org/onlinepubs/9699919799/functions/fwrite.html

On an error, fwrite will set the errno value and the error indictor


        RETURN VALUE

    The /fwrite/() function shall return the number of elements
    successfully written, which *may be less than **/nitems/**if a write
    error is encountered*. If /size/ or /nitems/ is 0, /fwrite/() shall
    return 0 and the state of the stream remains unchanged.
    Otherwise,*if a write error occurs, the error indicator for the
    stream shall be set*, ^[CX] [Option Start]  and /errno/ shall be set
    to indicate the error.

If fwrite() returns fewer items than you requiested (or zero), you must 
call ferror() to determine if an error occurred: 
https://pubs.opengroup.org/onlinepubs/009695399/functions/ferror.html

If the error indicator is set, you can get the error from the errno 
variable.

The error indicator is cleared with clearerr(): 
https://pubs.opengroup.org/onlinepubs/009695399/functions/clearerr.html

It may not return a negative value.



Re: [PATCH] doubt about fwrite

Posted by wei peng <al...@gmail.com>.
Thanks for gregory and xiang.
yes... the right way is modified the error handling code in
nsh_catfile not fwrite. I will repaired it again.

BR,
wei peng

Xiang Xiao <xi...@gmail.com> 于2019年12月24日周二 上午9:58写道:

> Hi Peng,
> From http://www.cplusplus.com/reference/cstdio/fwrite/
> fwrite return zero to indicate the error, the detailed info could get
> from errno.
> So the right change is modified the error handling code in
> nsh_catfile, not the return type of fwrite.
>
> Thanks
> Xiang
>
> On Tue, Dec 24, 2019 at 9:48 AM wei peng <al...@gmail.com> wrote:
> >
> > hi David,
> >
> > Thanks for your reply.
> >
> > Yes...i know the interface interface is standard,so what i had changed in
> > codes just repaired the problem.perhaps i should describe the problem  in
> > detail.
> >
> >
> > I entering "dmesg" on both terminals,because of the “CONFIG_IOB_DEBUG” is
> > enable so both of terminals will show messages continuously.
> > Then close one of them,and the other one will be frozen,after that i
> cannot
> > connect the borad (via usart or telnet).but i am sure the systerm is work
> > on.
> >
> >
> > I found the "dmesg" command call a function named "int nsh_catfile()",and
> > in this function,the logic is simple (read message from ramlog and write
> it
> > to terminals).
> > when write it to terminals ,it will call "size_t fwrite()"function, As
> you
> > see the size_t is unsigned cannot be negative. that is the problem.
> > i think if the terminal is close,the "size_t fwrite()"function should
> > return a negative number,and the nsh_catfile should be broken.
> >
> > BR,
> >
> > wei peng
> >
> > David Sidrane <da...@apache.org> 于2019年12月23日周一 下午5:36写道:
> >
> > > Hi wei peng
> > >  See below.
> > >
> > > On 2019/12/23 07:41:40, wei peng <al...@gmail.com> wrote:
> > > > hi~
> > > >   I connected the target board to terminal via "telnet" ,  in some
> cases
> > > > the terminal will be frozen. Here are detailed steps:
> > > >
> > > >    1. Enable "CONFIG_IOB_DEBUG"[necessary].
> > > >    2. New two terminals and connect to target board via "telnet".
> > > >    3. Input "dmesg" command,and the terminal will show information
> > > >    *continuously*.[two terminals are same][necessary]
> > > >    4. Close one of  the terminals,and the other one will be
> frozen.but
> > > the
> > > >    system is work on.
> > > >
> > > > I debug the system and repaired the bug,the file named commit.txt is
> > > > detailed steps.
> > > > BR,
> > > >
> > > > wei peng
> > >
> > > The interface is dictated by the OpenGroup stands [1]
> > > [1]
> https://pubs.opengroup.org/onlinepubs/009695399/functions/fwrite.html
> > >
> > > So that can not be changed.
> > >
> > > There must be a root cause related to what you are doing or a bug in
> the
> > > system. Check the configuration (compare it to other telnet board
> configs).
> > >
> > > Are you Entering dmesg on both terminals or on one and it is showing up
> > > the 2 terminals?
> > >
> > > David
> > >
> > >
>

Re: [PATCH] doubt about fwrite

Posted by Xiang Xiao <xi...@gmail.com>.
Hi Peng,
From http://www.cplusplus.com/reference/cstdio/fwrite/
fwrite return zero to indicate the error, the detailed info could get
from errno.
So the right change is modified the error handling code in
nsh_catfile, not the return type of fwrite.

Thanks
Xiang

On Tue, Dec 24, 2019 at 9:48 AM wei peng <al...@gmail.com> wrote:
>
> hi David,
>
> Thanks for your reply.
>
> Yes...i know the interface interface is standard,so what i had changed in
> codes just repaired the problem.perhaps i should describe the problem  in
> detail.
>
>
> I entering "dmesg" on both terminals,because of the “CONFIG_IOB_DEBUG” is
> enable so both of terminals will show messages continuously.
> Then close one of them,and the other one will be frozen,after that i cannot
> connect the borad (via usart or telnet).but i am sure the systerm is work
> on.
>
>
> I found the "dmesg" command call a function named "int nsh_catfile()",and
> in this function,the logic is simple (read message from ramlog and write it
> to terminals).
> when write it to terminals ,it will call "size_t fwrite()"function, As you
> see the size_t is unsigned cannot be negative. that is the problem.
> i think if the terminal is close,the "size_t fwrite()"function should
> return a negative number,and the nsh_catfile should be broken.
>
> BR,
>
> wei peng
>
> David Sidrane <da...@apache.org> 于2019年12月23日周一 下午5:36写道:
>
> > Hi wei peng
> >  See below.
> >
> > On 2019/12/23 07:41:40, wei peng <al...@gmail.com> wrote:
> > > hi~
> > >   I connected the target board to terminal via "telnet" ,  in some cases
> > > the terminal will be frozen. Here are detailed steps:
> > >
> > >    1. Enable "CONFIG_IOB_DEBUG"[necessary].
> > >    2. New two terminals and connect to target board via "telnet".
> > >    3. Input "dmesg" command,and the terminal will show information
> > >    *continuously*.[two terminals are same][necessary]
> > >    4. Close one of  the terminals,and the other one will be frozen.but
> > the
> > >    system is work on.
> > >
> > > I debug the system and repaired the bug,the file named commit.txt is
> > > detailed steps.
> > > BR,
> > >
> > > wei peng
> >
> > The interface is dictated by the OpenGroup stands [1]
> > [1] https://pubs.opengroup.org/onlinepubs/009695399/functions/fwrite.html
> >
> > So that can not be changed.
> >
> > There must be a root cause related to what you are doing or a bug in the
> > system. Check the configuration (compare it to other telnet board configs).
> >
> > Are you Entering dmesg on both terminals or on one and it is showing up
> > the 2 terminals?
> >
> > David
> >
> >

Re: [PATCH] doubt about fwrite

Posted by wei peng <al...@gmail.com>.
hi David,

Thanks for your reply.

Yes...i know the interface interface is standard,so what i had changed in
codes just repaired the problem.perhaps i should describe the problem  in
detail.


I entering "dmesg" on both terminals,because of the “CONFIG_IOB_DEBUG” is
enable so both of terminals will show messages continuously.
Then close one of them,and the other one will be frozen,after that i cannot
connect the borad (via usart or telnet).but i am sure the systerm is work
on.


I found the "dmesg" command call a function named "int nsh_catfile()",and
in this function,the logic is simple (read message from ramlog and write it
to terminals).
when write it to terminals ,it will call "size_t fwrite()"function, As you
see the size_t is unsigned cannot be negative. that is the problem.
i think if the terminal is close,the "size_t fwrite()"function should
return a negative number,and the nsh_catfile should be broken.

BR,

wei peng

David Sidrane <da...@apache.org> 于2019年12月23日周一 下午5:36写道:

> Hi wei peng
>  See below.
>
> On 2019/12/23 07:41:40, wei peng <al...@gmail.com> wrote:
> > hi~
> >   I connected the target board to terminal via "telnet" ,  in some cases
> > the terminal will be frozen. Here are detailed steps:
> >
> >    1. Enable "CONFIG_IOB_DEBUG"[necessary].
> >    2. New two terminals and connect to target board via "telnet".
> >    3. Input "dmesg" command,and the terminal will show information
> >    *continuously*.[two terminals are same][necessary]
> >    4. Close one of  the terminals,and the other one will be frozen.but
> the
> >    system is work on.
> >
> > I debug the system and repaired the bug,the file named commit.txt is
> > detailed steps.
> > BR,
> >
> > wei peng
>
> The interface is dictated by the OpenGroup stands [1]
> [1] https://pubs.opengroup.org/onlinepubs/009695399/functions/fwrite.html
>
> So that can not be changed.
>
> There must be a root cause related to what you are doing or a bug in the
> system. Check the configuration (compare it to other telnet board configs).
>
> Are you Entering dmesg on both terminals or on one and it is showing up
> the 2 terminals?
>
> David
>
>

Re: [PATCH] doubt about fwrite

Posted by David Sidrane <da...@apache.org>.
Hi wei peng
 See below.

On 2019/12/23 07:41:40, wei peng <al...@gmail.com> wrote: 
> hi~
>   I connected the target board to terminal via "telnet" ,  in some cases
> the terminal will be frozen. Here are detailed steps:
> 
>    1. Enable "CONFIG_IOB_DEBUG"[necessary].
>    2. New two terminals and connect to target board via "telnet".
>    3. Input "dmesg" command,and the terminal will show information
>    *continuously*.[two terminals are same][necessary]
>    4. Close one of  the terminals,and the other one will be frozen.but the
>    system is work on.
> 
> I debug the system and repaired the bug,the file named commit.txt is
> detailed steps.
> BR,
> 
> wei peng

The interface is dictated by the OpenGroup stands [1]
[1] https://pubs.opengroup.org/onlinepubs/009695399/functions/fwrite.html

So that can not be changed.

There must be a root cause related to what you are doing or a bug in the system. Check the configuration (compare it to other telnet board configs). 

Are you Entering dmesg on both terminals or on one and it is showing up the 2 terminals?

David