Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] readline/histfile.c: Check and retry write() operation in history_truncate_file()
@ 2014-06-11  2:36 Chen Gang
  2014-06-18 20:33 ` [Bug-readline] " Chet Ramey
  0 siblings, 1 reply; 11+ messages in thread
From: Chen Gang @ 2014-06-11  2:36 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: palves, amodra, binutils, bug-readline, gdb-patches

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 <gang.chen.5i5j@gmail.com>
---
 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 <gang.chen.5i5j@gmail.com>
+
+	* readline/histfile.c (history_truncate_file):
+	Check and retry write() operation.
+
 2013-09-24  Pierre Muller  <muller@sourceware.org>
 
 	* 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);
-- 
1.9.2.459.g68773ac


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-06-25 22:16 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-11  2:36 [PATCH] readline/histfile.c: Check and retry write() operation in history_truncate_file() 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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox