mirror of
https://github.com/nodejs/node-v0.x-archive.git
synced 2026-04-28 03:01:10 -04:00
move global vars from platfrom, node_signal_watcher to struct
This commit is contained in:
@@ -82,6 +82,7 @@ static const int X509_NAME_FLAGS = ASN1_STRFLGS_ESC_CTRL
|
||||
#define version_symbol NODE_VAR(version_symbol)
|
||||
#define ext_key_usage_symbol NODE_VAR(ext_key_usage_symbol)
|
||||
#define secure_context_constructor NODE_VAR(secure_context_constructor)
|
||||
#define locks NODE_VAR(locks)
|
||||
|
||||
|
||||
namespace node {
|
||||
@@ -98,8 +99,6 @@ static unsigned long crypto_id_cb(void) {
|
||||
#endif /* !_WIN32 */
|
||||
}
|
||||
|
||||
static uv_rwlock_t* locks;
|
||||
|
||||
|
||||
static void crypto_lock_init(void) {
|
||||
int i, n;
|
||||
|
||||
@@ -22,26 +22,27 @@
|
||||
#include <node_signal_watcher.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <node_vars.h>
|
||||
#define callback_symbol NODE_VAR(callback_symbol)
|
||||
#define signal_watcher_constructor_template NODE_VAR(signal_watcher_constructor_template)
|
||||
|
||||
namespace node {
|
||||
|
||||
using namespace v8;
|
||||
|
||||
Persistent<FunctionTemplate> SignalWatcher::constructor_template;
|
||||
static Persistent<String> callback_symbol;
|
||||
|
||||
void SignalWatcher::Initialize(Handle<Object> target) {
|
||||
HandleScope scope;
|
||||
|
||||
Local<FunctionTemplate> t = FunctionTemplate::New(SignalWatcher::New);
|
||||
constructor_template = Persistent<FunctionTemplate>::New(t);
|
||||
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
constructor_template->SetClassName(String::NewSymbol("SignalWatcher"));
|
||||
signal_watcher_constructor_template = Persistent<FunctionTemplate>::New(t);
|
||||
signal_watcher_constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
signal_watcher_constructor_template->SetClassName(String::NewSymbol("SignalWatcher"));
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor_template, "start", SignalWatcher::Start);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor_template, "stop", SignalWatcher::Stop);
|
||||
NODE_SET_PROTOTYPE_METHOD(signal_watcher_constructor_template, "start", SignalWatcher::Start);
|
||||
NODE_SET_PROTOTYPE_METHOD(signal_watcher_constructor_template, "stop", SignalWatcher::Stop);
|
||||
|
||||
target->Set(String::NewSymbol("SignalWatcher"),
|
||||
constructor_template->GetFunction());
|
||||
signal_watcher_constructor_template->GetFunction());
|
||||
|
||||
callback_symbol = NODE_PSYMBOL("callback");
|
||||
}
|
||||
@@ -73,7 +74,7 @@ void SignalWatcher::Callback(EV_P_ ev_signal *watcher, int revents) {
|
||||
|
||||
Handle<Value> SignalWatcher::New(const Arguments& args) {
|
||||
if (!args.IsConstructCall()) {
|
||||
return FromConstructorTemplate(constructor_template, args);
|
||||
return FromConstructorTemplate(signal_watcher_constructor_template, args);
|
||||
}
|
||||
|
||||
HandleScope scope;
|
||||
|
||||
@@ -149,6 +149,7 @@ struct globals {
|
||||
v8::Persistent<v8::String> callback_sym;
|
||||
|
||||
// node_crypto.cc
|
||||
uv_rwlock_t* locks;
|
||||
v8::Persistent<v8::String> subject_symbol;
|
||||
v8::Persistent<v8::String> subjectaltname_symbol;
|
||||
v8::Persistent<v8::String> modulus_symbol;
|
||||
@@ -167,6 +168,17 @@ struct globals {
|
||||
v8::Persistent<v8::String> chars_written_sym;
|
||||
v8::Persistent<v8::String> write_sym;
|
||||
v8::Persistent<v8::FunctionTemplate> buffer_constructor_template;
|
||||
|
||||
// platform*.cc
|
||||
char* process_title;
|
||||
struct {
|
||||
char *str;
|
||||
size_t len;
|
||||
} linux_process_title;
|
||||
|
||||
// node_signal_watcher.cc
|
||||
v8::Persistent<v8::String> callback_symbol;
|
||||
v8::Persistent<v8::FunctionTemplate> signal_watcher_constructor_template;
|
||||
};
|
||||
|
||||
struct globals* globals_get();
|
||||
|
||||
@@ -39,13 +39,14 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <ifaddrs.h>
|
||||
|
||||
#include <node_vars.h>
|
||||
#define process_title NODE_VAR(process_title)
|
||||
|
||||
|
||||
namespace node {
|
||||
|
||||
using namespace v8;
|
||||
|
||||
static char *process_title;
|
||||
double Platform::prog_start_time = Platform::GetUptime();
|
||||
|
||||
char** Platform::SetupArgs(int argc, char *argv[]) {
|
||||
|
||||
@@ -37,12 +37,14 @@
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <node_vars.h>
|
||||
#define process_title NODE_VAR(process_title)
|
||||
|
||||
|
||||
namespace node {
|
||||
|
||||
using namespace v8;
|
||||
|
||||
static char *process_title;
|
||||
double Platform::prog_start_time = Platform::GetUptime();
|
||||
|
||||
char** Platform::SetupArgs(int argc, char *argv[]) {
|
||||
|
||||
@@ -48,20 +48,18 @@
|
||||
# include <sys/sysinfo.h>
|
||||
#endif
|
||||
|
||||
#include <node_vars.h>
|
||||
#define linux_process_title NODE_VAR(linux_process_title)
|
||||
#define getbuf NODE_VAR(getbuf)
|
||||
|
||||
extern char **environ;
|
||||
|
||||
namespace node {
|
||||
|
||||
using namespace v8;
|
||||
|
||||
static char buf[MAXPATHLEN + 1];
|
||||
double Platform::prog_start_time = Platform::GetUptime();
|
||||
|
||||
static struct {
|
||||
char *str;
|
||||
size_t len;
|
||||
} process_title;
|
||||
|
||||
|
||||
char** Platform::SetupArgs(int argc, char *argv[]) {
|
||||
char **new_argv;
|
||||
@@ -75,23 +73,23 @@ char** Platform::SetupArgs(int argc, char *argv[]) {
|
||||
|
||||
s = envc ? environ[envc - 1] : argv[argc - 1];
|
||||
|
||||
process_title.str = argv[0];
|
||||
process_title.len = s + strlen(s) + 1 - argv[0];
|
||||
linux_process_title.str = argv[0];
|
||||
linux_process_title.len = s + strlen(s) + 1 - argv[0];
|
||||
|
||||
size = process_title.len;
|
||||
size = linux_process_title.len;
|
||||
size += (argc + 1) * sizeof(char **);
|
||||
size += (envc + 1) * sizeof(char **);
|
||||
|
||||
if ((s = (char *) malloc(size)) == NULL) {
|
||||
process_title.str = NULL;
|
||||
process_title.len = 0;
|
||||
linux_process_title.str = NULL;
|
||||
linux_process_title.len = 0;
|
||||
return argv;
|
||||
}
|
||||
|
||||
new_argv = (char **) s;
|
||||
new_env = new_argv + argc + 1;
|
||||
s = (char *) (new_env + envc + 1);
|
||||
memcpy(s, process_title.str, process_title.len);
|
||||
memcpy(s, linux_process_title.str, linux_process_title.len);
|
||||
|
||||
for (i = 0; i < argc; i++)
|
||||
new_argv[i] = s + (argv[i] - argv[0]);
|
||||
@@ -110,15 +108,15 @@ char** Platform::SetupArgs(int argc, char *argv[]) {
|
||||
|
||||
void Platform::SetProcessTitle(char *title) {
|
||||
/* No need to terminate, last char is always '\0'. */
|
||||
if (process_title.len)
|
||||
strncpy(process_title.str, title, process_title.len - 1);
|
||||
if (linux_process_title.len)
|
||||
strncpy(linux_process_title.str, title, linux_process_title.len - 1);
|
||||
}
|
||||
|
||||
|
||||
const char* Platform::GetProcessTitle(int *len) {
|
||||
if (process_title.str) {
|
||||
*len = strlen(process_title.str);
|
||||
return process_title.str;
|
||||
if (linux_process_title.str) {
|
||||
*len = strlen(linux_process_title.str);
|
||||
return linux_process_title.str;
|
||||
}
|
||||
else {
|
||||
*len = 0;
|
||||
@@ -140,7 +138,7 @@ int Platform::GetMemory(size_t *rss) {
|
||||
/* PID */
|
||||
if (fscanf(f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */
|
||||
/* Exec file */
|
||||
cbuf = buf;
|
||||
cbuf = getbuf;
|
||||
foundExeEnd = false;
|
||||
if (fscanf (f, "%c", cbuf++) == 0) goto error; // (
|
||||
while (1) {
|
||||
|
||||
@@ -35,11 +35,13 @@
|
||||
#include <platform_win32.h>
|
||||
#include <psapi.h>
|
||||
|
||||
#include <node_vars.h>
|
||||
#define process_title NODE_VAR(process_title)
|
||||
|
||||
namespace node {
|
||||
|
||||
using namespace v8;
|
||||
|
||||
static char *process_title = NULL;
|
||||
double Platform::prog_start_time = Platform::GetUptime();
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user