summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2016-02-21 14:56:05 +0000
committerdes <des@FreeBSD.org>2016-02-21 14:56:05 +0000
commit1414d6632bc7eef7ada88e10b487f9431fb28b2e (patch)
tree79987cbd90868289d5b36906a32d45f2342525b9
parentc5bee1a6aa9165429481650fdd1a309113ee83bd (diff)
downloadFreeBSD-src-1414d6632bc7eef7ada88e10b487f9431fb28b2e.zip
FreeBSD-src-1414d6632bc7eef7ada88e10b487f9431fb28b2e.tar.gz
Implement /proc/$$/limits.
PR: 207386 Submitted by: Szymon Śliwa <knight.erraunt@gmail.com> MFC after: 3 weeks
-rw-r--r--sys/compat/linprocfs/linprocfs.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c
index 496afba..86c4b05 100644
--- a/sys/compat/linprocfs/linprocfs.c
+++ b/sys/compat/linprocfs/linprocfs.c
@@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$");
#include <sys/proc.h>
#include <sys/ptrace.h>
#include <sys/resourcevar.h>
+#include <sys/resource.h>
#include <sys/sbuf.h>
#include <sys/sem.h>
#include <sys/smp.h>
@@ -1366,6 +1367,67 @@ linprocfs_dofdescfs(PFS_FILL_ARGS)
return (0);
}
+/*
+ * Filler function for proc/pid/limits
+ */
+
+#define RLIM_NONE -1
+
+static const struct limit_info {
+ const char *desc;
+ const char *unit;
+ unsigned long long rlim_id;
+} limits_info[] = {
+ { "Max cpu time", "seconds", RLIMIT_CPU },
+ { "Max file size", "bytes", RLIMIT_FSIZE },
+ { "Max data size", "bytes", RLIMIT_DATA },
+ { "Max stack size", "bytes", RLIMIT_STACK },
+ { "Max core file size", "bytes", RLIMIT_CORE },
+ { "Max resident set", "bytes", RLIMIT_RSS },
+ { "Max processes", "processes", RLIMIT_NPROC },
+ { "Max open files", "files", RLIMIT_NOFILE },
+ { "Max locked memory", "bytes", RLIMIT_MEMLOCK },
+ { "Max address space", "bytes", RLIMIT_AS },
+ { "Max file locks", "locks", RLIM_INFINITY },
+ { "Max pending signals", "signals", RLIM_INFINITY },
+ { "Max msgqueue size", "bytes", RLIM_NONE },
+ { "Max nice priority", "", RLIM_NONE },
+ { "Max realtime priority", "", RLIM_NONE },
+ { "Max realtime timeout", "us", RLIM_INFINITY },
+ { 0, 0, 0 }
+};
+
+static int
+linprocfs_doproclimits(PFS_FILL_ARGS)
+{
+ const struct limit_info *li;
+ struct rlimit li_rlimits;
+ struct plimit *cur_proc_lim;
+
+ cur_proc_lim = lim_alloc();
+ lim_copy(cur_proc_lim, p->p_limit);
+ sbuf_printf(sb, "%-26s%-21s%-21s%-10s\n", "Limit", "Soft Limit",
+ "Hard Limit", "Units");
+ for (li = limits_info; li->desc != NULL; ++li) {
+ if (li->rlim_id != RLIM_INFINITY && li->rlim_id != RLIM_NONE)
+ li_rlimits = cur_proc_lim->pl_rlimit[li->rlim_id];
+ else {
+ li_rlimits.rlim_cur = 0;
+ li_rlimits.rlim_max = 0;
+ }
+ if (li->rlim_id == RLIM_INFINITY ||
+ li_rlimits.rlim_cur == RLIM_INFINITY)
+ sbuf_printf(sb, "%-26s%-21s%-21s%-10s\n",
+ li->desc, "unlimited", "unlimited", li->unit);
+ else
+ sbuf_printf(sb, "%-26s%-21ld%-21ld%-10s\n",
+ li->desc, (long)li_rlimits.rlim_cur,
+ (long)li_rlimits.rlim_max, li->unit);
+ }
+ lim_free(cur_proc_lim);
+ return (0);
+}
+
/*
* Filler function for proc/sys/kernel/random/uuid
@@ -1504,6 +1566,8 @@ linprocfs_init(PFS_INIT_ARGS)
NULL, NULL, NULL, 0);
pfs_create_file(dir, "auxv", &linprocfs_doauxv,
NULL, &procfs_candebug, NULL, PFS_RD|PFS_RAWRD);
+ pfs_create_file(dir, "limits", &linprocfs_doproclimits,
+ NULL, NULL, NULL, PFS_RD);
/* /proc/scsi/... */
dir = pfs_create_dir(root, "scsi", NULL, NULL, NULL, 0);
OpenPOWER on IntegriCloud