From 77955d76772eea871f238e4c4cb4da9a3896db43 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 3 Sep 2014 09:51:34 -0500 Subject: [PATCH] Fix possible abort on writing to a full pipe. --- src/Flare.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Flare.cc b/src/Flare.cc index 8a0418f631..960e66cbf4 100644 --- a/src/Flare.cc +++ b/src/Flare.cc @@ -1,7 +1,6 @@ // See the file "COPYING" in the main distribution directory for copyright. #include "Flare.h" -#include "util.h" #include #include #include @@ -16,7 +15,21 @@ Flare::Flare() void Flare::Fire() { char tmp; - safe_write(pipe.WriteFD(), &tmp, 1); + + for ( ; ; ) + { + int n = write(pipe.WriteFD(), &tmp, 1); + + if ( n > 0 ) + // Success -- wrote a byte to pipe. + break; + + if ( n < 0 && errno == EAGAIN ) + // Success -- pipe is full and just need at least one byte in it. + break; + + // Loop because either the byte wasn't written or got EINTR error. + } } void Flare::Extinguish() @@ -25,5 +38,6 @@ void Flare::Extinguish() for ( ; ; ) if ( read(pipe.ReadFD(), &tmp, sizeof(tmp)) == -1 && errno == EAGAIN ) + // Pipe is now drained. break; }