Skip to content

Commit

Permalink
src: use uv_os_getpid() to get process id
Browse files Browse the repository at this point in the history
This commit uses the new uv_os_getpid() method to retrieve the
current process id.

PR-URL: #17415
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Khaidi Chu <i@2333.moe>
  • Loading branch information
cjihrig committed Dec 4, 2017
1 parent f299922 commit a803bca
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void Environment::PrintSyncTrace() const {
StackTrace::CurrentStackTrace(isolate(), 10, StackTrace::kDetailed);

fprintf(stderr, "(node:%u) WARNING: Detected use of sync API\n",
GetProcessId());
uv_os_getpid());

for (int i = 0; i < stack->GetFrameCount() - 1; i++) {
Local<StackFrame> stack_frame = stack->GetFrame(i);
Expand Down
5 changes: 2 additions & 3 deletions src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static int StartDebugSignalHandler() {
CHECK_EQ(0, pthread_attr_destroy(&attr));
if (err != 0) {
fprintf(stderr, "node[%u]: pthread_create: %s\n",
GetProcessId(), strerror(err));
uv_os_getpid(), strerror(err));
fflush(stderr);
// Leave SIGUSR1 blocked. We don't install a signal handler,
// receiving the signal would terminate the process.
Expand Down Expand Up @@ -144,7 +144,7 @@ static int StartDebugSignalHandler() {
DWORD pid;
LPTHREAD_START_ROUTINE* handler;

pid = GetCurrentProcessId();
pid = uv_os_getpid();

if (GetDebugSignalHandlerMappingName(pid,
mapping_name,
Expand Down Expand Up @@ -692,4 +692,3 @@ bool Agent::IsWaitingForConnect() {

} // namespace inspector
} // namespace node

2 changes: 1 addition & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3105,7 +3105,7 @@ void SetupProcessObject(Environment* env,
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "env"), process_env);

READONLY_PROPERTY(process, "pid",
Integer::New(env->isolate(), GetProcessId()));
Integer::New(env->isolate(), uv_os_getpid()));
READONLY_PROPERTY(process, "features", GetFeatures(env));

CHECK(process->SetAccessor(env->context(),
Expand Down
1 change: 0 additions & 1 deletion src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ void RegisterSignalHandler(int signal,
bool reset_handler = false);
#endif

uint32_t GetProcessId();
bool SafeGetenv(const char* key, std::string* text);

std::string GetHumanReadableProcessName();
Expand Down
19 changes: 2 additions & 17 deletions src/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,9 @@
#include "string_bytes.h"
#include "node_buffer.h"
#include "node_internals.h"
#include "uv.h"
#include <stdio.h>

#ifdef __POSIX__
#include <unistd.h> // getpid()
#endif

#ifdef _MSC_VER
#include <windows.h> // GetCurrentProcessId()
#endif

namespace node {

using v8::Isolate;
Expand Down Expand Up @@ -122,15 +115,7 @@ std::string GetHumanReadableProcessName() {
void GetHumanReadableProcessName(char (*name)[1024]) {
char title[1024] = "Node.js";
uv_get_process_title(title, sizeof(title));
snprintf(*name, sizeof(*name), "%s[%u]", title, GetProcessId());
}

uint32_t GetProcessId() {
#ifdef _WIN32
return GetCurrentProcessId();
#else
return getpid();
#endif
snprintf(*name, sizeof(*name), "%s[%u]", title, uv_os_getpid());
}

} // namespace node

0 comments on commit a803bca

Please sign in to comment.