Commit dd0fc415 authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

[Fuchsia] use zx_system_get_version() instead of uname() in SysInfo

Previously base::SysInfo was using uname(), but uname() depends on
fuchsia.device.NameProvider API which may not be accessible in all
processes. This change updates SysInfo to use zx_system_get_version()
to get OS version.

Bug: 986952
Change-Id: Ie3324180040933a509124147efd743de1f112416
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1715631
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Commit-Queue: Wez <wez@chromium.org>
Auto-Submit: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680176}
parent ff71cb32
......@@ -4,11 +4,12 @@
#include "base/system/sys_info.h"
#include <sys/utsname.h>
#include <zircon/syscalls.h>
#include "base/fuchsia/fuchsia_logging.h"
#include "base/logging.h"
#include "base/threading/scoped_blocking_call.h"
#include "build/build_config.h"
namespace base {
......@@ -58,45 +59,34 @@ int64_t SysInfo::AmountOfTotalDiskSpace(const FilePath& path) {
// static
std::string SysInfo::OperatingSystemVersion() {
struct utsname info;
if (uname(&info) < 0) {
NOTREACHED();
char result[64] = {};
zx_status_t status = zx_system_get_version(result, sizeof(result));
if (status != ZX_OK) {
ZX_DLOG(WARNING, status) << "zx_system_get_version";
return std::string();
}
return std::string(info.release);
return result;
}
// static
void SysInfo::OperatingSystemVersionNumbers(int32_t* major_version,
int32_t* minor_version,
int32_t* bugfix_version) {
struct utsname info;
if (uname(&info) < 0) {
*major_version = 0;
*minor_version = 0;
*bugfix_version = 0;
return;
}
int num_read = sscanf(info.release, "%d.%d.%d", major_version, minor_version,
bugfix_version);
if (num_read < 1)
*major_version = 0;
if (num_read < 2)
*minor_version = 0;
if (num_read < 3)
*bugfix_version = 0;
// Fuchsia doesn't have OS version numbers.
*major_version = 0;
*minor_version = 0;
*bugfix_version = 0;
}
// static
std::string SysInfo::OperatingSystemArchitecture() {
struct utsname info;
if (uname(&info) < 0) {
NOTREACHED();
return std::string();
}
return info.machine;
#if defined(ARCH_CPU_X86_64)
return "x86_64";
#elif defined(ARCH_CPU_ARM64)
return "aarch64";
#else
#error Unsupported architecture.
#endif
}
// static
......
......@@ -115,7 +115,8 @@ TEST_F(SysInfoTest, MAYBE_AmountOfTotalDiskSpace) {
EXPECT_GT(SysInfo::AmountOfTotalDiskSpace(tmp_path), 0) << tmp_path.value();
}
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \
defined(OS_FUCHSIA)
TEST_F(SysInfoTest, OperatingSystemVersionNumbers) {
int32_t os_major_version = -1;
int32_t os_minor_version = -1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment