nightly: remove unused BINARCHIVE
[unleashed.git] / share / man / man2 / setrctl.2
bloba5eb6d9ace5624fbad3cc633f9540426b63608da
1 '\" te
2 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH SETRCTL 2 "Jan 31, 2007"
7 .SH NAME
8 setrctl, getrctl \- set or get resource control values
9 .SH SYNOPSIS
10 .LP
11 .nf
12 #include <rctl.h>
14 \fBint\fR \fBsetrctl\fR(\fBconst char *\fR\fIcontrolname\fR, \fBrctlblk_t *\fR\fIold_blk\fR,
15      \fBrctlblk_t *\fR\fInew_blk\fR, \fBuint_t\fR \fIflags\fR);
16 .fi
18 .LP
19 .nf
20 \fBint\fR \fBgetrctl\fR(\fBconst char *\fR\fIcontrolname\fR, \fBrctlblk_t *\fR\fIold_blk\fR,
21      \fBrctlblk_t *\fR\fInew_blk\fR, \fBuint_t\fR \fIflags\fR);
22 .fi
24 .SH DESCRIPTION
25 .sp
26 .LP
27 The \fBsetrctl()\fR and \fBgetrctl()\fR functions provide interfaces for the
28 modification and retrieval of resource control (rctl) values on active entities
29 on the system, such as processes, tasks, or projects.  All resource controls
30 are unsigned 64-bit integers; however, a collection of flags are defined that
31 modify which rctl value is to be set or retrieved.
32 .sp
33 .LP
34 Resource controls are restricted to three levels: basic controls that can be
35 modified by the owner of the calling process, privileged controls that can be
36 modified only by privileged callers, and system controls that are fixed for the
37 duration of the operating system instance.  Setting or retrieving each of these
38 controls is performed by setting the privilege field of the resource control
39 block to \fBRCTL_BASIC\fR, \fBRCTL_PRIVILEGED\fR, or \fBRCTL_SYSTEM\fR with
40 \fBrctlblk_set_privilege()\fR (see \fBrctlblk_set_value\fR(3C)).
41 .sp
42 .LP
43 For limits on collective entities such as the task or project, the process ID
44 of the calling process is associated with the resource control value. This ID
45 is available by using \fBrctlblk_get_recipient_pid()\fR (see
46 \fBrctlblk_set_value\fR(3C)). These values are visible only to that process and
47 privileged processes within the collective.
48 .sp
49 .LP
50 The \fBgetrctl()\fR function provides a mechanism for iterating through all of
51 the established values on a resource control.  The iteration is primed by
52 calling \fBgetrctl()\fR with \fIold_blk\fR set to \fINULL\fR, a valid resource
53 control block pointer in \fInew_blk\fR, and specifying \fBRCTL_FIRST\fR in the
54 \fIflags\fR argument.  Once a resource control block has been obtained,
55 repeated calls to \fBgetrctl()\fR with \fBRCTL_NEXT\fR in the \fIflags\fR
56 argument and the obtained control in the \fIold_blk\fR argument will return the
57 next resource control block in the sequence.  The iteration reports the end of
58 the sequence by failing and setting \fBerrno\fR to \fBENOENT\fR.
59 .sp
60 .LP
61 The \fBgetrctl()\fR function allows the calling process to get the current
62 usage of a controlled resource using \fBRCTL_USAGE\fR as the \fIflags\fR value.
63 The current value of the resource usage is placed in the value field of the
64 resource control block specified by \fInew_blk\fR. This value is obtained with
65 \fBrctlblk_set_value\fR(3C). All other members of the returned block are
66 undefined and might be invalid.
67 .sp
68 .LP
69 The \fBsetrctl()\fR function allows the creation, modification, or deletion of
70 action-value pairs on a given resource control.  When passed \fBRCTL_INSERT\fR
71 as the \fIflags\fR value, \fBsetrctl()\fR expects \fInew_blk\fR to contain a
72 new action-value pair for insertion into the sequence. For \fBRCTL_DELETE\fR,
73 the block indicated by \fInew_blk\fR is deleted from the sequence. For
74 \fBRCTL_REPLACE\fR, the block matching \fIold_blk\fR is deleted and replaced by
75 the block indicated by \fInew_blk\fR. When (\fIflags\fR &
76 \fBRCTL_USE_RECIPIENT_PID\fR) is non-zero, \fBsetrctl()\fR uses the process ID
77 set by \fBrctlblk_set_value\fR(3C) when selecting the rctl value to insert,
78 delete, or replace basic rctls. Otherwise, the process ID of the calling
79 process is used.
80 .sp
81 .LP
82 The kernel maintains a history of which resource control values have triggered
83 for a particular entity, retrievable from a resource control block with the
84 \fBrctlblk_set_value\fR(3C) function. The insertion or deletion of a resource
85 control value at or below the currently enforced value might cause the
86 currently enforced value to be reset.  In the case of insertion, the newly
87 inserted value becomes the actively enforced value.  All higher values that
88 have previously triggered will have their firing times zeroed.  In the case of
89 deletion of the currently enforced value, the next higher value becomes the
90 actively enforced value.
91 .sp
92 .LP
93 The various resource control block properties are described on the
94 \fBrctlblk_set_value\fR(3C) manual page.
95 .sp
96 .LP
97 Resource controls are inherited from the predecessor process or task.  One of
98 the \fBexec\fR(2) functions can modify the resource controls of a process by
99 resetting their histories, as noted above for insertion or deletion operations.
100 .SH RETURN VALUES
103 Upon successful completion, the \fBsetrctl()\fR and \fBgetrctl()\fR functions
104 return 0. Otherwise they return \(mi1 and set \fBerrno\fR to indicate the
105 error.
106 .SH ERRORS
109 The \fBsetrctl()\fR and \fBgetrctl()\fR functions will fail if:
111 .ne 2
113 \fB\fBEFAULT\fR\fR
115 .RS 12n
116 The \fIcontrolname\fR, \fIold_blk\fR, or \fInew_blk\fR argument points to an
117 illegal address.
121 .ne 2
123 \fB\fBEINVAL\fR\fR
125 .RS 12n
126 No resource control with the given name is known to the system, or the resource
127 control block contains properties that are not valid for the resource control
128 specified.
130 \fBRCTL_USE_RECIPIENT_PID\fR was used to set a process scope rctl and the
131 process ID set by \fBrctlblk_set_value\fR(3C) does not match the process ID of
132 calling process.
136 .ne 2
138 \fB\fBENOENT\fR\fR
140 .RS 12n
141 No value beyond the given resource control block exists.
143 \fBRCTL_USE_RECIPIENT_PID\fR was used and the process ID set by
144 \fBrctlblk_set_value\fR(3C) does not exist within the current task, project, or
145 zone, depending on the resource control name.
149 .ne 2
151 \fB\fBESRCH\fR\fR
153 .RS 12n
154 No value matching the given resource control block was found for any of
155 \fBRCTL_NEXT\fR, \fBRCTL_DELETE\fR, or \fBRCTL_REPLACE\fR.
159 .ne 2
161 \fB\fBENOTSUPP\fR\fR
163 .RS 12n
164 The resource control requested by \fBRCTL_USAGE\fR does not support the usage
165 operation.
170 The \fBsetrctl()\fR function will fail if:
172 .ne 2
174 \fB\fBEACCES\fR\fR
176 .RS 10n
177 The rctl value specified cannot be changed by the current process, including
178 the case where the recipient process ID does not match the calling process and
179 the calling process is unprivileged.
183 .ne 2
185 \fB\fBEPERM\fR\fR
187 .RS 10n
188 An attempt to set a system limit was attempted.
191 .SH EXAMPLES
193 \fBExample 1 \fRRetrieve a rctl value.
196 Obtain the lowest enforced rctl value on the rctl limiting the number of LWPs
197 in a task.
200 .in +2
202 #include <rctl.h>
203 #include <stdio.h>
204 #include <stdlib.h>
205 #include <string.h>
206 #include <errno.h>
208 \&...
210 rctlblk_t *rblk;
212 if ((rblk = (rctlblk_t *)malloc(rctlblk_size())) == NULL) {
213         (void) fprintf(stderr, "malloc failed: %s\en",
214             strerror(errno));
215         exit(1);
218 if (getrctl("task.max-lwps", NULL, rblk, RCTL_FIRST) == -1)
219         (void) fprintf(stderr, "failed to get rctl: %s\en",
220             strerror(errno));
221 else
222         (void) printf("task.max-lwps = %llu\en",
223             rctlblk_get_value(rblk));
225 .in -2
227 .SH USAGE
230 Resource control blocks are matched on the value and privilege fields.
231 Resource control operations act on the first matching resource control block.
232 Duplicate resource control blocks are not permitted. Multiple blocks of equal
233 value and privilege need to be entirely deleted and reinserted, rather than
234 replaced, to have the correct outcome. Resource control blocks are sorted such
235 that all blocks with the same value that lack the \fBRCTL_LOCAL_DENY\fR flag
236 precede those having that flag set.
239 Only one \fBRCPRIV_BASIC\fR resource control value is permitted per process per
240 control.  Insertion of an \fBRCPRIV_BASIC\fR value will cause any existing
241 \fBRCPRIV_BASIC\fR value owned by that process on the control to be deleted.
244 The resource control facility provides the backend implementation for both
245 \fBsetrctl()\fR/\fBgetrctl()\fR and \fBsetrlimit()\fR/\fBgetrlimit()\fR. The
246 facility behaves consistently when either of these interfaces is used
247 exclusively; when using both interfaces, the caller must be aware of the
248 ordering issues above, as well as the limit equivalencies described in the
249 following paragraph.
252 The hard and soft process limits made available with \fBsetrlimit()\fR and
253 \fBgetrlimit()\fR are mapped to the resource controls implementation.  (New
254 process resource controls will not be made available with the rlimit
255 interface.)  Because of the \fBRCTL_INSERT\fR and \fBRCTL_DELETE\fR operations,
256 it is possible that the set of values defined on a resource control has more or
257 fewer than the two values defined for an rlimit.  In this case, the soft limit
258 is the lowest priority resource control value with the \fBRCTL_LOCAL_DENY\fR
259 flag set, and the hard limit is the resource control value with the lowest
260 priority equal to or exceeding \fBRCPRIV_PRIVILEGED\fR with the
261 \fBRCTL_LOCAL_DENY\fR flag set.  If no identifiable soft limit exists on the
262 resource control and \fBsetrlimit()\fR is called, a new resource control value
263 is created.  If a resource control does not have the global
264 \fBRCTL_GLOBAL_LOWERABLE\fR property set, its hard limit will not allow
265 lowering by unprivileged callers.
266 .SH ATTRIBUTES
269 See \fBattributes\fR(5) for descriptions of the following attributes:
274 box;
275 c | c
276 l | l .
277 ATTRIBUTE TYPE  ATTRIBUTE VALUE
279 MT-Level        Async-Signal-Safe
282 .SH SEE ALSO
285 \fBrctladm\fR(8), \fBgetrlimit\fR(2), \fBerrno\fR(3C),
286 \fBrctlblk_set_value\fR(3C), \fBattributes\fR(5), \fBresource_controls\fR(5)