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 115444 93e76aaf861579f4dea5615605d17b33166576c5
parent 115443 67f93efc40c81576ebb57965fa973ccf180241ef
child 115445 a6228bc289587667d4dc19792731c4fd311fa4a5
push id239
push userakeybl@mozilla.com
push dateThu, 03 Jan 2013 21:54:43 +0000
treeherdermozilla-release@3a7b66445659 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscjones
bugs795480
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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