x/mobile: os.Hostname() fails on Android 0 (possibly earlier version as well). #24701
Comments
On my Android O device and emulator, os.Hostname returns an error: If you don't see a crash from the standard library either, please change this issue title to be about making os.Hostname not fail on Android O and later. I don't know how to do that, though. |
@bradfitz Just tried reinstalling go from golang.org ( |
@eliasnaur You are absolutely right! App was crashing because the go library was not handling the error properly. Updated title and description to reflect that. |
Perhaps the |
SGTM. |
Change https://golang.org/cl/110295 mentions this issue: |
Apologies for commenting on a closed issue, but in the commit 3c7456c should there be a break after name = string(buf[:i]) ?
|
Change https://golang.org/cl/110436 mentions this issue: |
@mdcnz, whoops. Fixed. Thanks! |
The Uname name was never being used because it always generated a too-long string. The new test looking for zero bytes wouldn't have caught it (I thought it would've), but is still nice to have. Updates #24701 Change-Id: I2648074452609e4ad1b9736973e1b3a95eac658d Reviewed-on: https://go-review.googlesource.com/110436 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.10.1 darwin/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/johan/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/johan/golang"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.10.1/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.10.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/kq/3436m_v11sg0l7zqtmv2r1gw0000gn/T/go-build866177725=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
Building a golang library for Android using
gomobile bind
:When the library is, calling
os.Hostname()
, the call fails with erroropen /proc/sys/kernel/hostname: permission denied
run on Android O (8.1.0). Also tested on Marshmallow (6.0) where the problem didn't occur.EDIT: Exact messsage is
Looks like access to
/proc
has been restricted? https://issuetracker.google.com/issues/37140047What did you expect to see?
Call not failing.
What did you see instead?
App stopping with error
EDIT: my library wasn't handling the error case properly, so it is not actually crashing, just that the call to
os.Hostname()
is failing.The text was updated successfully, but these errors were encountered: