Skip to content

Commit

Permalink
Use write_all in case writes to stderr/stdout are only partially su…
Browse files Browse the repository at this point in the history
…ccessful
  • Loading branch information
rocallahan committed Aug 13, 2024
1 parent d1224b4 commit bdde224
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/StdioMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
#include "ReplayTask.h"
#include "Session.h"
#include "log.h"
#include "util.h"

namespace rr {

Switchable StdioMonitor::will_write(Task* t) {
if (t->session().mark_stdio()) {
char buf[256];
snprintf(buf, sizeof(buf) - 1, "[rr %d %" PRId64 "]", t->tgid(), t->trace_time());
ssize_t len = strlen(buf);
if (write(original_fd, buf, len) != len) {
ASSERT(t, false) << "Couldn't write to " << original_fd;
}
write_all(original_fd, buf, strlen(buf));
}

return PREVENT_SWITCH;
Expand All @@ -31,10 +29,7 @@ void StdioMonitor::did_write(Task* t, const std::vector<Range>& ranges,
}
for (auto& r : ranges) {
auto bytes = t->read_mem(r.data.cast<uint8_t>(), r.length);
if (bytes.size() !=
(size_t)write(original_fd, bytes.data(), bytes.size())) {
ASSERT(t, false) << "Couldn't write to " << original_fd;
}
write_all(original_fd, bytes.data(), bytes.size());
}
}

Expand Down

0 comments on commit bdde224

Please sign in to comment.