From d47cb9ab63b44058edc682f6e78b2de9ddb8ca4c Mon Sep 17 00:00:00 2001 From: cjihrig Date: Fri, 1 Dec 2017 09:57:07 -0500 Subject: [PATCH] src: use uv_os_getpid() to get process id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit uses the new uv_os_getpid() method to retrieve the current process id. PR-URL: https://github.com/nodejs/node/pull/17415 Reviewed-By: Ben Noordhuis Reviewed-By: Richard Lau Reviewed-By: Anna Henningsen Reviewed-By: Refael Ackermann Reviewed-By: Tobias Nießen Reviewed-By: Jon Moss Reviewed-By: Khaidi Chu --- src/env.cc | 2 +- src/inspector_agent.cc | 5 ++--- src/node.cc | 2 +- src/node_internals.h | 1 - src/util.cc | 19 ++----------------- 5 files changed, 6 insertions(+), 23 deletions(-) diff --git a/src/env.cc b/src/env.cc index 3212dcc46cd4d0..8c3b43d2102cb1 100644 --- a/src/env.cc +++ b/src/env.cc @@ -119,7 +119,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 stack_frame = stack->GetFrame(i); diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index be943ea5bebe0c..c1b574ac2e86de 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc @@ -110,7 +110,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. @@ -145,7 +145,7 @@ static int StartDebugSignalHandler() { DWORD pid; LPTHREAD_START_ROUTINE* handler; - pid = GetCurrentProcessId(); + pid = uv_os_getpid(); if (GetDebugSignalHandlerMappingName(pid, mapping_name, @@ -694,4 +694,3 @@ bool Agent::IsWaitingForConnect() { } // namespace inspector } // namespace node - diff --git a/src/node.cc b/src/node.cc index 49657b0deedd11..d17752bbad38f5 100644 --- a/src/node.cc +++ b/src/node.cc @@ -3492,7 +3492,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)); process->SetAccessor(FIXED_ONE_BYTE_STRING(env->isolate(), "ppid"), diff --git a/src/node_internals.h b/src/node_internals.h index 53c1ea7501d732..8f3fb4fb9aa27d 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -225,7 +225,6 @@ void RegisterSignalHandler(int signal, bool reset_handler = false); #endif -uint32_t GetProcessId(); bool SafeGetenv(const char* key, std::string* text); std::string GetHumanReadableProcessName(); diff --git a/src/util.cc b/src/util.cc index 2aa9fb026ea315..77824acb03a610 100644 --- a/src/util.cc +++ b/src/util.cc @@ -22,16 +22,9 @@ #include "string_bytes.h" #include "node_buffer.h" #include "node_internals.h" +#include "uv.h" #include -#ifdef __POSIX__ -#include // getpid() -#endif - -#ifdef _MSC_VER -#include // GetCurrentProcessId() -#endif - namespace node { using v8::Isolate; @@ -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