mirror of
https://github.com/golang/go
synced 2024-11-21 21:24:45 -07: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:
parent
773a921ccb
commit
9b571a3120
@ -559,7 +559,16 @@ func Sysctl(name string) (value string, err error) {
|
||||
return "", err
|
||||
}
|
||||
if n == 0 {
|
||||
return "", nil
|
||||
// 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.
|
||||
|
Loading…
Reference in New Issue
Block a user