1
0
mirror of https://github.com/golang/go synced 2024-10-03 02:41:23 -06:00

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
This commit is contained in:
Joel Sing 2011-11-18 01:52:39 +11:00
parent 773a921ccb
commit 9b571a3120

View File

@ -559,8 +559,17 @@ func Sysctl(name string) (value string, err error) {
return "", err return "", err
} }
if n == 0 { 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 return "", nil
} }
}
// Read into buffer of that size. // Read into buffer of that size.
buf := make([]byte, n) buf := make([]byte, n)