From 1b36bcc3b59a3e123c5b1ac2617cadcb69d0e94a Mon Sep 17 00:00:00 2001
From: Joel Sing <jsing@google.com>
Date: Tue, 5 Mar 2013 21:40:37 +1100
Subject: [PATCH] syscall: handle getsockname for unix sockets on openbsd 5.2

On OpenBSD 5.2, calling getsockname on an unbound Unix domain socket
results in a successful syscall, however the AF is unset and the length
is returned as zero. This has been changed to more portable behaviour,
which will be included in the OpenBSD 5.3 release.

For now, work around this by treating a successful getsockname() call
that returns a family of AF_UNSPEC and length of zero as a AF_UNIX
socket.

Makes TestPassFD work on OpenBSD 5.2.

Fixes #4956.

R=golang-dev, minux.ma, rsc, mikioh.mikioh
CC=golang-dev
https://golang.org/cl/7449046
---
 src/pkg/syscall/passfd_test.go | 4 ----
 src/pkg/syscall/syscall_bsd.go | 5 +++++
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/pkg/syscall/passfd_test.go b/src/pkg/syscall/passfd_test.go
index 079c9303ba5..a0e59095075 100644
--- a/src/pkg/syscall/passfd_test.go
+++ b/src/pkg/syscall/passfd_test.go
@@ -13,7 +13,6 @@ import (
 	"net"
 	"os"
 	"os/exec"
-	"runtime"
 	"syscall"
 	"testing"
 	"time"
@@ -27,9 +26,6 @@ import (
 // "-test.run=^TestPassFD$" and an environment variable used to signal
 // that the test should become the child process instead.
 func TestPassFD(t *testing.T) {
-	if runtime.GOOS == "openbsd" {
-		t.Skip("issue 4956")
-	}
 	if os.Getenv("GO_WANT_HELPER_PROCESS") == "1" {
 		passFDChild()
 		return
diff --git a/src/pkg/syscall/syscall_bsd.go b/src/pkg/syscall/syscall_bsd.go
index a1e0d153f7e..560409a2620 100644
--- a/src/pkg/syscall/syscall_bsd.go
+++ b/src/pkg/syscall/syscall_bsd.go
@@ -327,6 +327,11 @@ func Getsockname(fd int) (sa Sockaddr, err error) {
 	if err = getsockname(fd, &rsa, &len); err != nil {
 		return
 	}
+	// TODO(jsing): Remove after OpenBSD 5.4 is released (see issue 3349).
+	if runtime.GOOS == "openbsd" && rsa.Addr.Family == AF_UNSPEC && rsa.Addr.Len == 0 {
+		rsa.Addr.Family = AF_UNIX
+		rsa.Addr.Len = SizeofSockaddrUnix
+	}
 	return anyToSockaddr(&rsa)
 }
 
-- 
GitLab