From patchwork Wed Jun 11 02:35:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chen Gang X-Patchwork-Id: 1428 Received: (qmail 32757 invoked by alias); 11 Jun 2014 02:36:02 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 32642 invoked by uid 89); 11 Jun 2014 02:35:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 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-pa0-f54.google.com Received: from mail-pa0-f54.google.com (HELO mail-pa0-f54.google.com) (209.85.220.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 11 Jun 2014 02:35:42 +0000 Received: by mail-pa0-f54.google.com with SMTP id rd3so1368880pab.13 for ; Tue, 10 Jun 2014 19:35:39 -0700 (PDT) X-Received: by 10.66.162.137 with SMTP id ya9mr9847998pab.31.1402454139639; Tue, 10 Jun 2014 19:35:39 -0700 (PDT) Received: from [192.168.1.23] ([124.127.118.42]) by mx.google.com with ESMTPSA id uj3sm21185929pac.8.2014.06.10.19.35.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 10 Jun 2014 19:35:39 -0700 (PDT) Message-ID: <5397C077.1080702@gmail.com> Date: Wed, 11 Jun 2014 10:35:35 +0800 From: Chen Gang User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: Andreas Schwab CC: palves@redhat.com, amodra@gmail.com, binutils@sourceware.org, bug-readline@gnu.org, gdb-patches@sourceware.org Subject: [PATCH] readline/histfile.c: Check and retry write() operation in history_truncate_file() 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. The related warning (cross compile for aarch64-linux): ../../binutils-gdb/readline/histfile.c: In function ‘history_truncate_file’: ../../binutils-gdb/readline/histfile.c:406:13: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused readline/ * readline/histfile.c (history_truncate_file): Check and retry write() operation. Signed-off-by: Chen Gang --- readline/ChangeLog.gdb | 5 +++++ readline/histfile.c | 25 +++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/readline/ChangeLog.gdb b/readline/ChangeLog.gdb index 1218fd7..f547a90 100644 --- a/readline/ChangeLog.gdb +++ b/readline/ChangeLog.gdb @@ -1,3 +1,8 @@ +2014-06-11 Chen Gang + + * readline/histfile.c (history_truncate_file): + Check and retry write() operation. + 2013-09-24 Pierre Muller * readline.c (bind_arrow_keys_internal): diff --git a/readline/histfile.c b/readline/histfile.c index 30a6182..66597a7 100644 --- a/readline/histfile.c +++ b/readline/histfile.c @@ -403,11 +403,32 @@ history_truncate_file (fname, lines) truncate to. */ if (bp > buffer && ((file = open (filename, O_WRONLY|O_TRUNC|O_BINARY, 0600)) != -1)) { - write (file, bp, chars_read - (bp - buffer)); + int chars_write; +#if defined (__BEOS__) + char *orig = bp; +#endif + + do + { + chars_write = write (file, bp, chars_read - (bp - buffer)); + if (chars_write < 0) + { + rv = errno; + close (file); + goto truncate_exit; + } + else if (chars_write == 0) + { + usleep (1000); + continue; + } + bp += chars_write; + } + while (chars_read - (bp - buffer) > 0); #if defined (__BEOS__) /* BeOS ignores O_TRUNC. */ - ftruncate (file, chars_read - (bp - buffer)); + ftruncate (file, chars_read - (orig - buffer)); #endif close (file);