src: fix tracing if cwd or file path is inaccessible

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: https://github.com/nodejs/node/pull/21867
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
This commit is contained in:
Anna Henningsen authored and Michaël Zasso committed 2018-08-01 21:35:15 +02:00
1 parent c101b396aa
commit 4c9c1bbc45
1 file changed
+7 -1
+7 -1
View File
@@ -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) {
@@ -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;