From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3790 invoked by alias); 21 Jun 2014 02:25:41 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 3748 invoked by uid 89); 21 Jun 2014 02:25:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-pb0-f52.google.com Received: from mail-pb0-f52.google.com (HELO mail-pb0-f52.google.com) (209.85.160.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sat, 21 Jun 2014 02:25:36 +0000 Received: by mail-pb0-f52.google.com with SMTP id rq2so3738983pbb.11 for ; Fri, 20 Jun 2014 19:25:34 -0700 (PDT) X-Received: by 10.66.216.197 with SMTP id os5mr9728812pac.29.1403317534715; Fri, 20 Jun 2014 19:25:34 -0700 (PDT) Received: from [192.168.1.104] ([223.72.65.24]) by mx.google.com with ESMTPSA id kh4sm15588911pbc.64.2014.06.20.19.25.31 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 20 Jun 2014 19:25:34 -0700 (PDT) Message-ID: <53A4ED1B.2060608@gmail.com> Date: Sat, 21 Jun 2014 02:25:00 -0000 From: Chen Gang User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130625 Thunderbird/17.0.7 MIME-Version: 1.0 To: chet.ramey@case.edu CC: Andreas Schwab , 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() References: <5397C077.1080702@gmail.com> <53A1F78A.8020508@case.edu> <53A23D77.1040905@gmail.com> <53A3F78E.6020803@gmail.com> <53A4AD62.6020408@case.edu> In-Reply-To: <53A4AD62.6020408@case.edu> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-SW-Source: 2014-06/txt/msg00788.txt.bz2 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