Add support for RLIMIT_NPTS to limits(1).

After the MPSAFE TTY import we support an additional rlimit, called
RLIMIT_NPTS. This limit allows you to cap the amount of pseudo-terminals
allocated by one user.

We forgot to add support for this limit to limits(1), which means it
crashed. Add the proper bits to make it work like it should.
Unfortunately not all shells actually implement the RLIMIT, so
unfortunately I suspect it to be broken with certain shells.

Submitted by:	Yuriy Tsibizov <yuriy tsibizov gfk ru>
This commit is contained in:
ed 2008-09-02 19:13:24 +00:00
parent 59a00054ac
commit 5f23a3b5ca
2 changed files with 68 additions and 54 deletions

View File

@ -30,11 +30,11 @@
.Op Fl C Ar class | Fl U Ar user
.Op Fl SHB
.Op Fl ea
.Op Fl bcdflmnstuv Op Ar val
.Op Fl bcdflmnstuvp Op Ar val
.Nm
.Op Fl C Ar class | Fl U Ar user
.Op Fl SHB
.Op Fl bcdflmnstuv Op Ar val
.Op Fl bcdflmnstuvp Op Ar val
.Op Fl E
.Oo
.Op Ar name Ns = Ns Ar value ...
@ -262,6 +262,10 @@ and is inclusive of text, data, bss, stack,
and
.Xr mmap 2 Ns 'd
space.
.It Fl p Op Ar val
Select or set the
.Va pseudoterminals
resource limit.
.El
.Pp
Valid values for

View File

