From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28261 invoked by alias); 20 Jun 2014 21:53:47 -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 28234 invoked by uid 89); 20 Jun 2014 21:53:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mpv2.tis.cwru.edu Received: from mpv2.tis.CWRU.Edu (HELO mpv2.tis.cwru.edu) (129.22.105.37) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (DES-CBC3-SHA encrypted) ESMTPS; Fri, 20 Jun 2014 21:53:45 +0000 Received: from mpv8.tis.CWRU.Edu (EHLO mpv8.cwru.edu) ([129.22.105.116]) by mpv2.tis.cwru.edu (MOS 4.3.5-GA FastPath queued) with ESMTP id BGE04455; Fri, 20 Jun 2014 17:53:41 -0400 (EDT) Received: from h0.82.16.98.dynamic.ip.windstream.net (EHLO _192.168.254.10_) ([98.16.82.0]) by mpv8.cwru.edu (MOS 4.3.5-GA FastPath queued) with ESMTP id LIZ92859 (AUTH cpr); Fri, 20 Jun 2014 17:53:40 -0400 (EDT) Message-ID: <53A4AD62.6020408@case.edu> Date: Fri, 20 Jun 2014 21:53:00 -0000 From: Chet Ramey Reply-To: chet.ramey@case.edu User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: Chen Gang , Andreas Schwab CC: chet.ramey@case.edu, 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> In-Reply-To: <53A3F78E.6020803@gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Junkmail-Whitelist: YES (by domain whitelist at mpv2.tis.cwru.edu) X-SW-Source: 2014-06/txt/msg00785.txt.bz2 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. > > 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. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/