Page MenuHomeFreeBSD

sockstat(1): Add "-F" parameter
ClosedPublic

Authored by otis on Wed, Oct 29, 8:53 PM.
Tags
None
Referenced Files
F134573341: D53458.id165676.diff
Mon, Nov 3, 7:50 AM
F134548496: D53458.id165676.diff
Mon, Nov 3, 2:36 AM
F134541265: D53458.id165676.diff
Mon, Nov 3, 1:19 AM
F134541258: D53458.id165647.diff
Mon, Nov 3, 1:19 AM
F134541250: D53458.id165361.diff
Mon, Nov 3, 1:19 AM
F134541235: D53458.id165492.diff
Mon, Nov 3, 1:19 AM
F134541224: D53458.id.diff
Mon, Nov 3, 1:19 AM
F134541221: D53458.id165534.diff
Mon, Nov 3, 1:19 AM
Subscribers

Details

Summary

Add "-F" parameter that, when specified, instructs sockstat(1) to
only display sockets for username/UID specified.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

otis requested review of this revision.Wed, Oct 29, 8:53 PM

Just some sorting nits, I don't know about anything else.

usr.bin/sockstat/main.c
93

92m90 to match Unix style alphabetical organization like in 93,94

1888

Big F comes before little f, like it does in Cc;Ii: and Ll.

1924

This should go before little F like the Ccs and Iis.

usr.bin/sockstat/sockstat.1
86

79,82m76 to match Unix sorting like in 72,76

Just some sorting nits, I don't know about anything else.

Thanks for preliminary review.

There are still more open issues I need to work on, so this diff is just a placeholder for now (to track my progress).

Address ziaee's comments.

otis marked 4 inline comments as done.Thu, Oct 30, 8:33 PM
asomers requested changes to this revision.Fri, Oct 31, 1:59 PM

Thanks for doing this. I think it will be a good addition. But I'm curious: why did you choose -F? Obviously -u and -U were already taken.

usr.bin/sockstat/main.c
125

This would probably be better as an inline function than as a macro.

919

realloc is allowed to move the memory. It probably won't as long as we're only shrinking the array, but it's allowed to. If it does, then the pointers already inserted into ftree will become dangling. So I think you should either remove realloc entirely or add an assertion that the files pointer doesn't move.

920
1618

These could all be constant strings instead of macros.

1738

Here's a minor bug. Not introduced by you, but if -j or -F is in use, sockstat will still gather up all of the sockets in nosocks, even though it's not going to display them. We could skip that gather step to save efficiency. I think we should do that, but it doesn't need to be part of this PR.

1911

We filter only on first occurence of -F? For -j, we filter on the last.

This revision now requires changes to proceed.Fri, Oct 31, 1:59 PM

Address asomers' suggestions.

otis marked 5 inline comments as done.Sat, Nov 1, 9:58 PM
otis added inline comments.
usr.bin/sockstat/main.c
919

realloc is allowed to move the memory. It probably won't as long as we're only shrinking the array, but it's allowed to. If it does, then the pointers already inserted into ftree will become dangling. So I think you should either remove realloc entirely or add an assertion that the files pointer doesn't move.

I've removed the realloc() call completely.

1618

These could all be constant strings instead of macros.

good point, to not duplicate the strings (although I suppose that the compiler would optimize the string in a non-duplicated way).

1738

Here's a minor bug. Not introduced by you, but if -j or -F is in use, sockstat will still gather up all of the sockets in nosocks, even though it's not going to display them. We could skip that gather step to save efficiency. I think we should do that, but it doesn't need to be part of this PR.

I've only been able to identify one place where nosocks are being gathered.

1911

We filter only on first occurence of -F? For -j, we filter on the last.

For the sake of consistency, I made -F to act on the last occurence.

LGTM. Thanks for the contribution, Juraj.

This revision is now accepted and ready to land.Sun, Nov 2, 2:42 PM
This revision was automatically updated to reflect the committed changes.
otis marked 3 inline comments as done.