Implement process.title for linux
authorRyan Dahl <ry@tinyclouds.org>
Wed, 11 Aug 2010 19:44:35 +0000 (12:44 -0700)
committerRyan Dahl <ry@tinyclouds.org>
Wed, 11 Aug 2010 20:15:00 +0000 (13:15 -0700)
src/platform_linux.cc

index f2a1e8432406de13465e61e46bd2ae6d3c94b78d..d964d23600b8a3c0341f30ec9acabbb1d48e5126 100644 (file)
@@ -4,23 +4,37 @@
 #include <sys/param.h> // for MAXPATHLEN
 #include <unistd.h> // getpagesize
 
+/* SetProcessTitle */
+#include <sys/prctl.h>
+#include <linux/prctl.h>
+#include <stdlib.h> // free
+#include <string.h> // strdup
+
 
 namespace node {
 
 static char buf[MAXPATHLEN + 1];
+static char *process_title;
 
 
 char** OS::SetupArgs(int argc, char *argv[]) {
+  process_title = strdup(argv[0]);
   return argv;
 }
 
 
 void OS::SetProcessTitle(char *title) {
-  ;
+  if (process_title) free(process_title);
+  process_title = strdup(title);
+  prctl(PR_SET_NAME, process_title);
 }
 
 
 const char* OS::GetProcessTitle(int *len) {
+  if (process_title) {
+    *len = strlen(process_title);
+    return process_title;
+  }
   *len = 0;
   return NULL;
 }