Bug 799686 - Make about:memory dump file readable on Android. r=njn
authorKartikaya Gupta <kgupta@mozilla.com>
Sat, 13 Oct 2012 08:54:49 -0400
changeset 110272 7f47eacb16e385d1516171b55c67bd5a8b150a21
parent 110271 5091701dcc4582baf6914b5b587589942d1ec976
child 110273 7e369eed5f9f26e3555fdc941a5052143e3b6a4d
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersnjn
bugs799686
milestone19.0a1
Bug 799686 - Make about:memory dump file readable on Android. r=njn
xpcom/base/nsMemoryReporterManager.cpp
--- a/xpcom/base/nsMemoryReporterManager.cpp
+++ b/xpcom/base/nsMemoryReporterManager.cpp
@@ -33,16 +33,21 @@
 #ifdef XP_WIN
 #include <process.h>
 #define getpid _getpid
 #else
 #include <unistd.h>
 #include <fcntl.h>
 #endif
 
+#ifdef ANDROID
+#include <sys/types.h>
+#include <sys/stat.h>
+#endif
+
 using namespace mozilla;
 using namespace mozilla::dom;
 
 #if defined(MOZ_MEMORY)
 #  define HAVE_JEMALLOC_STATS 1
 #  include "jemalloc.h"
 #endif  // MOZ_MEMORY
 
@@ -1303,17 +1308,25 @@ nsMemoryReporterManager::DumpMemoryRepor
     }
     filename.AppendLiteral("-");
     filename.AppendInt(getpid());
     filename.AppendLiteral(".json.gz");
 
     rv = tmpFile->AppendNative(NS_LITERAL_CSTRING("incomplete-") + filename);
     NS_ENSURE_SUCCESS(rv, rv);
    
-    rv = tmpFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600);
+#ifdef ANDROID
+    // Set umask to 0 while we create the file because on Android the default
+    // umask is 0077.
+    mode_t mask = umask(0);
+#endif
+    rv = tmpFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0644);
+#ifdef ANDROID
+    umask(mask);
+#endif
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsRefPtr<nsGZFileWriter> writer = new nsGZFileWriter();
     rv = writer->Init(tmpFile);
     NS_ENSURE_SUCCESS(rv, rv);
 
     // Dump the memory reports to the file.