Bug 1284167 - /proc is unreliable on non-Linux. r?milan draft
authorJan Beich <jbeich@FreeBSD.org>
Mon, 04 Jul 2016 00:30:22 +0000
changeset 383787 dfd84a3a1d5923fd57a9fb2a7c9229fc3f842d03
parent 383418 ef894e2f3b4c47c121e6b0626bb8dced30d8849e
child 524546 da4192fcbcc0d9526d24c9822504388c2a8f4d1a
push id22095
push userbmo:jbeich@FreeBSD.org
push dateTue, 05 Jul 2016 00:00:34 +0000
reviewersmilan
bugs1284167
milestone50.0a1
Bug 1284167 - /proc is unreliable on non-Linux. r?milan MozReview-Commit-ID: 1B9bxjuRj6k
xpcom/base/nsSystemInfo.cpp
--- a/xpcom/base/nsSystemInfo.cpp
+++ b/xpcom/base/nsSystemInfo.cpp
@@ -27,16 +27,19 @@
 
 #ifdef XP_MACOSX
 #include "MacHelpers.h"
 #endif
 
 #ifdef MOZ_WIDGET_GTK
 #include <gtk/gtk.h>
 #include <dlfcn.h>
+#endif
+
+#if defined (XP_LINUX) && !defined (ANDROID)
 #include <unistd.h>
 #include <fstream>
 #include "mozilla/Tokenizer.h"
 #include "nsCharSeparatedTokenizer.h"
 
 #include <map>
 #include <string>
 #endif
@@ -68,17 +71,17 @@ NS_EXPORT int android_sdk_version;
 
 // Slot for NS_InitXPCOM2 to pass information to nsSystemInfo::Init.
 // Only set to nonzero (potentially) if XP_UNIX.  On such systems, the
 // system call to discover the appropriate value is not thread-safe,
 // so we must call it before going multithreaded, but nsSystemInfo::Init
 // only happens well after that point.
 uint32_t nsSystemInfo::gUserUmask = 0;
 
-#if defined (MOZ_WIDGET_GTK)
+#if defined (XP_LINUX) && !defined (ANDROID)
 static void
 SimpleParseKeyValuePairs(const std::string& aFilename,
                          std::map<nsCString, nsCString>& aKeyValuePairs)
 {
   std::ifstream input(aFilename.c_str());
   for (std::string line; std::getline(input, line); ) {
     nsAutoCString key, value;
 
@@ -492,17 +495,17 @@ nsSystemInfo::Init()
   MOZ_ASSERT(sizeof(sysctlValue32) == len);
 
   len = sizeof(sysctlValue32);
   if (!sysctlbyname("machdep.cpu.stepping", &sysctlValue32, &len, NULL, 0)) {
     cpuStepping = static_cast<int>(sysctlValue32);
   }
   MOZ_ASSERT(sizeof(sysctlValue32) == len);
 
-#elif defined (MOZ_WIDGET_GTK)
+#elif defined (XP_LINUX) && !defined (ANDROID)
   // Get vendor, family, model, stepping, physical cores, L3 cache size
   // from /proc/cpuinfo file
   {
     std::map<nsCString, nsCString> keyValuePairs;
     SimpleParseKeyValuePairs("/proc/cpuinfo", keyValuePairs);
 
     // cpuVendor from "vendor_id"
     cpuVendor.Assign(keyValuePairs[NS_LITERAL_CSTRING("vendor_id")]);