Commit 9b571a31 authored by Joel Sing's avatar Joel Sing

syscall: hostname/domainname fix for openbsd

Work around a bug that was fixed after OpenBSD 5.0 - a request for
kern.hostname or kern.domainname with a nil value for oldp will result
in a length of zero being returned. If we hit this case use a length
of MAXHOSTNAMELEN (256).

R=golang-dev, mikioh.mikioh
CC=golang-dev
https://golang.org/cl/5408041
parent 773a921c
......@@ -559,8 +559,17 @@ func Sysctl(name string) (value string, err error) {
return "", err
}
if n == 0 {
// TODO(jsing): Remove after OpenBSD 5.2 release.
// Work around a bug that was fixed after OpenBSD 5.0.
// The length for kern.hostname and kern.domainname is always
// returned as 0 when a nil value is passed for oldp.
if OS == "openbsd" && (value == "kern.hostname" || value == "kern.domainname") {
// MAXHOSTNAMELEN
n = 256
} else {
return "", nil
}
}
// Read into buffer of that size.
buf := make([]byte, n)
......
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