@ -76,17 +76,18 @@ static struct {
{
{ "", "infinity", "Resource limits%s%s:\n", "-max", "-cur", "",
{
{ " cputime%-4s %8s", " secs\n", 1 },
{ " filesize%-4s %8s", " kB\n", 1024 },
{ " datasize%-4s %8s", " kB\n", 1024 },
{ " stacksize%-4s %8s", " kB\n", 1024 },
{ " coredumpsize%-4s %8s", " kB\n", 1024 },
{ " memoryuse%-4s %8s", " kB\n", 1024 },
{ " memorylocked%-4s %8s", " kB\n", 1024 },
{ " maxprocesses%-4s %8s", "\n", 1 },
{ " openfiles%-4s %8s", "\n", 1 },
{ " sbsize%-4s %8s", " bytes\n", 1 },
{ " vmemoryuse%-4s %8s", " kB\n", 1024 }
{ " cputime%-4s %8s", " secs\n", 1 },
{ " filesize%-4s %8s", " kB\n", 1024 },
{ " datasize%-4s %8s", " kB\n", 1024 },
{ " stacksize%-4s %8s", " kB\n", 1024 },
{ " coredumpsize%-4s %8s", " kB\n", 1024 },
{ " memoryuse%-4s %8s", " kB\n", 1024 },
{ " memorylocked%-4s %8s", " kB\n", 1024 },
{ " maxprocesses%-4s %8s", "\n", 1 },
{ " openfiles%-4s %8s", "\n", 1 },
{ " sbsize%-4s %8s", " bytes\n", 1 },
{ " vmemoryuse%-4s %8s", " kB\n", 1024 },
{ " pseudo-terminals%-4s %8s", "\n", 1 }
}
},
{ "sh", "unlimited", "", " -H", " -S", "",
@ -101,22 +102,24 @@ static struct {
{ "ulimit%s -u %s", ";\n", 1 },
{ "ulimit%s -n %s", ";\n", 1 },
{ "ulimit%s -b %s", ";\n", 1 },
{ "ulimit%s -v %s", ";\n", 1024 }
{ "ulimit%s -v %s", ";\n", 1024 },
{ "ulimit%s -p %s", ";\n", 1 }
}
},
{ "csh", "unlimited", "", " -h", "", NULL,
{
{ "limit%s cputime %s", ";\n", 1 },
{ "limit%s filesize %s", ";\n", 1024 },
{ "limit%s datasize %s", ";\n", 1024 },
{ "limit%s stacksize %s", ";\n", 1024 },
{ "limit%s coredumpsize %s", ";\n", 1024 },
{ "limit%s memoryuse %s", ";\n", 1024 },
{ "limit%s memorylocked %s", ";\n", 1024 },
{ "limit%s maxproc %s", ";\n", 1 },
{ "limit%s openfiles %s", ";\n", 1 },
{ "limit%s sbsize %s", ";\n", 1 },
{ "limit%s vmemoryuse %s", ";\n", 1024 }
{ "limit%s cputime %s", ";\n", 1 },
{ "limit%s filesize %s", ";\n", 1024 },
{ "limit%s datasize %s", ";\n", 1024 },
{ "limit%s stacksize %s", ";\n", 1024 },
{ "limit%s coredumpsize %s", ";\n", 1024 },
{ "limit%s memoryuse %s", ";\n", 1024 },
{ "limit%s memorylocked %s", ";\n", 1024 },
{ "limit%s maxproc %s", ";\n", 1 },
{ "limit%s openfiles %s", ";\n", 1 },
{ "limit%s sbsize %s", ";\n", 1 },
{ "limit%s vmemoryuse %s", ";\n", 1024 },
{ "limit%s pseudoterminals %s", ";\n", 1 }
}
},
{ "bash|bash2", "unlimited", "", " -H", " -S", "",
@ -131,22 +134,24 @@ static struct {
{ "ulimit%s -u %s", ";\n", 1 },
{ "ulimit%s -n %s", ";\n", 1 },
{ "ulimit%s -b %s", ";\n", 1 },
{ "ulimit%s -v %s", ";\n", 1024 }
{ "ulimit%s -v %s", ";\n", 1024 },
{ "ulimit%s -p %s", ";\n", 1 }
}
},
{ "tcsh", "unlimited", "", " -h", "", NULL,
{
{ "limit%s cputime %s", ";\n", 1 },
{ "limit%s filesize %s", ";\n", 1024 },
{ "limit%s datasize %s", ";\n", 1024 },
{ "limit%s stacksize %s", ";\n", 1024 },
{ "limit%s coredumpsize %s", ";\n", 1024 },
{ "limit%s memoryuse %s", ";\n", 1024 },
{ "limit%s memorylocked %s", ";\n", 1024 },
{ "limit%s maxproc %s", ";\n", 1 },
{ "limit%s descriptors %s", ";\n", 1 },
{ "limit%s sbsize %s", ";\n", 1 },
{ "limit%s vmemoryuse %s", ";\n", 1024 }
{ "limit%s cputime %s", ";\n", 1 },
{ "limit%s filesize %s", ";\n", 1024 },
{ "limit%s datasize %s", ";\n", 1024 },
{ "limit%s stacksize %s", ";\n", 1024 },
{ "limit%s coredumpsize %s", ";\n", 1024 },
{ "limit%s memoryuse %s", ";\n", 1024 },
{ "limit%s memorylocked %s", ";\n", 1024 },
{ "limit%s maxproc %s", ";\n", 1 },
{ "limit%s descriptors %s", ";\n", 1 },
{ "limit%s sbsize %s", ";\n", 1 },
{ "limit%s vmemoryuse %s", ";\n", 1024 },
{ "limit%s pseudoterminals %s", ";\n", 1 }
}
},
{ "ksh|pdksh", "unlimited", "", " -H", " -S", "",
@ -161,7 +166,8 @@ static struct {
{ "ulimit%s -p %s", ";\n", 1 },
{ "ulimit%s -n %s", ";\n", 1 },
{ "ulimit%s -b %s", ";\n", 1 },
{ "ulimit%s -v %s", ";\n", 1024 }
{ "ulimit%s -v %s", ";\n", 1024 },
{ "ulimit%s -p %s", ";\n", 1 }
}
},
{ "zsh", "unlimited", "", " -H", " -S", "",
@ -176,22 +182,24 @@ static struct {
{ "ulimit%s -u %s", ";\n", 1 },
{ "ulimit%s -n %s", ";\n", 1 },
{ "ulimit%s -b %s", ";\n", 1 },
{ "ulimit%s -v %s", ";\n", 1024 }
{ "ulimit%s -v %s", ";\n", 1024 },
{ "ulimit%s -p %s", ";\n", 1 }
}
},
{ "rc|es", "unlimited", "", " -h", "", NULL,
{
{ "limit%s cputime %s", ";\n", 1 },
{ "limit%s filesize %s", ";\n", 1024 },
{ "limit%s datasize %s", ";\n", 1024 },
{ "limit%s stacksize %s", ";\n", 1024 },
{ "limit%s coredumpsize %s", ";\n", 1024 },
{ "limit%s memoryuse %s", ";\n", 1024 },
{ "limit%s lockedmemory %s", ";\n", 1024 },
{ "limit%s processes %s", ";\n", 1 },
{ "limit%s descriptors %s", ";\n", 1 },
{ "limit%s sbsize %s", ";\n", 1 },
{ "limit%s vmemoryuse %s", ";\n", 1024 }
{ "limit%s cputime %s", ";\n", 1 },
{ "limit%s filesize %s", ";\n", 1024 },
{ "limit%s datasize %s", ";\n", 1024 },
{ "limit%s stacksize %s", ";\n", 1024 },
{ "limit%s coredumpsize %s", ";\n", 1024 },
{ "limit%s memoryuse %s", ";\n", 1024 },
{ "limit%s lockedmemory %s", ";\n", 1024 },
{ "limit%s processes %s", ";\n", 1 },
{ "limit%s descriptors %s", ";\n", 1 },
{ "limit%s sbsize %s", ";\n", 1 },
{ "limit%s vmemoryuse %s", ";\n", 1024 },
{ "limit%s pseudoterminals %s", ";\n", 1 }
}
},
{ NULL, NULL, NULL, NULL, NULL, NULL,
@ -213,7 +221,8 @@ static struct {
{ "maxproc", login_getcapnum },
{ "openfiles", login_getcapnum },
{ "sbsize", login_getcapsize },
{ "vmemoryuse", login_getcapsize }
{ "vmemoryuse", login_getcapsize },
{ "pseudoterminals",login_getcapnum },
};
/*
@ -224,7 +233,7 @@ static struct {
* to be modified accordingly!
*/
#define RCS_STRING "tfdscmlunbv"
#define RCS_STRING "tfdscmlunbvp"
static rlim_t resource_num(int which, int ch, const char *str);
static void usage(void);
@ -261,7 +270,7 @@ main(int argc, char *argv[])
}
optarg = NULL;
while ((ch = getopt(argc, argv, ":EeC:U:BSHab:c:d:f:l:m:n:s:t:u:v:")) != -1) {
while ((ch = getopt(argc, argv, ":EeC:U:BSHab:c:d:f:l:m:n:s:t:u:v:p:")) != -1) {
switch(ch) {
case 'a':
doall = 1;
@ -475,7 +484,7 @@ static void
usage(void)
{
(void)fprintf(stderr,
"usage: limits [-C class|-U user] [-eaSHBE] [-bcdflmnstuv [val]] [[name=val ...] cmd]\n");
"usage: limits [-C class|-U user] [-eaSHBE] [-bcdflmnstuvp [val]] [[name=val ...] cmd]\n");
exit(EXIT_FAILURE);
}
@ -581,6 +590,7 @@ resource_num(int which, int ch, const char *str)
break;
case RLIMIT_NPROC:
case RLIMIT_NOFILE:
case RLIMIT_NPTS:
res = strtoq(s, &e, 0);
s = e;
break;