[Midnightbsd-cvs] src [11452] trunk/usr.bin/rctl/rctl.c: sync rctl with freebsd.
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sat Jul 7 12:44:27 EDT 2018
Revision: 11452
http://svnweb.midnightbsd.org/src/?rev=11452
Author: laffer1
Date: 2018-07-07 12:44:26 -0400 (Sat, 07 Jul 2018)
Log Message:
-----------
sync rctl with freebsd.
Modified Paths:
--------------
trunk/usr.bin/rctl/Makefile
trunk/usr.bin/rctl/rctl.8
trunk/usr.bin/rctl/rctl.c
Property Changed:
----------------
trunk/usr.bin/rctl/rctl.8
Modified: trunk/usr.bin/rctl/Makefile
===================================================================
--- trunk/usr.bin/rctl/Makefile 2018-07-07 16:44:08 UTC (rev 11451)
+++ trunk/usr.bin/rctl/Makefile 2018-07-07 16:44:26 UTC (rev 11452)
@@ -1,4 +1,5 @@
# $MidnightBSD$
+# $FreeBSD: stable/10/usr.bin/rctl/Makefile 222772 2011-06-06 20:24:17Z ed $
PROG= rctl
MAN= rctl.8
Modified: trunk/usr.bin/rctl/rctl.8
===================================================================
--- trunk/usr.bin/rctl/rctl.8 2018-07-07 16:44:08 UTC (rev 11451)
+++ trunk/usr.bin/rctl/rctl.8 2018-07-07 16:44:26 UTC (rev 11452)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\"-
.\" Copyright (c) 2009 Edward Tomasz Napierala
.\" All rights reserved.
@@ -23,9 +24,9 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.bin/rctl/rctl.8 293681 2016-01-11 19:21:20Z trasz $
.\"
-.Dd December 3, 2012
+.Dd November 5, 2015
.Dt RCTL 8
.Os
.Sh NAME
@@ -38,19 +39,26 @@
.Op Ar filter
.Nm
.Fl a
-.Op Ar rule
+.Ar rule
.Nm
+.Fl l
.Op Fl h
.Op Fl n
-.Fl l
-.Op Ar filter
+.Ar filter
.Nm
.Fl r
-.Op Ar filter
+.Ar filter
.Nm
+.Fl u
.Op Fl h
-.Fl u
-.Op Ar filter
+.Ar filter
+.Pp
+.Nm
+requires the kernel to be compiled with:
+.Bd -ragged -offset indent
+.Cd "options RACCT"
+.Cd "options RCTL"
+.Ed
.Sh DESCRIPTION
When called without options, the
.Nm
@@ -77,8 +85,15 @@
.Ar filter
from the RCTL database.
.It Fl u Ar filter
-Display resource usage for a subject (process, user, login class
-or jail) matching the
+Display resource usage for a subject
+.Po
+.Sy process ,
+.Sy user ,
+.Sy loginclass
+or
+.Sy jail
+.Pc
+matching the
.Ar filter .
.It Fl h
"Human-readable" output.
@@ -87,24 +102,49 @@
.It Fl n
Display user IDs numerically rather than converting them to a user name.
.El
+.Pp
+Modifying rules affects all currently running and future processes matching
+the rule.
.Sh RULE SYNTAX
Syntax for a rule is subject:subject-id:resource:action=amount/per.
.Pp
-Subject defines the kind of entity the rule applies to.
-It can be either process, user, login class, or jail.
-.Pp
-Subject ID identifies the subject.
-It can be a process ID, user name, numerical user ID, login class name,
+.Bl -tag -width "subject-id" -compact -offset indent
+.It subject
+defines the kind of entity the rule applies to.
+It can be either
+.Sy process ,
+.Sy user ,
+.Sy loginclass ,
+or
+.Sy jail .
+.It subject-id
+identifies the
+.Em subject .
+It can be a process ID, user name, numerical user ID, login class name from
+.Xr login.conf 5 ,
or jail name.
-.Pp
-Resource identifies the resource the rule controls.
-.Pp
-Action defines what will happen when a process exceeds the allowed amount.
-.Pp
-Amount defines how much of the resource a process can use before
-the defined action triggers.
-.Pp
-The per field defines what entity the amount gets accounted for.
+.It resource
+identifies the resource the rule controls.
+See the
+.Sx RESOURCES
+section below for details.
+.It action
+defines what will happen when a process exceeds the allowed
+.Em amount .
+See the
+.Sx ACTIONS
+section below for details.
+.It amount
+defines how much of the resource a process can use before
+the defined
+.Em action
+triggers.
+Resources which limit bytes may use prefixes from
+.Xr expand_number 3 .
+.It per
+defines what entity the
+.Em amount
+gets accounted for.
For example, rule "loginclass:users:vmem:deny=100M/process" means
that each process of any user belonging to login class "users" may allocate
up to 100MB of virtual memory.
@@ -114,58 +154,98 @@
Rule "loginclass:users:vmem:deny=100M/loginclass" would mean that the sum of
virtual memory allocated by all processes of all users belonging to that login
class will not exceed 100MB.
+.El
.Pp
-Valid rule has all those fields specified, except for the per, which defaults
-to the value of subject.
+A valid rule has all those fields specified, except for
+.Em per ,
+which defaults
+to the value of
+.Em subject .
.Pp
-A filter is a rule for which one of more fields other than per is left empty.
+A filter is a rule for which one of more fields other than
+.Em per
+is left empty.
For example, a filter that matches every rule could be written as ":::=/",
or, in short, ":".
A filter that matches all the login classes would be "loginclass:".
-A filter that matches all defined rules for maxproc resource would be
+A filter that matches all defined rules for
+.Sy maxproc
+resource would be
"::maxproc".
+.Sh SUBJECTS
+.Bl -column -offset 3n "pseudoterminals" ".Sy username or numerical User ID"
+.It Em subject Ta Em subject-id
+.It Sy process Ta numerical Process ID
+.It Sy user Ta user name or numerical User ID
+.It Sy loginclass Ta login class from
+.Xr login.conf 5
+.It Sy jail Ta jail name
+.El
.Sh RESOURCES
.Bl -column -offset 3n "pseudoterminals"
-.It cputime Ta "CPU time, in seconds"
-.It datasize Ta "data size, in bytes"
-.It stacksize Ta "stack size, in bytes"
-.It coredumpsize Ta "core dump size, in bytes"
-.It memoryuse Ta "resident set size, in bytes"
-.It memorylocked Ta "locked memory, in bytes"
-.It maxproc Ta "number of processes"
-.It openfiles Ta "file descriptor table size"
-.It vmemoryuse Ta "address space limit, in bytes"
-.It pseudoterminals Ta "number of PTYs"
-.It swapuse Ta "swap usage, in bytes"
-.It nthr Ta "number of threads"
-.It msgqqueued Ta "number of queued SysV messages"
-.It msgqsize Ta "SysV message queue size, in bytes"
-.It nmsgq Ta "number of SysV message queues"
-.It nsem Ta "number of SysV semaphores"
-.It nsemop Ta "number of SysV semaphores modified in a single semop(2) call"
-.It nshm Ta "number of SysV shared memory segments"
-.It shmsize Ta "SysV shared memory size, in bytes"
-.It wallclock Ta "wallclock time, in seconds"
-.It pcpu Ta "%CPU, in percents of a single CPU core"
+.It Em resource
+.It Sy cputime Ta "CPU time, in seconds"
+.It Sy datasize Ta "data size, in bytes"
+.It Sy stacksize Ta "stack size, in bytes"
+.It Sy coredumpsize Ta "core dump size, in bytes"
+.It Sy memoryuse Ta "resident set size, in bytes"
+.It Sy memorylocked Ta "locked memory, in bytes"
+.It Sy maxproc Ta "number of processes"
+.It Sy openfiles Ta "file descriptor table size"
+.It Sy vmemoryuse Ta "address space limit, in bytes"
+.It Sy pseudoterminals Ta "number of PTYs"
+.It Sy swapuse Ta "swap space that may be reserved or used, in bytes"
+.It Sy nthr Ta "number of threads"
+.It Sy msgqqueued Ta "number of queued SysV messages"
+.It Sy msgqsize Ta "SysV message queue size, in bytes"
+.It Sy nmsgq Ta "number of SysV message queues"
+.It Sy nsem Ta "number of SysV semaphores"
+.It Sy nsemop Ta "number of SysV semaphores modified in a single semop(2) call"
+.It Sy nshm Ta "number of SysV shared memory segments"
+.It Sy shmsize Ta "SysV shared memory size, in bytes"
+.It Sy wallclock Ta "wallclock time, in seconds"
+.It Sy pcpu Ta "%CPU, in percents of a single CPU core"
.El
.Sh ACTIONS
.Bl -column -offset 3n "pseudoterminals"
-.It deny Ta "deny the allocation; not supported for cpu and wallclock"
-.It log Ta "log a warning to the console"
-.It devctl Ta "send notification to"
+.It Em action
+.It Sy deny Ta deny the allocation; not supported for
+.Sy cputime
+and
+.Sy wallclock
+.It Sy log Ta "log a warning to the console"
+.It Sy devctl Ta "send notification to"
.Xr devd 8
-.It "sig* e.g. sigterm; send a signal to the offending process"
-.El
-.Pp
+using
+.Sy system
+= "RCTL",
+.Sy subsystem
+= "rule",
+.Sy type
+= "matched"
+.It sig* e.g.
+.Sy sigterm ;
+send a signal to the offending process.
See
.Xr signal 3
-for a list of supported signals.
+for a list of supported signals
+.El
.Pp
Not all actions are supported for all resources.
-Attempt to add rule with action not supported by a given resource will result
-in error.
-.Pp
-Note that limiting RSS may kill the machine due to thrashing.
+Attempting to add a rule with an action not supported by a given resource will
+result in error.
+.Sh LOADER TUNABLES
+Tunables can be set at the
+.Xr loader 8
+prompt, or
+.Xr loader.conf 5 .
+.Bl -tag -width indent
+.It Va kern.racct.enable: No 1
+Enable
+.Nm .
+This defaults to 1, unless
+.Cd "options RACCT_DEFAULT_TO_DISABLED"
+is set in the kernel configuration file.
.Sh EXIT STATUS
.Ex -std
.Sh EXAMPLES
@@ -180,6 +260,15 @@
.Pp
Display all the rules applicable to process with PID 512:
.Dl Nm Fl l Ar process:512
+.Pp
+Display all rules:
+.Dl Nm
+.Pp
+Display all rules matching user "joe":
+.Dl Nm Ar user:joe
+.Pp
+Display all rules matching login classes:
+.Dl Nm Ar loginclass:
.Sh SEE ALSO
.Xr rctl.conf 5
.Sh HISTORY
@@ -191,5 +280,10 @@
.An -nosplit
The
.Nm
-command was written by
-.An Edward Tomasz Napierala Aq trasz at FreeBSD.org .
+was developed by
+.An Edward Tomasz Napierala Aq trasz at FreeBSD.org
+under sponsorship from the FreeBSD Foundation.
+.Sh BUGS
+Limiting
+.Sy memoryuse
+may kill the machine due to thrashing.
Property changes on: trunk/usr.bin/rctl/rctl.8
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/rctl/rctl.c
===================================================================
--- trunk/usr.bin/rctl/rctl.c 2018-07-07 16:44:08 UTC (rev 11451)
+++ trunk/usr.bin/rctl/rctl.c 2018-07-07 16:44:26 UTC (rev 11452)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2010 The FreeBSD Foundation
* All rights reserved.
@@ -26,14 +27,15 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.bin/rctl/rctl.c 325847 2017-11-15 12:21:06Z bapt $
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/rctl/rctl.c 325847 2017-11-15 12:21:06Z bapt $");
#include <sys/types.h>
#include <sys/rctl.h>
+#include <sys/sysctl.h>
#include <assert.h>
#include <ctype.h>
#include <err.h>
@@ -47,7 +49,7 @@
#include <stdlib.h>
#include <string.h>
-#define RCTL_DEFAULT_BUFSIZE 4096
+#define RCTL_DEFAULT_BUFSIZE 128 * 1024
static id_t
parse_user(const char *s)
@@ -305,13 +307,37 @@
}
static void
+enosys(void)
+{
+ int error, racct_enable;
+ size_t racct_enable_len;
+
+ racct_enable_len = sizeof(racct_enable);
+ error = sysctlbyname("kern.racct.enable",
+ &racct_enable, &racct_enable_len, NULL, 0);
+
+ if (error != 0) {
+ if (errno == ENOENT)
+ errx(1, "RACCT/RCTL support not present in kernel; see rctl(8) for details");
+
+ err(1, "sysctlbyname");
+ }
+
+ if (racct_enable == 0)
+ errx(1, "RACCT/RCTL present, but disabled; enable using kern.racct.enable=1 tunable");
+}
+
+static void
add_rule(char *rule)
{
int error;
error = rctl_add_rule(rule, strlen(rule) + 1, NULL, 0);
- if (error != 0)
+ if (error != 0) {
+ if (errno == ENOSYS)
+ enosys();
err(1, "rctl_add_rule");
+ }
free(rule);
}
@@ -330,8 +356,11 @@
error = rctl_get_limits(filter, strlen(filter) + 1, outbuf,
outbuflen);
- if (error && errno != ERANGE)
+ if (error && errno != ERANGE) {
+ if (errno == ENOSYS)
+ enosys();
err(1, "rctl_get_limits");
+ }
} while (error && errno == ERANGE);
print_rules(outbuf, hflag, nflag);
@@ -345,8 +374,11 @@
int error;
error = rctl_remove_rule(filter, strlen(filter) + 1, NULL, 0);
- if (error != 0)
+ if (error != 0) {
+ if (errno == ENOSYS)
+ enosys();
err(1, "rctl_remove_rule");
+ }
free(filter);
}
@@ -399,8 +431,11 @@
error = rctl_get_racct(filter, strlen(filter) + 1, outbuf,
outbuflen);
- if (error && errno != ERANGE)
+ if (error && errno != ERANGE) {
+ if (errno == ENOSYS)
+ enosys();
err(1, "rctl_get_racct");
+ }
} while (error && errno == ERANGE);
while ((tmp = strsep(&outbuf, ",")) != NULL) {
@@ -439,8 +474,11 @@
err(1, "realloc");
error = rctl_get_rules(filter, filterlen, outbuf, outbuflen);
- if (error && errno != ERANGE)
+ if (error && errno != ERANGE) {
+ if (errno == ENOSYS)
+ enosys();
err(1, "rctl_get_rules");
+ }
} while (error && errno == ERANGE);
print_rules(outbuf, hflag, nflag);
@@ -457,7 +495,7 @@
}
int
-main(int argc __unused, char **argv __unused)
+main(int argc, char **argv)
{
int ch, aflag = 0, hflag = 0, nflag = 0, lflag = 0, rflag = 0,
uflag = 0;
More information about the Midnightbsd-cvs
mailing list