]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: hostname/domainname fix for openbsd
authorJoel Sing <jsing@google.com>
Thu, 17 Nov 2011 14:52:39 +0000 (01:52 +1100)
committerJoel Sing <jsing@google.com>
Thu, 17 Nov 2011 14:52:39 +0000 (01:52 +1100)
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

src/pkg/syscall/syscall_bsd.go

index 65ac1e08daf094ea2eca3d7cce8a75c79214bbcc..163232ad485ff77671841aa60821007fca963163 100644 (file)
@@ -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.