From 4c9c1bbc45eb9dafcbb0080e2fbc061ade3d55ad Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 17 Jul 2018 23:51:09 +0200 Subject: [PATCH] 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 Reviewed-By: Eugene Ostroukhov Reviewed-By: Ali Ijaz Sheikh --- src/tracing/node_trace_writer.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/tracing/node_trace_writer.cc b/src/tracing/node_trace_writer.cc index a2f7bebfc72f9a..5e3ddc633f153f 100644 --- a/src/tracing/node_trace_writer.cc +++ b/src/tracing/node_trace_writer.cc @@ -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;