[llvm-commits] [llvm] r103085 - /llvm/trunk/lib/Support/raw_ostream.cpp

Chandler Carruth chandlerc at google.com
Wed May 5 12:12:42 PDT 2010


On Wed, May 5, 2010 at 10:55 AM, Dan Gohman <gohman at apple.com> wrote:

>
> On May 5, 2010, at 8:17 AM, Benjamin Kramer wrote:
>
> > Author: d0k
> > Date: Wed May  5 10:17:47 2010
> > New Revision: 103085
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=103085&view=rev
> > Log:
> > Try again if write(2) reports an recoverable error.
> >
> > This should fix mysteriously crashing boost regression tests when stderr
> is
> > managed by bjam (PR7043).
> >
> > Modified:
> >    llvm/trunk/lib/Support/raw_ostream.cpp
> >
> > Modified: llvm/trunk/lib/Support/raw_ostream.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/raw_ostream.cpp?rev=103085&r1=103084&r2=103085&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/lib/Support/raw_ostream.cpp (original)
> > +++ llvm/trunk/lib/Support/raw_ostream.cpp Wed May  5 10:17:47 2010
> > @@ -21,6 +21,7 @@
> > #include "llvm/Support/ErrorHandling.h"
> > #include "llvm/ADT/STLExtras.h"
> > #include <cctype>
> > +#include <cerrno>
> > #include <sys/stat.h>
> > #include <sys/types.h>
> >
> > @@ -420,7 +421,11 @@
> > void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) {
> >   assert(FD >= 0 && "File already closed.");
> >   pos += Size;
> > -  if (::write(FD, Ptr, Size) != (ssize_t) Size)
> > +  ssize_t ret;
> > +  do {
> > +    ret = ::write(FD, Ptr, Size);
> > +  } while (ret < 0 && (errno == EAGAIN || errno == EINTR));
>
> Is EAGAIN really a recoverable error? According to the documentation I
> have, EAGAIN is only used for non-blocking I/O (O_NONBLOCK), so
> immediately retrying the write in that case is likely to send the process
> into a spin. raw_ostream isn't really designed to be used with non-blocking
> I/O, so it seems better to just fail.
>

It seems plausible that a shell or other process attaches a non-blocking
file descriptor to stderr, so spinning (with some amount of yielding) seems
reasonable in the face of EAGAIN.


> EINTR is recoverable, but it's not the only way that write can fail
> when interrupted.  Another possibility is that the write could be
> interrupted
> after some bytes have already been written, in which case it'll return
> a positive value less than Size to indicate the number of bytes written.
>
> Dan
>
> > +  if (ret != (ssize_t) Size)
> >     error_detected();
> > }
> >
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20100505/1253c4d2/attachment.html>


More information about the llvm-commits mailing list