Skip to content

Commit 53af202

Browse files
committed
limits: Unbreak after RLIMIT_VMM addition
Update structures and add assertions to prevent a reoccurrence. Fixes: 1092ec8 ("kern: Introduce RLIMIT_VMM") Reviewed by: bnovkov, allanjude Differential Revision: https://reviews.freebsd.org/D54273
1 parent 41e9414 commit 53af202

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

usr.bin/limits/limits.1

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
.\" 5. Modifications may be freely made to this file providing the above
1818
.\" conditions are met.
1919
.\"
20-
.Dd June 25, 2020
20+
.Dd December 17, 2025
2121
.Dt LIMITS 1
2222
.Os
2323
.Sh NAME
@@ -28,11 +28,11 @@
2828
.Op Fl C Ar class | Fl P Ar pid | Fl U Ar user
2929
.Op Fl SHB
3030
.Op Fl ea
31-
.Op Fl bcdfklmnopstuvw Op Ar val
31+
.Op Fl bcdfklmnopstuVvwy Op Ar val
3232
.Nm
3333
.Op Fl C Ar class | Fl U Ar user
3434
.Op Fl SHB
35-
.Op Fl bcdfklmnopstuvwy Op Ar val
35+
.Op Fl bcdfklmnopstuVvwy Op Ar val
3636
.Op Fl E
3737
.Oo
3838
.Op Ar name Ns = Ns Ar value ...
@@ -265,6 +265,10 @@ in the entire system is limited to the value of the
265265
.Va kern.maxproc
266266
.Xr sysctl 8
267267
variable.
268+
.It Fl V Op Ar val
269+
Select or set the
270+
.Va vmms
271+
resource limit.
268272
.It Fl v Op Ar val
269273
Select or set the
270274
.Va virtualmem

usr.bin/limits/limits.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ static struct {
228228
static struct {
229229
const char * cap;
230230
rlim_t (*func)(login_cap_t *, const char *, rlim_t, rlim_t);
231-
} resources[RLIM_NLIMITS] = {
231+
} resources[] = {
232232
{ "cputime", login_getcaptime },
233233
{ "filesize", login_getcapsize },
234234
{ "datasize", login_getcapsize },
@@ -245,17 +245,22 @@ static struct {
245245
{ "kqueues", login_getcapnum },
246246
{ "umtxp", login_getcapnum },
247247
{ "pipebuf", login_getcapnum },
248+
{ "vmms", login_getcapnum },
248249
};
249250

251+
_Static_assert(nitems(resources) == RLIM_NLIMITS,
252+
"Please add entries to resources[] for the new limits");
253+
250254
/*
251255
* One letter for each resource levels.
252256
* NOTE: There is a dependency on the corresponding
253257
* letter index being equal to the resource number.
254258
* If sys/resource.h defines are changed, this needs
255259
* to be modified accordingly!
256260
*/
257-
258-
#define RCS_STRING "tfdscmlunbvpwkoy"
261+
static const char rcs_string[] = "tfdscmlunbvpwkoyV";
262+
_Static_assert(sizeof(rcs_string) - 1 == RLIM_NLIMITS,
263+
"Please add letters to rcs_string[] for the new limits");
259264

260265
static rlim_t resource_num(int which, int ch, const char *str);
261266
static void usage(void) __dead2;
@@ -266,8 +271,6 @@ static void getrlimit_proc(pid_t pid, int resource, struct rlimit *rlp);
266271
static void setrlimit_proc(pid_t pid, int resource, const struct rlimit *rlp);
267272
extern char **environ;
268273

269-
static const char rcs_string[] = RCS_STRING;
270-
271274
int
272275
main(int argc, char *argv[])
273276
{
@@ -295,7 +298,7 @@ main(int argc, char *argv[])
295298
pid = -1;
296299
optarg = NULL;
297300
while ((ch = getopt(argc, argv,
298-
":EeC:U:BSHP:ab:c:d:f:l:m:n:s:t:u:v:p:w:k:o:y:")) != -1) {
301+
":ab:BC:c:d:Eef:Hk:l:m:n:o:P:p:Ss:t:U:u:V:v:w:y:")) != -1) {
299302
switch(ch) {
300303
case 'a':
301304
doall = 1;
@@ -552,7 +555,7 @@ usage(void)
552555
{
553556
(void)fprintf(stderr,
554557
"usage: limits [-C class|-P pid|-U user] [-eaSHBE] "
555-
"[-bcdfklmnostuvpw [val]] [[name=val ...] cmd]\n");
558+
"[-bcdfklmnostuVvpwy [val]] [[name=val ...] cmd]\n");
556559
exit(EXIT_FAILURE);
557560
}
558561

@@ -664,6 +667,7 @@ resource_num(int which, int ch, const char *str)
664667
case RLIMIT_NPTS:
665668
case RLIMIT_KQUEUES:
666669
case RLIMIT_UMTXP:
670+
case RLIMIT_VMM:
667671
res = strtoq(s, &e, 0);
668672
s = e;
669673
break;

0 commit comments

Comments
 (0)