Skip to content

Commit

Permalink
src: fix tracing if cwd or file path is inaccessible
Browse files Browse the repository at this point in the history
Otherwise this would have crashed the process.
In particular, checking the return value of an libuv call against `-1`
was invalid to begin with, as libuv uses it to propagate the
error code.

PR-URL: #21867
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
  • Loading branch information
addaleax authored and targos committed Aug 1, 2018
1 parent c101b39 commit 4c9c1bb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/tracing/node_trace_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,13 @@ void NodeTraceWriter::OpenNewFileForStreaming() {

fd_ = uv_fs_open(tracing_loop_, &req, filepath.c_str(),
O_CREAT | O_WRONLY | O_TRUNC, 0644, nullptr);
CHECK_NE(fd_, -1);
uv_fs_req_cleanup(&req);
if (fd_ < 0) {
fprintf(stderr, "Could not open trace file %s: %s\n",
filepath.c_str(),
uv_strerror(fd_));
fd_ = -1;
}
}

void NodeTraceWriter::AppendTraceEvent(TraceObject* trace_event) {
Expand Down Expand Up @@ -145,6 +150,7 @@ void NodeTraceWriter::Flush(bool blocking) {
}

void NodeTraceWriter::WriteToFile(std::string&& str, int highest_request_id) {
if (fd_ == -1) return;
WriteRequest* write_req = new WriteRequest();
write_req->str = std::move(str);
write_req->writer = this;
Expand Down

0 comments on commit 4c9c1bb

Please sign in to comment.