Bug 229266 - some system utilities take JID only, not jail name
Summary: some system utilities take JID only, not jail name
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: Jamie Gritton
URL: https://lists.freebsd.org/pipermail/f...
Keywords: patch
Depends on:
Blocks:
 
Reported: 2018-06-24 08:02 UTC by Miroslav Lachman
Modified: 2018-07-06 19:12 UTC (History)
5 users (show)

See Also:


Attachments
Uses jail_getid(3) or equivalent for: cpuset, ipfw, libugidfw, sockstat (7.12 KB, patch)
2018-06-26 18:38 UTC, Jamie Gritton
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Miroslav Lachman 2018-06-24 08:02:08 UTC
FreeBSD has many jail aware utilities but they are inconsistent in 
taking JID as parameter.

For example "sockstat" takes -j JID "Show only sockets belonging to the 
specified jail ID" and it means numeric ID only.
On the other hand "ps" takes -J JID "This may be either the jid or name 
of the jail.  Use -J 0 to display only host processes."

The same apply for "top", it understands jid as a number or name of the 
jail too.
Then again "cpuset" takes only numerical ID of the jail...

This should be consistent across all FreeBSD base utilities so all of 
them can use numerical ID and name.

I took a quick look in to sources and almost each util has very different code to work with JID / jail name.

I am not C developer so I cannot provide any patches. I hope somebody else will have free time to fix these utilities.

Note I found this commit to fix jid / jail name problem for pgrep/pkill but again, it is very different code to what I found for procstat or sockstat
https://svnweb.freebsd.org/base?view=revision&revision=287012
Comment 1 Jamie Gritton freebsd_committer freebsd_triage 2018-06-26 17:38:30 UTC
I found four programs that let you specify a jail by JID only:
cpuset(1)
ipfw(8)
sockstat(1)
ugidfw(8)

Eight programs (11 if you count the jail programs themselves) that allow jails to be specified by name or ID:
ifconfig(8)
ifconfig(8)
pkill(1)
ps(1)
service(8)
sysrc(8)
xtop(1)
zfs(8)

And one that only allows jail by name:
rctl(8)


Of the four that only take a JID, a fix is easy for cpuset, ipfw, and sockstat.  ugidfw(8) actually parses the JID in libugidfw(3), and I'm hesitant to introduce a library dependency within another library; I may end up basically re-coding jail_getid(3) there.

A "fix" for rctl(8) to take JIDs is out of scope: the name parsing for that one is actually done in the kernel.
Comment 2 Jamie Gritton freebsd_committer freebsd_triage 2018-06-26 18:38:01 UTC
Created attachment 194658 [details]
Uses jail_getid(3) or equivalent for: cpuset, ipfw, libugidfw, sockstat
Comment 3 Christian Schwarz 2018-06-27 16:37:36 UTC
May I suggest to put this on reviews.freebsd.org ?
Comment 4 Jamie Gritton freebsd_committer freebsd_triage 2018-06-28 16:41:36 UTC
OK, I've added it as differential D16047.
Comment 5 commit-hook freebsd_committer freebsd_triage 2018-07-03 23:47:42 UTC
A commit references this bug:

Author: jamie
Date: Tue Jul  3 23:47:23 UTC 2018
New revision: 335921
URL: https://svnweb.freebsd.org/changeset/base/335921

Log:
  Allow jail names (not just IDs) to be specified for: cpuset(1), ipfw(8),
   sockstat(1), ugidfw(8)
  These are the last of the jail-aware userland utilities that didn't work
   with names.

  PR:		229266
  MFC after:	3 days
  Differential Revision:	D16047

Changes:
  head/lib/libugidfw/ugidfw.c
  head/sbin/ipfw/Makefile
  head/sbin/ipfw/ipfw.8
  head/sbin/ipfw/ipfw2.c
  head/usr.bin/cpuset/Makefile
  head/usr.bin/cpuset/cpuset.1
  head/usr.bin/cpuset/cpuset.c
  head/usr.bin/sockstat/Makefile
  head/usr.bin/sockstat/sockstat.1
  head/usr.bin/sockstat/sockstat.c
Comment 6 commit-hook freebsd_committer freebsd_triage 2018-07-06 16:24:07 UTC
A commit references this bug:

Author: jamie
Date: Fri Jul  6 16:23:30 UTC 2018
New revision: 336035
URL: https://svnweb.freebsd.org/changeset/base/336035

Log:
  Missed a bit of doc change from r335921.

  PR:		229266

Changes:
  head/usr.bin/cpuset/cpuset.1
Comment 7 commit-hook freebsd_committer freebsd_triage 2018-07-06 19:10:47 UTC
A commit references this bug:

Author: jamie
Date: Fri Jul  6 19:10:09 UTC 2018
New revision: 336039
URL: https://svnweb.freebsd.org/changeset/base/336039

Log:
  MFC r335921:

    Allow jail names (not just IDs) to be specified for: cpuset(1), ipfw(8),
     sockstat(1), ugidfw(8)
    These are the last of the jail-aware userland utilities that didn't work
     with names.

  PR:		229266
  Differential Revision:	D16047

Changes:
_U  stable/10/
  stable/10/lib/libugidfw/ugidfw.c
  stable/10/sbin/ipfw/Makefile
  stable/10/sbin/ipfw/ipfw.8
  stable/10/sbin/ipfw/ipfw2.c
  stable/10/usr.bin/cpuset/Makefile
  stable/10/usr.bin/cpuset/cpuset.1
  stable/10/usr.bin/cpuset/cpuset.c
  stable/10/usr.bin/sockstat/Makefile
  stable/10/usr.bin/sockstat/sockstat.1
  stable/10/usr.bin/sockstat/sockstat.c
Comment 8 commit-hook freebsd_committer freebsd_triage 2018-07-06 19:10:52 UTC
A commit references this bug:

Author: jamie
Date: Fri Jul  6 19:10:13 UTC 2018
New revision: 336040
URL: https://svnweb.freebsd.org/changeset/base/336040

Log:
  MFC r335921:

    Allow jail names (not just IDs) to be specified for: cpuset(1), ipfw(8),
     sockstat(1), ugidfw(8)
    These are the last of the jail-aware userland utilities that didn't work
     with names.

  PR:		229266
  Differential Revision:	D16047

Changes:
_U  stable/11/
  stable/11/lib/libugidfw/ugidfw.c
  stable/11/sbin/ipfw/Makefile
  stable/11/sbin/ipfw/ipfw.8
  stable/11/sbin/ipfw/ipfw2.c
  stable/11/usr.bin/cpuset/Makefile
  stable/11/usr.bin/cpuset/cpuset.1
  stable/11/usr.bin/cpuset/cpuset.c
  stable/11/usr.bin/sockstat/Makefile
  stable/11/usr.bin/sockstat/sockstat.1
  stable/11/usr.bin/sockstat/sockstat.c