Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7ecec67

Browse filesBrowse files
bnoordhuisMylesBorins
authored andcommitted
src: abstract getpid() operation
There are a few places where we paper over the fact that getpid() is called GetCurrentProcessId() on Windows. Let's move it into a function. PR-URL: #17087 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
1 parent 4c23e6a commit 7ecec67
Copy full SHA for 7ecec67

File tree

Expand file treeCollapse file tree

5 files changed

+27
-19
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+27
-19
lines changed
Open diff view settings
Collapse file

‎src/env.cc‎

Copy file name to clipboardExpand all lines: src/env.cc
+2-7Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
#include "async_wrap.h"
33
#include "v8-profiler.h"
44

5-
#if defined(_MSC_VER)
6-
#define getpid GetCurrentProcessId
7-
#else
8-
#include <unistd.h>
9-
#endif
10-
115
#include <stdio.h>
126
#include <algorithm>
137

@@ -182,7 +176,8 @@ void Environment::PrintSyncTrace() const {
182176
Local<v8::StackTrace> stack =
183177
StackTrace::CurrentStackTrace(isolate(), 10, StackTrace::kDetailed);
184178

185-
fprintf(stderr, "(node:%d) WARNING: Detected use of sync API\n", getpid());
179+
fprintf(stderr, "(node:%u) WARNING: Detected use of sync API\n",
180+
GetProcessId());
186181

187182
for (int i = 0; i < stack->GetFrameCount() - 1; i++) {
188183
Local<StackFrame> stack_frame = stack->GetFrame(i);
Collapse file

‎src/inspector_agent.cc‎

Copy file name to clipboardExpand all lines: src/inspector_agent.cc
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#include <vector>
1414

1515
#ifdef __POSIX__
16-
#include <limits.h>
17-
#include <unistd.h> // setuid, getuid
16+
#include <limits.h> // PTHREAD_STACK_MIN
17+
#include <pthread.h>
1818
#endif // __POSIX__
1919

2020
namespace node {
@@ -108,7 +108,8 @@ static int StartDebugSignalHandler() {
108108
CHECK_EQ(0, pthread_sigmask(SIG_SETMASK, &sigmask, nullptr));
109109
CHECK_EQ(0, pthread_attr_destroy(&attr));
110110
if (err != 0) {
111-
fprintf(stderr, "node[%d]: pthread_create: %s\n", getpid(), strerror(err));
111+
fprintf(stderr, "node[%u]: pthread_create: %s\n",
112+
GetProcessId(), strerror(err));
112113
fflush(stderr);
113114
// Leave SIGUSR1 blocked. We don't install a signal handler,
114115
// receiving the signal would terminate the process.
Collapse file

‎src/node.cc‎

Copy file name to clipboardExpand all lines: src/node.cc
+4-9Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@
9999
#if defined(_MSC_VER)
100100
#include <direct.h>
101101
#include <io.h>
102-
#define getpid GetCurrentProcessId
103102
#define umask _umask
104103
typedef int mode_t;
105104
#else
@@ -1995,13 +1994,8 @@ NO_RETURN void Assert(const char* const (*args)[4]) {
19951994
if (uv_exepath(exepath, &exepath_size))
19961995
snprintf(exepath, sizeof(exepath), "node");
19971996

1998-
char pid[12] = {0};
1999-
#ifndef _WIN32
2000-
snprintf(pid, sizeof(pid), "[%u]", getpid());
2001-
#endif
2002-
2003-
fprintf(stderr, "%s%s: %s:%s:%s%s Assertion `%s' failed.\n",
2004-
exepath, pid, filename, linenum,
1997+
fprintf(stderr, "%s[%u]: %s:%s:%s%s Assertion `%s' failed.\n",
1998+
exepath, GetProcessId(), filename, linenum,
20051999
function, *function ? ":" : "", message);
20062000
fflush(stderr);
20072001

@@ -3532,7 +3526,8 @@ void SetupProcessObject(Environment* env,
35323526
process_env_template->NewInstance(env->context()).ToLocalChecked();
35333527
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "env"), process_env);
35343528

3535-
READONLY_PROPERTY(process, "pid", Integer::New(env->isolate(), getpid()));
3529+
READONLY_PROPERTY(process, "pid",
3530+
Integer::New(env->isolate(), GetProcessId()));
35363531
READONLY_PROPERTY(process, "features", GetFeatures(env));
35373532

35383533
CHECK(process->SetAccessor(env->context(),
Collapse file

‎src/node_internals.h‎

Copy file name to clipboardExpand all lines: src/node_internals.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ void RegisterSignalHandler(int signal,
166166
bool reset_handler = false);
167167
#endif
168168

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

171172
template <typename T, size_t N>
Collapse file

‎src/util.cc‎

Copy file name to clipboardExpand all lines: src/util.cc
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424
#include "node_internals.h"
2525
#include <stdio.h>
2626

27+
#ifdef __POSIX__
28+
#include <unistd.h> // getpid()
29+
#endif
30+
31+
#ifdef _MSC_VER
32+
#include <windows.h> // GetCurrentProcessId()
33+
#endif
34+
2735
namespace node {
2836

2937
using v8::Isolate;
@@ -105,4 +113,12 @@ void LowMemoryNotification() {
105113
}
106114
}
107115

116+
uint32_t GetProcessId() {
117+
#ifdef _WIN32
118+
return GetCurrentProcessId();
119+
#else
120+
return getpid();
121+
#endif
122+
}
123+
108124
} // namespace node

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.