Fixes to appease make presubmit and make forcefull on FreeBSD.

This change adds a dependency on lsof(1) when running on FreeBSD.
lsof(1) is not part of the base system, and lsof(1) would need to be
installed (usually from ports).  If lsof(1) is not installed an error
will be returned in the form of:

ident_test.go:88: exec: "lsof": executable file not found in $PATH

Change-Id: I3cb15af369dc10a8a39aeaf82cceff3c788104b8
This commit is contained in:
Bill Thiede 2013-08-02 22:34:46 -07:00
parent 38bb307085
commit e6b86ddb9d
4 changed files with 38 additions and 3 deletions

View File

@ -1,3 +1,5 @@
// +build linux darwin
/*
Copyright 2011 Google Inc.

View File

@ -0,0 +1,27 @@
// +build !linux,!darwin
/*
Copyright 2013 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"log"
"runtime"
)
func main() {
log.Fatalln("cammount not implemented on", runtime.GOOS)
}

View File

@ -84,8 +84,8 @@ func AddrPairUserid(local, remote net.Addr) (uid int, err error) {
localv4, remotev4)
}
if runtime.GOOS == "darwin" {
return uidFromDarwinLsof(lAddr.IP, lAddr.Port, rAddr.IP, rAddr.Port)
if runtime.GOOS == "darwin" || runtime.GOOS == "freebsd" {
return uidFromLsof(lAddr.IP, lAddr.Port, rAddr.IP, rAddr.Port)
}
if runtime.GOOS == "linux" {
file := "/proc/net/tcp"
@ -125,9 +125,12 @@ func (p maybeBrackets) String() string {
return s
}
func uidFromDarwinLsof(lip net.IP, lport int, rip net.IP, rport int) (uid int, err error) {
func uidFromLsof(lip net.IP, lport int, rip net.IP, rport int) (uid int, err error) {
seek := fmt.Sprintf("%s:%d->%s:%d", maybeBrackets(lip), lport, maybeBrackets(rip), rport)
seekb := []byte(seek)
if _, err = exec.LookPath("lsof"); err != nil {
return
}
cmd := exec.Command("lsof",
"-b", // avoid system calls that could block
"-w", // and don't warn about cases where -b fails

View File

@ -120,6 +120,9 @@ func TestHTTPAuth(t *testing.T) {
t.Fatal(err)
}
if g, e := string(body), fmt.Sprintf("uid=%d", os.Getuid()); g != e {
if g == "ERR: "+ErrUnsupportedOS.Error() {
t.Skipf("Skipping test; not implemented on " + runtime.GOOS)
}
t.Errorf("got body %q; want %q", g, e)
}
}