[commit: ghc] master: EventLog: Loop fwrite if necessary during flush (f46f32b)

git at git.haskell.org git at git.haskell.org
Sun Nov 1 18:35:02 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/f46f32b922d7ecbee2829937295521f5db1d7997/ghc

>---------------------------------------------------------------

commit f46f32b922d7ecbee2829937295521f5db1d7997
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Sun Nov 1 19:06:09 2015 +0100

    EventLog: Loop fwrite if necessary during flush
    
    Previously the eventlog flush code would fail if `fwrite` wrote less
    than the requested amount. Like all Unix stream I/O operations, however,
    `fwrite` isn't guaranteed to write the entire buffer. Here we loop as
    long as `fwrite` succeeds in writing anything.
    
    Fixes #11041.
    
    Test Plan: Validate with eventlog
    
    Reviewers: austin, simonmar
    
    Reviewed By: simonmar
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D1415
    
    GHC Trac Issues: #11041


>---------------------------------------------------------------

f46f32b922d7ecbee2829937295521f5db1d7997
 rts/eventlog/EventLog.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/rts/eventlog/EventLog.c b/rts/eventlog/EventLog.c
index 2153942..db103a7 100644
--- a/rts/eventlog/EventLog.c
+++ b/rts/eventlog/EventLog.c
@@ -1100,20 +1100,22 @@ void postBlockMarker (EventsBuf *eb)
 
 void printAndClearEventBuf (EventsBuf *ebuf)
 {
-    StgWord64 numBytes = 0, written = 0;
-
     closeBlockMarker(ebuf);
 
     if (ebuf->begin != NULL && ebuf->pos != ebuf->begin)
     {
-        numBytes = ebuf->pos - ebuf->begin;
-
-        written = fwrite(ebuf->begin, 1, numBytes, event_log_file);
-        if (written != numBytes) {
-            debugBelch(
-                "printAndClearEventLog: fwrite() failed, written=%" FMT_Word64
-                " doesn't match numBytes=%" FMT_Word64, written, numBytes);
-            return;
+        StgInt8 *begin = ebuf->begin;
+        while (begin < ebuf->pos) {
+            StgWord64 remain = ebuf->pos - begin;
+            StgWord64 written = fwrite(begin, 1, remain, event_log_file);
+            if (written == 0) {
+                debugBelch(
+                    "printAndClearEventLog: fwrite() failed to write anything;"
+                    " tried to write numBytes=%" FMT_Word64, remain);
+                resetEventsBuf(ebuf);
+                return;
+            }
+            begin += written;
         }
 
         resetEventsBuf(ebuf);



More information about the ghc-commits mailing list