diff --git a/doc/api.markdown b/doc/api.markdown index 162321e61b..677af4f90d 100644 --- a/doc/api.markdown +++ b/doc/api.markdown @@ -750,6 +750,10 @@ The PID of the process. console.log('This process is pid ' + process.pid); +### process.title + +Getter/setter to set what is displayed in 'ps'. + ### process.platform diff --git a/src/node.cc b/src/node.cc index e72c8dfb9b..72dc481bc0 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1506,6 +1506,24 @@ static Handle Binding(const Arguments& args) { } +static Handle ProcessTitleGetter(Local property, + const AccessorInfo& info) { + HandleScope scope; + int len; + const char *s = OS::GetProcessTitle(&len); + return scope.Close(s ? String::New(s, len) : String::Empty()); +} + + +static void ProcessTitleSetter(Local property, + Local value, + const AccessorInfo& info) { + HandleScope scope; + String::Utf8Value title(value->ToString()); + OS::SetProcessTitle(*title); +} + + static void Load(int argc, char *argv[]) { HandleScope scope; @@ -1514,6 +1532,12 @@ static void Load(int argc, char *argv[]) { process = Persistent::New(process_template->GetFunction()->NewInstance()); + + process->SetAccessor(String::New("title"), + ProcessTitleGetter, + ProcessTitleSetter); + + // Add a reference to the global object Local global = v8::Context::GetCurrent()->Global(); process->Set(String::NewSymbol("global"), global); @@ -1733,6 +1757,9 @@ static void AtExit() { int main(int argc, char *argv[]) { + // Hack aroung with the argv pointer. Used for process.title = "blah". + argv = node::OS::SetupArgs(argc, argv); + // Parse a few arguments which are specific to Node. node::ParseArgs(&argc, argv); // Parse the rest of the args (up to the 'option_end_index' (where '--' was diff --git a/src/platform.h b/src/platform.h index 45f4754726..f025230725 100644 --- a/src/platform.h +++ b/src/platform.h @@ -5,6 +5,10 @@ namespace node { class OS { public: + static char** SetupArgs(int argc, char *argv[]); + static void SetProcessTitle(char *title); + static const char* GetProcessTitle(int *len); + static int GetMemory(size_t *rss, size_t *vsize); static int GetExecutablePath(char* buffer, size_t* size); }; diff --git a/src/platform_cygwin.cc b/src/platform_cygwin.cc index 31276bd2ed..f2a1e84324 100644 --- a/src/platform_cygwin.cc +++ b/src/platform_cygwin.cc @@ -9,6 +9,23 @@ namespace node { static char buf[MAXPATHLEN + 1]; + +char** OS::SetupArgs(int argc, char *argv[]) { + return argv; +} + + +void OS::SetProcessTitle(char *title) { + ; +} + + +const char* OS::GetProcessTitle(int *len) { + *len = 0; + return NULL; +} + + int OS::GetMemory(size_t *rss, size_t *vsize) { FILE *f = fopen("/proc/self/stat", "r"); if (!f) return -1; diff --git a/src/platform_darwin.cc b/src/platform_darwin.cc index 2ff43f278f..16897b28d9 100644 --- a/src/platform_darwin.cc +++ b/src/platform_darwin.cc @@ -8,6 +8,22 @@ namespace node { + +char** OS::SetupArgs(int argc, char *argv[]) { + return argv; +} + + +void OS::SetProcessTitle(char *title) { + ; +} + + +const char* OS::GetProcessTitle(int *len) { + *len = 0; + return NULL; +} + // Researched by Tim Becker and Michael Knight // http://blog.kuriositaet.de/?p=257 int OS::GetMemory(size_t *rss, size_t *vsize) { diff --git a/src/platform_freebsd.cc b/src/platform_freebsd.cc index a0d25dd206..0a2c28bec9 100644 --- a/src/platform_freebsd.cc +++ b/src/platform_freebsd.cc @@ -13,6 +13,22 @@ namespace node { +char** OS::SetupArgs(int argc, char *argv[]) { + return argv; +} + + +void OS::SetProcessTitle(char *title) { + ; +} + + +const char* OS::GetProcessTitle(int *len) { + *len = 0; + return NULL; +} + + int OS::GetMemory(size_t *rss, size_t *vsize) { kvm_t *kd = NULL; struct kinfo_proc *kinfo = NULL; diff --git a/src/platform_linux.cc b/src/platform_linux.cc index 31276bd2ed..f2a1e84324 100644 --- a/src/platform_linux.cc +++ b/src/platform_linux.cc @@ -9,6 +9,23 @@ namespace node { static char buf[MAXPATHLEN + 1]; + +char** OS::SetupArgs(int argc, char *argv[]) { + return argv; +} + + +void OS::SetProcessTitle(char *title) { + ; +} + + +const char* OS::GetProcessTitle(int *len) { + *len = 0; + return NULL; +} + + int OS::GetMemory(size_t *rss, size_t *vsize) { FILE *f = fopen("/proc/self/stat", "r"); if (!f) return -1; diff --git a/src/platform_none.cc b/src/platform_none.cc index 56a36e1dd5..420efe189b 100644 --- a/src/platform_none.cc +++ b/src/platform_none.cc @@ -5,6 +5,22 @@ namespace node { +char** OS::SetupArgs(int argc, char *argv[]) { + return argv; +} + + +void OS::SetProcessTitle(char *title) { + ; +} + + +const char* OS::GetProcessTitle(int *len) { + *len = 0; + return NULL; +} + + int OS::GetMemory(size_t *rss, size_t *vsize) { // Not implemented *rss = 0; diff --git a/src/platform_sunos.cc b/src/platform_sunos.cc index 34c47fcedd..7723035a3b 100644 --- a/src/platform_sunos.cc +++ b/src/platform_sunos.cc @@ -24,6 +24,22 @@ namespace node { +char** OS::SetupArgs(int argc, char *argv[]) { + return argv; +} + + +void OS::SetProcessTitle(char *title) { + ; +} + + +const char* OS::GetProcessTitle(int *len) { + *len = 0; + return NULL; +} + + int OS::GetMemory(size_t *rss, size_t *vsize) { pid_t pid = getpid(); diff --git a/wscript b/wscript index f29174f271..f55ea5d88b 100644 --- a/wscript +++ b/wscript @@ -187,12 +187,8 @@ def configure(conf): if not conf.check(lib='nsl', uselib_store="NSL"): conf.fatal("Cannot find nsl library") - - conf.sub_config('deps/libeio') - - if conf.env['USE_SHARED_V8']: v8_includes = []; if o.shared_v8_includes: v8_includes.append(o.shared_v8_includes);