PMM-2643: Support listing unix sockets in ConnectionsPid and ConnectionsPidWithContext.

Signed-off-by: Kamil Dziedzic <arvenil@klecza.pl>
pull/546/head
Kamil Dziedzic 7 years ago
parent 1c49dd8c6f
commit b76d065dff
No known key found for this signature in database
GPG Key ID: 9B2A8BE32C07EA6C

@ -71,6 +71,7 @@ type FilterStat struct {
}
var constMap = map[string]int{
"unix": syscall.AF_UNIX,
"TCP": syscall.SOCK_STREAM,
"UDP": syscall.SOCK_DGRAM,
"IPv4": syscall.AF_INET,
@ -178,10 +179,15 @@ func getIOCountersAll(n []IOCountersStat) ([]IOCountersStat, error) {
func parseNetLine(line string) (ConnectionStat, error) {
f := strings.Fields(line)
if len(f) < 9 {
if len(f) < 8 {
return ConnectionStat{}, fmt.Errorf("wrong line,%s", line)
}
if len(f) == 8 {
f = append(f, f[7])
f[7] = "unix"
}
pid, err := strconv.Atoi(f[1])
if err != nil {
return ConnectionStat{}, err
@ -199,10 +205,15 @@ func parseNetLine(line string) (ConnectionStat, error) {
return ConnectionStat{}, fmt.Errorf("unknown type, %s", f[7])
}
laddr, raddr, err := parseNetAddr(f[8])
var laddr, raddr Addr
if f[7] == "unix" {
laddr.IP = f[8]
} else {
laddr, raddr, err = parseNetAddr(f[8])
if err != nil {
return ConnectionStat{}, fmt.Errorf("failed to parse netaddr, %s", f[8])
}
}
n := ConnectionStat{
Fd: uint32(fd),

@ -63,7 +63,7 @@ func ConnectionsPidWithContext(ctx context.Context, kind string, pid int32) ([]C
case "udp6":
args = append(args, "6udp")
case "unix":
return ret, common.ErrNotImplementedError
args = []string{"-U"}
}
r, err := common.CallLsofWithContext(ctx, invoke, pid, args...)

Loading…
Cancel
Save