limits: Unbreak after RLIMIT_VMM addition

Update structures and add assertions to prevent a reoccurrence.

Fixes:		1092ec8b33 ("kern: Introduce RLIMIT_VMM")
Reviewed by:	bnovkov, allanjude
Differential Revision:	https://reviews.freebsd.org/D54273
This commit is contained in:
Dag-Erling Smørgrav
2025-12-17 20:38:59 +01:00
parent 41e9414e26
commit 53af2026f2
2 changed files with 18 additions and 10 deletions
+7 -3
View File
@@ -17,7 +17,7 @@
.\" 5. Modifications may be freely made to this file providing the above .\" 5. Modifications may be freely made to this file providing the above
.\" conditions are met. .\" conditions are met.
.\" .\"
.Dd June 25, 2020 .Dd December 17, 2025
.Dt LIMITS 1 .Dt LIMITS 1
.Os .Os
.Sh NAME .Sh NAME
@@ -28,11 +28,11 @@
.Op Fl C Ar class | Fl P Ar pid | Fl U Ar user .Op Fl C Ar class | Fl P Ar pid | Fl U Ar user
.Op Fl SHB .Op Fl SHB
.Op Fl ea .Op Fl ea
.Op Fl bcdfklmnopstuvw Op Ar val .Op Fl bcdfklmnopstuVvwy Op Ar val
.Nm .Nm
.Op Fl C Ar class | Fl U Ar user .Op Fl C Ar class | Fl U Ar user
.Op Fl SHB .Op Fl SHB
.Op Fl bcdfklmnopstuvwy Op Ar val .Op Fl bcdfklmnopstuVvwy Op Ar val
.Op Fl E .Op Fl E
.Oo .Oo
.Op Ar name Ns = Ns Ar value ... .Op Ar name Ns = Ns Ar value ...
@@ -265,6 +265,10 @@ in the entire system is limited to the value of the
.Va kern.maxproc .Va kern.maxproc
.Xr sysctl 8 .Xr sysctl 8
variable. variable.
.It Fl V Op Ar val
Select or set the
.Va vmms
resource limit.
.It Fl v Op Ar val .It Fl v Op Ar val
Select or set the Select or set the
.Va virtualmem .Va virtualmem
+11 -7
View File
@@ -228,7 +228,7 @@ static struct {
static struct { static struct {
const char * cap; const char * cap;
rlim_t (*func)(login_cap_t *, const char *, rlim_t, rlim_t); rlim_t (*func)(login_cap_t *, const char *, rlim_t, rlim_t);
} resources[RLIM_NLIMITS] = { } resources[] = {
{ "cputime", login_getcaptime }, { "cputime", login_getcaptime },
{ "filesize", login_getcapsize }, { "filesize", login_getcapsize },
{ "datasize", login_getcapsize }, { "datasize", login_getcapsize },
@@ -245,8 +245,12 @@ static struct {
{ "kqueues", login_getcapnum }, { "kqueues", login_getcapnum },
{ "umtxp", login_getcapnum }, { "umtxp", login_getcapnum },
{ "pipebuf", login_getcapnum }, { "pipebuf", login_getcapnum },
{ "vmms", login_getcapnum },
}; };
_Static_assert(nitems(resources) == RLIM_NLIMITS,
"Please add entries to resources[] for the new limits");
/* /*
* One letter for each resource levels. * One letter for each resource levels.
* NOTE: There is a dependency on the corresponding * NOTE: There is a dependency on the corresponding
@@ -254,8 +258,9 @@ static struct {
* If sys/resource.h defines are changed, this needs * If sys/resource.h defines are changed, this needs
* to be modified accordingly! * to be modified accordingly!
*/ */
static const char rcs_string[] = "tfdscmlunbvpwkoyV";
#define RCS_STRING "tfdscmlunbvpwkoy" _Static_assert(sizeof(rcs_string) - 1 == RLIM_NLIMITS,
"Please add letters to rcs_string[] for the new limits");
static rlim_t resource_num(int which, int ch, const char *str); static rlim_t resource_num(int which, int ch, const char *str);
static void usage(void) __dead2; static void usage(void) __dead2;
@@ -266,8 +271,6 @@ static void getrlimit_proc(pid_t pid, int resource, struct rlimit *rlp);
static void setrlimit_proc(pid_t pid, int resource, const struct rlimit *rlp); static void setrlimit_proc(pid_t pid, int resource, const struct rlimit *rlp);
extern char **environ; extern char **environ;
static const char rcs_string[] = RCS_STRING;
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
@@ -295,7 +298,7 @@ main(int argc, char *argv[])
pid = -1; pid = -1;
optarg = NULL; optarg = NULL;
while ((ch = getopt(argc, argv, while ((ch = getopt(argc, argv,
":EeC:U:BSHP:ab:c:d:f:l:m:n:s:t:u:v:p:w:k:o:y:")) != -1) { ":ab:BC:c:d:Eef:Hk:l:m:n:o:P:p:Ss:t:U:u:V:v:w:y:")) != -1) {
switch(ch) { switch(ch) {
case 'a': case 'a':
doall = 1; doall = 1;
@@ -552,7 +555,7 @@ usage(void)
{ {
(void)fprintf(stderr, (void)fprintf(stderr,
"usage: limits [-C class|-P pid|-U user] [-eaSHBE] " "usage: limits [-C class|-P pid|-U user] [-eaSHBE] "
"[-bcdfklmnostuvpw [val]] [[name=val ...] cmd]\n"); "[-bcdfklmnostuVvpwy [val]] [[name=val ...] cmd]\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@@ -664,6 +667,7 @@ resource_num(int which, int ch, const char *str)
case RLIMIT_NPTS: case RLIMIT_NPTS:
case RLIMIT_KQUEUES: case RLIMIT_KQUEUES:
case RLIMIT_UMTXP: case RLIMIT_UMTXP:
case RLIMIT_VMM:
res = strtoq(s, &e, 0); res = strtoq(s, &e, 0);
s = e; s = e;
break; break;