Bug 1001842 part 1: record the umask in NS_InitXPCOM2 and expose it to JS via nsSystemInfo. r=bsmedberg

This commit is contained in:
Zack Weinberg 2014-04-26 10:56:54 -04:00
Родитель 298702866a
Коммит cd4452471d
4 изменённых файлов: 42 добавлений и 0 удалений

Просмотреть файл

@ -40,6 +40,13 @@ NS_EXPORT int android_sdk_version;
}
#endif
// 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(XP_WIN)
namespace {
nsresult GetHDDInfo(const char* aSpecialDirName, nsAutoCString& aModel,
@ -198,6 +205,7 @@ nsSystemInfo::Init()
SetInt32Property(NS_LITERAL_STRING("memmapalign"), PR_GetMemMapAlignment());
SetInt32Property(NS_LITERAL_STRING("cpucount"), PR_GetNumberOfProcessors());
SetUint64Property(NS_LITERAL_STRING("memsize"), PR_GetPhysicalMemorySize());
SetUint32Property(NS_LITERAL_STRING("umask"), nsSystemInfo::gUserUmask);
for (uint32_t i = 0; i < ArrayLength(cpuPropItems); i++) {
rv = SetPropertyAsBool(NS_ConvertASCIItoUTF16(cpuPropItems[i].name),
@ -306,6 +314,19 @@ nsSystemInfo::SetInt32Property(const nsAString &aPropertyName,
}
}
void
nsSystemInfo::SetUint32Property(const nsAString &aPropertyName,
const uint32_t aValue)
{
// Only one property is currently set via this function.
// It may legitimately be zero.
#ifdef DEBUG
nsresult rv =
#endif
SetPropertyAsUint32(aPropertyName, aValue);
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Unable to set property");
}
void
nsSystemInfo::SetUint64Property(const nsAString &aPropertyName,
const uint64_t aValue)

Просмотреть файл

@ -14,9 +14,15 @@ public:
nsresult Init();
// Slot for NS_InitXPCOM2 to pass information to nsSystemInfo::Init.
// See comments above the variable definition and in NS_InitXPCOM2.
static uint32_t gUserUmask;
protected:
void SetInt32Property(const nsAString &aPropertyName,
const int32_t aValue);
void SetUint32Property(const nsAString &aPropertyName,
const uint32_t aValue);
void SetUint64Property(const nsAString &aPropertyName,
const uint64_t aValue);

Просмотреть файл

@ -461,6 +461,17 @@ NS_InitXPCOM2(nsIServiceManager* *result,
// chance to start up, because the initialization is not thread-safe.
mozilla::AvailableMemoryTracker::Init();
#ifdef XP_UNIX
// Discover the current value of the umask, and save it where
// nsSystemInfo::Init can retrieve it when necessary. There is no way
// to read the umask without changing it, and the setting is process-
// global, so this must be done while we are still single-threaded; the
// nsSystemInfo object is typically created much later, when some piece
// of chrome JS wants it. The system call is specified as unable to fail.
nsSystemInfo::gUserUmask = ::umask(0777);
::umask(nsSystemInfo::gUserUmask);
#endif
NS_LogInit();
// Set up chromium libs

Просмотреть файл

@ -13,4 +13,8 @@ function run_test() {
let value = sysInfo.getProperty(aPropertyName);
do_check_true(!!value);
});
// This property must exist, but its value might be zero.
print("Testing property: umask")
do_check_eq(typeof sysInfo.getProperty("umask"), "number");
}