Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

report: add cwd to report #27022

Merged
merged 1 commit into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/api/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ is provided below for reference.
"dumpEventTime": "2018-12-21T00:50:11Z",
"dumpEventTimeStamp": "1545371411331",
"processId": 8974,
"cwd": "/home/nodeuser/project/node",
"commandLine": [
"/home/nodeuser/project/node/out/Release/node",
"--experimental-report",
Expand Down
16 changes: 16 additions & 0 deletions src/node_report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
#include <atomic>
#include <fstream>
#include <iomanip>
#include <climits> // PATH_MAX

#ifdef _WIN32
/* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */
#define PATH_MAX_BYTES (MAX_PATH * 4)
#else
#define PATH_MAX_BYTES (PATH_MAX)
#endif

#ifndef _WIN32
extern char** environ;
Expand Down Expand Up @@ -213,6 +221,14 @@ static void WriteNodeReport(Isolate* isolate,
// Report native process ID
writer.json_keyvalue("processId", pid);

{
// Report the process cwd.
char buf[PATH_MAX_BYTES];
size_t cwd_size = sizeof(buf);
if (uv_cwd(buf, &cwd_size) == 0)
writer.json_keyvalue("cwd", buf);
}

// Report out the command line.
if (!node::per_process::cli_options->cmdline.empty()) {
writer.json_arraystart("commandLine");
Expand Down
3 changes: 2 additions & 1 deletion test/common/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function _validateContent(data) {
'nodejsVersion', 'wordSize', 'arch', 'platform',
'componentVersions', 'release', 'osName', 'osRelease',
'osVersion', 'osMachine', 'host', 'glibcVersionRuntime',
'glibcVersionCompiler'];
'glibcVersionCompiler', 'cwd'];
checkForUnknownFields(header, headerFields);
assert.strictEqual(typeof header.event, 'string');
assert.strictEqual(typeof header.trigger, 'string');
Expand All @@ -76,6 +76,7 @@ function _validateContent(data) {
assert(String(+header.dumpEventTimeStamp), header.dumpEventTimeStamp);

assert(Number.isSafeInteger(header.processId));
assert.strictEqual(typeof header.cwd, 'string');
assert(Array.isArray(header.commandLine));
header.commandLine.forEach((arg) => {
assert.strictEqual(typeof arg, 'string');
Expand Down