Bug 795480 - Make b2g app ensure that it's the process group controller. r=cjones
authorDave Hylands <dhylands@mozilla.com>
Fri, 28 Sep 2012 16:11:03 -0700
changeset 108685 93e76aaf861579f4dea5615605d17b33166576c5
parent 108684 67f93efc40c81576ebb57965fa973ccf180241ef
child 108686 a6228bc289587667d4dc19792731c4fd311fa4a5
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewerscjones
bugs795480
milestone18.0a1
Bug 795480 - Make b2g app ensure that it's the process group controller. r=cjones
b2g/app/nsBrowserApp.cpp
--- a/b2g/app/nsBrowserApp.cpp
+++ b/b2g/app/nsBrowserApp.cpp
@@ -7,16 +7,17 @@
 #include "application.ini.h"
 #include "nsXPCOMGlue.h"
 #if defined(XP_WIN)
 #include <windows.h>
 #include <stdlib.h>
 #elif defined(XP_UNIX)
 #include <sys/time.h>
 #include <sys/resource.h>
+#include <unistd.h>
 #endif
 
 #include <stdio.h>
 #include <stdarg.h>
 
 #include "nsCOMPtr.h"
 #include "nsIFile.h"
 #include "nsStringGlue.h"
@@ -164,16 +165,25 @@ int main(int argc, char* argv[])
   }
 
   char *lastSlash = strrchr(exePath, XPCOM_FILE_PATH_SEPARATOR[0]);
   if (!lastSlash || ((lastSlash - exePath) + sizeof(XPCOM_DLL) + 1 > MAXPATHLEN))
     return 255;
 
   strcpy(++lastSlash, XPCOM_DLL);
 
+#if defined(XP_UNIX)
+  // If the b2g app is launched from adb shell, then the shell will wind
+  // up being the process group controller. This means that we can't send
+  // signals to the process group (useful for profiling).
+  // We ignore the return value since setsid() fails if we're already the
+  // process group controller (the normal situation).
+  (void)setsid();
+#endif
+
   int gotCounters;
 #if defined(XP_UNIX)
   struct rusage initialRUsage;
   gotCounters = !getrusage(RUSAGE_SELF, &initialRUsage);
 #elif defined(XP_WIN)
   IO_COUNTERS ioCounters;
   gotCounters = GetProcessIoCounters(GetCurrentProcess(), &ioCounters);
 #endif