forked from OSchip/llvm-project
driver: handle write error better
We would previously simply assume that the write would always succeed. However, write(2) may return -1 for error as well as fail to perform a complete write (in which case the returned number of bytes will be less than the requested bytes). Explicitly check if an error condition is encountered. This would previously not be caught as we default initialized success to true. Add an assertion that we always perform a complete write (a continuous retry could be added to ensure that we finish writing completely). This was caught by GCC's signed comparison warning and manual inspection. llvm-svn: 217355
This commit is contained in:
parent
0971629764
commit
9e5b49831c
|
@ -931,7 +931,15 @@ Driver::MainLoop ()
|
||||||
#endif
|
#endif
|
||||||
if (err == 0)
|
if (err == 0)
|
||||||
{
|
{
|
||||||
if (write (fds[WRITE], commands_data, commands_size) == commands_size)
|
ssize_t nrwr = write(fds[WRITE], commands_data, commands_size);
|
||||||
|
if (nrwr < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "error: write(%i, %p, %zd) failed (errno = %i) "
|
||||||
|
"when trying to open LLDB commands pipe\n",
|
||||||
|
fds[WRITE], commands_data, commands_size, errno);
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
else if (static_cast<size_t>(nrwr) == commands_size)
|
||||||
{
|
{
|
||||||
// Close the write end of the pipe so when we give the read end to
|
// Close the write end of the pipe so when we give the read end to
|
||||||
// the debugger/command interpreter it will exit when it consumes all
|
// the debugger/command interpreter it will exit when it consumes all
|
||||||
|
@ -953,10 +961,18 @@ Driver::MainLoop ()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr, "error: fdopen(%i, \"r\") failed (errno = %i) when trying to open LLDB commands pipe\n", fds[READ], errno);
|
fprintf(stderr,
|
||||||
|
"error: fdopen(%i, \"r\") failed (errno = %i) when "
|
||||||
|
"trying to open LLDB commands pipe\n",
|
||||||
|
fds[READ], errno);
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
assert(!"partial writes not handled");
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue