Skip to content

Commit

Permalink
Fix lsof parsing after Xenial behavior change.
Browse files Browse the repository at this point in the history
  • Loading branch information
niemeyer committed Jun 2, 2016
1 parent 3e620f8 commit 0135bf7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
package mgo_test

import (
"bytes"
"errors"
"flag"
"fmt"
Expand Down Expand Up @@ -150,14 +151,16 @@ func (s *S) Stop(host string) {
}

func (s *S) pid(host string) int {
output, err := exec.Command("lsof", "-iTCP:"+hostPort(host), "-sTCP:LISTEN", "-Fp").CombinedOutput()
// Note recent releases of lsof force 'f' to be present in the output (WTF?).
cmd := exec.Command("lsof", "-iTCP:"+hostPort(host), "-sTCP:LISTEN", "-Fpf")
output, err := cmd.CombinedOutput()
if err != nil {
panic(err)
}
pidstr := string(output[1 : len(output)-1])
pidstr := string(bytes.Fields(output[1:])[0])
pid, err := strconv.Atoi(pidstr)
if err != nil {
panic("cannot convert pid to int: " + pidstr)
panic(fmt.Errorf("cannot convert pid to int: %q, command line: %q", pidstr, cmd.Args))
}
return pid
}
Expand Down

0 comments on commit 0135bf7

Please sign in to comment.