Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Chen Gang <gang.chen.5i5j@gmail.com>
To: chet.ramey@case.edu
Cc: Andreas Schwab <schwab@linux-m68k.org>,
	palves@redhat.com,  gdb-patches@sourceware.org,
	binutils@sourceware.org,  bug-readline@gnu.org, amodra@gmail.com
Subject: Re: [Bug-readline] [PATCH] readline/histfile.c: Check and retry write() operation in history_truncate_file()
Date: Sat, 21 Jun 2014 02:25:00 -0000	[thread overview]
Message-ID: <53A4ED1B.2060608@gmail.com> (raw)
In-Reply-To: <53A4AD62.6020408@case.edu>

On 06/21/2014 05:53 AM, Chet Ramey wrote:
> On 6/20/14, 4:57 AM, Chen Gang wrote:
>> On 06/19/2014 09:31 AM, Chen Gang wrote:
>>>
>>>
>>> On 06/19/2014 04:33 AM, Chet Ramey wrote:
>>>> On 6/10/14, 10:35 PM, Chen Gang wrote:
>>>>> For regular file, write() operation may also fail, so check it too. If
>>>>> write() return 0, can simply wait and try again, it should not suspend
>>>>> infinitely if environments have no critical issues.
>>>>
>>>> Readline-6.3 checks the return value from write() and returns a non-zero
>>>> value to the history_truncate_file caller.  I really don't think that
>>>> waiting forever if write continues to return 0 is a great idea; an error
>>>> return is enough to let the caller deal with it.
>>>>
>>
>> Oh, sorry, after think of again, for me, we have to waiting forever if
>> write() continues to return 0.
> 
> There aren't really any plausible conditions under which write(2) returns
> 0 instead of -1 when writing a non-zero number of bytes to a regular file.
> 

Hmm... for me, what you said is acceptable.  And the function comment need be
changed:

  "Returns 0 on success, errno or -1 on failure"

>>
>> When this case happens, the file is already truncated, and the left data
>> which is writing to file will be free after return from
>> history_truncate_file().
>>
>> If return an error code in this case, the caller can not deal with it --
>> the log data which should be remained, have been lost, can not get them
>> back again.
> 
> However, you're right about the data being lost if write fails and returns
> -1. Since the sequence of operations is open-read-close-open-write-close, I
> think I will change the code for the next version to use a scheme similar
> to history_do_write() and restore the original version of the file if the
> write fails.
> 

OK, thanks.

And since you will work for it next, is it still necessary to send patch v2 for
the temporary fix, at present?


Thanks
-- 
Open share and attitude like air warter and life which God blessed


  reply	other threads:[~2014-06-21  2:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-11  2:36 Chen Gang
2014-06-18 20:33 ` [Bug-readline] " Chet Ramey
2014-06-19  1:31   ` Chen Gang
2014-06-20  8:58     ` Chen Gang
2014-06-20 21:53       ` Chet Ramey
2014-06-21  2:25         ` Chen Gang [this message]
2014-06-21 23:19           ` Chet Ramey
2014-06-22  2:01             ` Chen Gang
2014-06-23 13:57               ` Chet Ramey
2014-06-23 14:59                 ` Chen Gang
2014-06-25 22:16                   ` Chen Gang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53A4ED1B.2060608@gmail.com \
    --to=gang.chen.5i5j@gmail.com \
    --cc=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=bug-readline@gnu.org \
    --cc=chet.ramey@case.edu \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    --cc=schwab@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox