summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/env.cc9
-rw-r--r--src/inspector_agent.cc7
-rw-r--r--src/node.cc13
-rw-r--r--src/node_internals.h1
-rw-r--r--src/util.cc16
5 files changed, 27 insertions, 19 deletions
diff --git a/src/env.cc b/src/env.cc
index d4ca34aa74..425333ed7a 100644
--- a/src/env.cc
+++ b/src/env.cc
@@ -4,12 +4,6 @@
#include "node_buffer.h"
#include "node_platform.h"
-#if defined(_MSC_VER)
-#define getpid GetCurrentProcessId
-#else
-#include <unistd.h>
-#endif
-
#include <stdio.h>
#include <algorithm>
@@ -184,7 +178,8 @@ void Environment::PrintSyncTrace() const {
Local<v8::StackTrace> stack =
StackTrace::CurrentStackTrace(isolate(), 10, StackTrace::kDetailed);
- fprintf(stderr, "(node:%d) WARNING: Detected use of sync API\n", getpid());
+ fprintf(stderr, "(node:%u) WARNING: Detected use of sync API\n",
+ GetProcessId());
for (int i = 0; i < stack->GetFrameCount() - 1; i++) {
Local<StackFrame> stack_frame = stack->GetFrame(i);
diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc
index 215e91873a..798b80df86 100644
--- a/src/inspector_agent.cc
+++ b/src/inspector_agent.cc
@@ -13,8 +13,8 @@
#include <vector>
#ifdef __POSIX__
-#include <limits.h>
-#include <unistd.h> // setuid, getuid
+#include <limits.h> // PTHREAD_STACK_MIN
+#include <pthread.h>
#endif // __POSIX__
namespace node {
@@ -108,7 +108,8 @@ static int StartDebugSignalHandler() {
CHECK_EQ(0, pthread_sigmask(SIG_SETMASK, &sigmask, nullptr));
CHECK_EQ(0, pthread_attr_destroy(&attr));
if (err != 0) {
- fprintf(stderr, "node[%d]: pthread_create: %s\n", getpid(), strerror(err));
+ fprintf(stderr, "node[%u]: pthread_create: %s\n",
+ GetProcessId(), strerror(err));
fflush(stderr);
// Leave SIGUSR1 blocked. We don't install a signal handler,
// receiving the signal would terminate the process.
diff --git a/src/node.cc b/src/node.cc
index 573c74a37e..0bd9a44658 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -99,7 +99,6 @@
#if defined(_MSC_VER)
#include <direct.h>
#include <io.h>
-#define getpid GetCurrentProcessId
#define umask _umask
typedef int mode_t;
#else
@@ -1659,13 +1658,8 @@ NO_RETURN void Assert(const char* const (*args)[4]) {
if (uv_exepath(exepath, &exepath_size))
snprintf(exepath, sizeof(exepath), "node");
- char pid[12] = {0};
-#ifndef _WIN32
- snprintf(pid, sizeof(pid), "[%u]", getpid());
-#endif
-
- fprintf(stderr, "%s%s: %s:%s:%s%s Assertion `%s' failed.\n",
- exepath, pid, filename, linenum,
+ fprintf(stderr, "%s[%u]: %s:%s:%s%s Assertion `%s' failed.\n",
+ exepath, GetProcessId(), filename, linenum,
function, *function ? ":" : "", message);
fflush(stderr);
@@ -3197,7 +3191,8 @@ void SetupProcessObject(Environment* env,
process_env_template->NewInstance(env->context()).ToLocalChecked();
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "env"), process_env);
- READONLY_PROPERTY(process, "pid", Integer::New(env->isolate(), getpid()));
+ READONLY_PROPERTY(process, "pid",
+ Integer::New(env->isolate(), GetProcessId()));
READONLY_PROPERTY(process, "features", GetFeatures(env));
CHECK(process->SetAccessor(env->context(),
diff --git a/src/node_internals.h b/src/node_internals.h
index b67a69b989..7c4a0d9fa2 100644
--- a/src/node_internals.h
+++ b/src/node_internals.h
@@ -248,6 +248,7 @@ void RegisterSignalHandler(int signal,
bool reset_handler = false);
#endif
+uint32_t GetProcessId();
bool SafeGetenv(const char* key, std::string* text);
template <typename T, size_t N>
diff --git a/src/util.cc b/src/util.cc
index ef93d16968..0fb897bc8e 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -24,6 +24,14 @@
#include "node_internals.h"
#include <stdio.h>
+#ifdef __POSIX__
+#include <unistd.h> // getpid()
+#endif
+
+#ifdef _MSC_VER
+#include <windows.h> // GetCurrentProcessId()
+#endif
+
namespace node {
using v8::Isolate;
@@ -105,4 +113,12 @@ void LowMemoryNotification() {
}
}
+uint32_t GetProcessId() {
+#ifdef _WIN32
+ return GetCurrentProcessId();
+#else
+ return getpid();
+#endif
+}
+
} // namespace node