Repository navigation
Expand file tree
/
Copy pathnode_zos.cc
More file actions
179 lines (153 loc) Β· 5.51 KB
/
Copy pathnode_zos.cc
File metadata and controls
179 lines (153 loc) Β· 5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "node_zos.h"
#include "env-inl.h"
#include "node_internals.h"
#include "node_watchdog.h"
#include <pthread.h>
#include <signal.h>
#include <sys/msg.h>
#ifndef NJS_PRODUCT_OWNER
#error "NJS_PRODUCT_OWNER must be defined"
#endif
#ifndef NJS_FEATURE_NAME
#error "NJS_FEATURE_NAME must be defined"
#endif
#ifndef NJS_PRODUCT_NAME
#error "NJS_PRODUCT_NAME must be defined"
#endif
#ifndef NJS_PID
#error "NJS_PID must be defined"
#endif
namespace {
uv_thread_t signalHandlerThread;
char* galtStack = nullptr;
void __zosAtExit() {
if (galtStack != nullptr) {
free(galtStack);
galtStack = nullptr;
}
}
} // namespace
namespace node {
void zosDestroyThread() {
uv_queue_work(nullptr, nullptr, nullptr, nullptr);
SigintWatchdogHelper::GetInstance()->Stop();
msgctl(uv_backend_fd(uv_default_loop()), IPC_RMID, nullptr);
// Tell zoslib that main process is terminating, for its diagnostics:
__mainTerminating();
}
static void SignalHandlerThread(void* data) {
while (1) {
CHECK_EQ(pause(), -1);
CHECK_EQ(errno, EINTR);
}
}
void zosCreateSignalHandler() {
uv_thread_create(&signalHandlerThread, SignalHandlerThread, nullptr);
// Block all signals on the main thread
sigset_t set;
sigfillset(&set);
CHECK_EQ(0, pthread_sigmask(SIG_BLOCK, &set, nullptr));
}
void zosCancelSignalHandler() {
if (pthread_cancel(signalHandlerThread) == -1) abort();
}
void zosSignalExit(int signo, siginfo_t* info, void* ucontext) {
zosDestroyThread();
// Use alternate stack in case LE uses main thread's sp upon termination.
struct sigaction new_action;
new_action.sa_flags = SA_ONSTACK;
new_action.sa_handler = SIG_DFL;
sigaction(signo, &new_action, nullptr);
if (signo == SIGABRT)
abort(); // from zoslib
else
raise(signo);
}
void zosIgnorePipeChildSignals() {
struct sigaction new_action;
new_action.sa_handler = SIG_IGN;
sigfillset(&new_action.sa_mask);
sigaction(SIGPIPE, &new_action, nullptr);
new_action.sa_handler = SIG_IGN;
sigfillset(&new_action.sa_mask);
sigaction(SIGCHLD, &new_action, nullptr);
}
static void RegisterProduct() {
std::string major_version = std::to_string(NODE_MAJOR_VERSION);
std::string product_owner = NJS_PRODUCT_OWNER;
std::string feature_name = NJS_FEATURE_NAME;
std::string product_name = NJS_PRODUCT_NAME;
std::string pid = NJS_PID;
std::string val;
if (credentials::SafeGetenv("NODE_SMF89_REGISTRATION_VERBOSE", &val))
printf("Product registration data:\n"
"Product Name: %s\n"
"PID Name: %s\n"
"Major Version: %s\n"
"Product Owner: %s\n"
"Feature Name: %s\n",
product_name.c_str(),
pid.c_str(),
major_version.c_str(),
product_owner.c_str(),
feature_name.c_str());
uint64_t rc = __registerProduct(major_version.c_str(),
product_owner.c_str(),
feature_name.c_str(),
product_name.c_str(),
pid.c_str());
if (rc && !credentials::SafeGetenv("NODE_SMF89_SUPPRESS_WARNING", &val)) {
fprintf(stderr,
"WARNING: Could not register product with IFAUSAGE, "
"rc = %lu\n",
rc);
if (const char* errorString = getIFAUsageErrorString(rc))
fprintf(stderr, "%s\n", errorString);
fprintf(stderr,
"WARNING: Product usage data may not be collected. For more "
"details on the product registration data, set environment "
"variable NODE_SMF89_REGISTRATION_VERBOSE=1. To suppress this "
"warning message set the environment variable "
"NODE_SMF89_SUPPRESS_WARNING=1.\n");
}
}
ExitCode zosStart() {
// Initialize environment variables in zoslib:
zoslib_config_t config{
.RUNTIME_LIMIT_ENVAR = "__NODERUNTIMELIMIT",
.CCSID_GUESS_BUF_SIZE_ENVAR = "__NODECCSIDGUESSBUFSIZE"};
if (__update_envar_names(&config) != 0) {
return ExitCode::kGenericUserError;
}
// Create an alternate stack for signal processing
const unsigned int STACK_SIZE = SIGSTKSZ + 1024 * 1024;
galtStack = reinterpret_cast<char*>(malloc(STACK_SIZE));
if (galtStack == nullptr) {
return ExitCode::kGenericUserError;
}
stack_t ss = {.ss_sp = galtStack, .ss_size = STACK_SIZE, .ss_flags = 0};
sigaltstack(&ss, 0);
if (__doLogMemoryUsage()) atexit(__zosAtExit);
return ExitCode::kNoFailure;
}
} // namespace node