summaryrefslogtreecommitdiff
path: root/usr.bin/limits
diff options
context:
space:
mode:
authorSimon J. Gerraty <sjg@FreeBSD.org>2014-04-28 07:50:45 +0000
committerSimon J. Gerraty <sjg@FreeBSD.org>2014-04-28 07:50:45 +0000
commit3b8f08459569bf0faa21473e5cec2491e95c9349 (patch)
tree80f45dd81ca716bcd7ca9674581e1fc40b93cd34 /usr.bin/limits
parent9d2ab4a62d6733c45958627ac113bdbd818d1e2a (diff)
parentb2ba55951383498f252746f618d513139da06e8e (diff)
downloadsrc-test2-3b8f08459569bf0faa21473e5cec2491e95c9349.tar.gz
src-test2-3b8f08459569bf0faa21473e5cec2491e95c9349.zip
Notes
Diffstat (limited to 'usr.bin/limits')
-rw-r--r--usr.bin/limits/limits.128
-rw-r--r--usr.bin/limits/limits.c57
2 files changed, 42 insertions, 43 deletions
diff --git a/usr.bin/limits/limits.1 b/usr.bin/limits/limits.1
index 26e8929374fd..3962feff1943 100644
--- a/usr.bin/limits/limits.1
+++ b/usr.bin/limits/limits.1
@@ -19,7 +19,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd January 23, 2012
+.Dd November 1, 2013
.Dt LIMITS 1
.Os
.Sh NAME
@@ -30,11 +30,11 @@
.Op Fl C Ar class | Fl P Ar pid | Fl U Ar user
.Op Fl SHB
.Op Fl ea
-.Op Fl bcdflmnstuvpw Op Ar val
+.Op Fl bcdfklmnstuvpw Op Ar val
.Nm
.Op Fl C Ar class | Fl U Ar user
.Op Fl SHB
-.Op Fl bcdflmnstuvpw Op Ar val
+.Op Fl bcdfklmnstuvpw Op Ar val
.Op Fl E
.Oo
.Op Ar name Ns = Ns Ar value ...
@@ -87,9 +87,6 @@ Like the previous usage, it outputs these values to standard
output, except that it will emit them in
.Ic eval
format, suitable for the calling shell.
-The calling shell is determined by examining the entries in the
-.Pa /proc
-file system for the parent process.
If the shell is known (i.e., it is one of
.Nm sh , csh , bash , tcsh , ksh , pdksh
or
@@ -210,6 +207,10 @@ resource limit.
Select or set the
.Va filesize
resource limit.
+.It Fl k Op Ar val
+Select or set the
+.Va kqueues
+resource limit.
.It Fl l Op Ar val
Select or set the
.Va memorylocked
@@ -386,21 +387,6 @@ utility does not handle commands with equal
signs in their
names, for obvious reasons.
.Pp
-When eval output is selected, the
-.Pa /proc
-file system must be installed
-and mounted for the shell to be correctly determined, and therefore
-output syntax correct for the running shell.
-The default output is valid for
-.Xr sh 1 ,
-so this means that any
-usage of
-.Nm
-in eval mode prior mounting
-.Pa /proc
-may only occur in standard bourne
-shell scripts.
-.Pp
The
.Nm
utility makes no effort to ensure that resource settings emitted or displayed
diff --git a/usr.bin/limits/limits.c b/usr.bin/limits/limits.c
index 3c5fd6de3104..28b09ca0a622 100644
--- a/usr.bin/limits/limits.c
+++ b/usr.bin/limits/limits.c
@@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/sysctl.h>
+#include <sys/user.h>
#include <sys/param.h>
#include <stdlib.h>
#include <unistd.h>
@@ -89,7 +90,8 @@ static struct {
{ " sbsize%-4s %8s", " bytes\n", 1 },
{ " vmemoryuse%-4s %8s", " kB\n", 1024 },
{ " pseudo-terminals%-4s %8s", "\n", 1 },
- { " swapuse%-4s %8s", " kB\n", 1024 }
+ { " swapuse%-4s %8s", " kB\n", 1024 },
+ { " kqueues%-4s %8s", "\n", 1 },
}
},
{ "sh", "unlimited", "", " -H", " -S", "",
@@ -106,7 +108,8 @@ static struct {
{ "ulimit%s -b %s", ";\n", 1 },
{ "ulimit%s -v %s", ";\n", 1024 },
{ "ulimit%s -p %s", ";\n", 1 },
- { "ulimit%s -w %s", ";\n", 1024 }
+ { "ulimit%s -w %s", ";\n", 1024 },
+ { "ulimit%s -k %s", ";\n", 1 },
}
},
{ "csh", "unlimited", "", " -h", "", NULL,
@@ -123,7 +126,8 @@ static struct {
{ "limit%s sbsize %s", ";\n", 1 },
{ "limit%s vmemoryuse %s", ";\n", 1024 },
{ "limit%s pseudoterminals %s", ";\n", 1 },
- { "limit%s swapuse %s", ";\n", 1024 }
+ { "limit%s swapsize %s", ";\n", 1024 },
+ { "limit%s kqueues %s", ";\n", 1 },
}
},
{ "bash|bash2", "unlimited", "", " -H", " -S", "",
@@ -157,7 +161,8 @@ static struct {
{ "limit%s sbsize %s", ";\n", 1 },
{ "limit%s vmemoryuse %s", ";\n", 1024 },
{ "limit%s pseudoterminals %s", ";\n", 1 },
- { "limit%s swapuse %s", ";\n", 1024 }
+ { "limit%s swapsize %s", ";\n", 1024 },
+ { "limit%s kqueues %s", ";\n", 1 },
}
},
{ "ksh|pdksh", "unlimited", "", " -H", " -S", "",
@@ -232,7 +237,8 @@ static struct {
{ "sbsize", login_getcapsize },
{ "vmemoryuse", login_getcapsize },
{ "pseudoterminals",login_getcapnum },
- { "swapuse", login_getcapsize }
+ { "swapuse", login_getcapsize },
+ { "kqueues", login_getcapnum },
};
/*
@@ -243,7 +249,7 @@ static struct {
* to be modified accordingly!
*/
-#define RCS_STRING "tfdscmlunbvpw"
+#define RCS_STRING "tfdscmlunbvpwk"
static rlim_t resource_num(int which, int ch, const char *str);
static void usage(void);
@@ -282,7 +288,8 @@ main(int argc, char *argv[])
pid = -1;
optarg = NULL;
- while ((ch = getopt(argc, argv, ":EeC:U:BSHP:ab:c:d:f:l:m:n:s:t:u:v:p:w:")) != -1) {
+ while ((ch = getopt(argc, argv,
+ ":EeC:U:BSHP:ab:c:d:f:l:m:n:s:t:u:v:p:w:k:")) != -1) {
switch(ch) {
case 'a':
doall = 1;
@@ -539,7 +546,7 @@ usage(void)
{
(void)fprintf(stderr,
"usage: limits [-C class|-P pid|-U user] [-eaSHBE] "
- "[-bcdflmnstuvpw [val]] [[name=val ...] cmd]\n");
+ "[-bcdflmnstuvpwk [val]] [[name=val ...] cmd]\n");
exit(EXIT_FAILURE);
}
@@ -647,6 +654,7 @@ resource_num(int which, int ch, const char *str)
case RLIMIT_NPROC:
case RLIMIT_NOFILE:
case RLIMIT_NPTS:
+ case RLIMIT_KQUEUES:
res = strtoq(s, &e, 0);
s = e;
break;
@@ -698,27 +706,32 @@ getshelltype(void)
pid_t ppid = getppid();
if (ppid != 1) {
- FILE * fp;
+ struct kinfo_proc kp;
struct stat st;
- char procdir[MAXPATHLEN], buf[128];
- int l = sprintf(procdir, "/proc/%ld/", (long)ppid);
+ char path[MAXPATHLEN];
char * shell = getenv("SHELL");
+ int mib[4];
+ size_t len;
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_PROC;
+ mib[3] = ppid;
if (shell != NULL && stat(shell, &st) != -1) {
struct stat st1;
- strcpy(procdir+l, "file");
- /* $SHELL is actual shell? */
- if (stat(procdir, &st1) != -1 && memcmp(&st, &st1, sizeof st) == 0)
- return getshellbyname(shell);
- }
- strcpy(procdir+l, "status");
- if (stat(procdir, &st) == 0 && (fp = fopen(procdir, "r")) != NULL) {
- char * p = fgets(buf, sizeof buf, fp)==NULL ? NULL : strtok(buf, " \t");
- fclose(fp);
- if (p != NULL)
- return getshellbyname(p);
+ mib[2] = KERN_PROC_PATHNAME;
+ len = sizeof(path);
+ if (sysctl(mib, 4, path, &len, NULL, 0) != -1) {
+ /* $SHELL is actual shell? */
+ if (stat(path, &st1) != -1 && memcmp(&st, &st1, sizeof st) == 0)
+ return getshellbyname(shell);
+ }
}
+ mib[2] = KERN_PROC_PID;
+ len = sizeof(kp);
+ if (sysctl(mib, 4, &kp, &len, NULL, 0) != -1)
+ return getshellbyname(kp.ki_comm);
}
return SH_SH;
}