summaryrefslogtreecommitdiff
path: root/usr.bin/limits/limits.c
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/limits.c
parent9d2ab4a62d6733c45958627ac113bdbd818d1e2a (diff)
parentb2ba55951383498f252746f618d513139da06e8e (diff)
downloadsrc-test2-3b8f08459569bf0faa21473e5cec2491e95c9349.tar.gz
src-test2-3b8f08459569bf0faa21473e5cec2491e95c9349.zip
Notes
Diffstat (limited to 'usr.bin/limits/limits.c')
-rw-r--r--usr.bin/limits/limits.c57
1 files changed, 35 insertions, 22 deletions
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;
}