diff options
author | legendecas <legendecas@gmail.com> | 2021-05-11 18:38:49 +0300 |
---|---|---|
committer | Danielle Adams <adamzdanielle@gmail.com> | 2021-05-31 22:34:49 +0300 |
commit | 61c95f08b37d16ab24ac684faeb917223a1c2634 (patch) | |
tree | 0fe10138a3c225eb194b95736991157fa07d247e /src | |
parent | ba96f142336b886bb1840f109955bc967fea3e51 (diff) |
src: write named pipe info in diagnostic report
Writes pipe handles with `uv_pipe_getsockname()`
and `uv_pipe_getpeername()`.
PR-URL: https://github.com/nodejs/node/pull/38637
Fixes: https://github.com/nodejs/node/issues/38625
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/node_report_utils.cc | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/node_report_utils.cc b/src/node_report_utils.cc index abbf6d529d0..82ed385ad17 100644 --- a/src/node_report_utils.cc +++ b/src/node_report_utils.cc @@ -82,6 +82,42 @@ static void ReportEndpoints(uv_handle_t* h, JSONWriter* writer) { ReportEndpoint(h, rc == 0 ? addr : nullptr, "remoteEndpoint", writer); } +// Utility function to format libuv pipe information. +static void ReportPipeEndpoints(uv_handle_t* h, JSONWriter* writer) { + uv_any_handle* handle = reinterpret_cast<uv_any_handle*>(h); + MallocedBuffer<char> buffer(0); + size_t buffer_size = 0; + int rc = -1; + + // First call to get required buffer size. + rc = uv_pipe_getsockname(&handle->pipe, buffer.data, &buffer_size); + if (rc == UV_ENOBUFS) { + buffer = MallocedBuffer<char>(buffer_size); + if (buffer.data != nullptr) { + rc = uv_pipe_getsockname(&handle->pipe, buffer.data, &buffer_size); + } + } + if (rc == 0 && buffer_size != 0 && buffer.data != nullptr) { + writer->json_keyvalue("localEndpoint", buffer.data); + } else { + writer->json_keyvalue("localEndpoint", null); + } + + // First call to get required buffer size. + rc = uv_pipe_getpeername(&handle->pipe, buffer.data, &buffer_size); + if (rc == UV_ENOBUFS) { + buffer = MallocedBuffer<char>(buffer_size); + if (buffer.data != nullptr) { + rc = uv_pipe_getpeername(&handle->pipe, buffer.data, &buffer_size); + } + } + if (rc == 0 && buffer_size != 0 && buffer.data != nullptr) { + writer->json_keyvalue("remoteEndpoint", buffer.data); + } else { + writer->json_keyvalue("remoteEndpoint", null); + } +} + // Utility function to format libuv path information. static void ReportPath(uv_handle_t* h, JSONWriter* writer) { MallocedBuffer<char> buffer(0); @@ -147,6 +183,9 @@ void WalkHandle(uv_handle_t* h, void* arg) { case UV_UDP: ReportEndpoints(h, writer); break; + case UV_NAMED_PIPE: + ReportPipeEndpoints(h, writer); + break; case UV_TIMER: { uint64_t due = handle->timer.timeout; uint64_t now = uv_now(handle->timer.loop); |