Add FreeBSD support

For FreeBSD 12.2 and before I think we could use SCM_CREDS to get
the pid of the peer. For FreeBSD 13.x and later, the Xucred is
extended with a pid. For now we'll leave it unimplemented and
expect to add FreeBSD 13+ support whern it is released.

Signed-off-by: Denton Gentry <dgentry@tailscale.com>
This commit is contained in:
Denton Gentry
2021-03-02 06:23:55 -08:00
committed by Denton Gentry
parent 88448a8ba5
commit 6ba7dd52e8
4 changed files with 71 additions and 8 deletions
+13 -7
View File
@@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.
// +build go1.15
// +build linux darwin
// +build linux darwin freebsd
package peercred // import "inet.af/peercred"
@@ -12,6 +12,7 @@ import (
"net"
"os"
"path/filepath"
"runtime"
"testing"
)
@@ -59,11 +60,16 @@ func TestUnixSock(t *testing.T) {
t.Errorf("UID = %q; want %q", got, want)
}
pid, ok := creds.PID()
if !ok {
t.Errorf("no PID")
if runtime.GOOS == "freebsd" {
if ok {
t.Error("PID ok; want !ok. Thank you for fixing FreeBSD, please update the test.")
}
} else {
if !ok {
t.Errorf("no PID")
}
if got, want := pid, os.Getpid(); got != want {
t.Errorf("PID = %v; want %v", got, want)
}
}
if got, want := pid, os.Getpid(); got != want {
t.Errorf("PID = %v; want %v", got, want)
}
}