4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI"
37 #include <sys/resource.h>
42 * order is important in this table! it is indexed by resource ID.
45 static struct rlimtab
{
50 /* RLIMIT_CPU */ "time", "seconds", 1,
51 /* RLIMIT_FSIZE */ "file", "blocks", 512,
52 /* RLIMIT_DATA */ "data", "kbytes", 1024,
53 /* RLIMIT_STACK */ "stack", "kbytes", 1024,
54 /* RLIMIT_CORE */ "coredump", "blocks", 512,
55 /* RLIMIT_NOFILE */ "nofiles", "descriptors", 1,
56 /* RLIMIT_VMEM */ "memory", "kbytes", 1024,
60 sysulimit(int argc
, char **argv
)
62 extern int opterr
, optind
;
63 int savopterr
, savoptind
, savsp
;
66 char errargs
[PATH_MAX
];
67 int hard
, soft
, cnt
, c
, res
;
68 rlim_t limit
, new_limit
;
70 char resources
[RLIM_NLIMITS
];
72 for (res
= 0; res
< RLIM_NLIMITS
; res
++) {
87 while ((c
= getopt(argc
, argv
, "HSacdfnstv")) != -1) {
96 for (res
= 0; res
< RLIM_NLIMITS
; res
++) {
123 gfailure(usage
, ulimuse
);
131 resources
[res
= RLIMIT_FSIZE
]++;
136 * if out of arguments, then print the specified resources
139 if (optind
== argc
) {
140 if (!hard
&& !soft
) {
143 for (res
= 0; res
< RLIM_NLIMITS
; res
++) {
144 if (resources
[res
] == 0) {
147 if (getrlimit(res
, &rlimit
) < 0) {
151 prs_buff(_gettext(rlimtab
[res
].name
));
153 prs_buff(_gettext(rlimtab
[res
].scale
));
158 if (rlimit
.rlim_cur
== RLIM_INFINITY
) {
159 prs_buff(_gettext("unlimited"));
161 prull_buff(rlimit
.rlim_cur
/
162 rlimtab
[res
].divisor
);
169 if (rlimit
.rlim_max
== RLIM_INFINITY
) {
170 prs_buff(_gettext("unlimited"));
172 prull_buff(rlimit
.rlim_max
/
173 rlimtab
[res
].divisor
);
181 if (cnt
> 1 || optind
+ 1 != argc
) {
182 gfailure(usage
, ulimuse
);
186 if (eq(argv
[optind
], "unlimited")) {
187 limit
= RLIM_INFINITY
;
191 new_limit
= limit
= 0;
193 if (*args
< '0' || *args
> '9') {
194 snprintf(errargs
, PATH_MAX
-1,
195 "%s: %s", argv
[0], args
);
196 failure(errargs
, badnum
);
199 /* Check for overflow! */
200 new_limit
= (limit
* 10) + (*args
- '0');
201 if (new_limit
>= limit
) {
204 snprintf(errargs
, PATH_MAX
-1,
205 "%s: %s", argv
[0], args
);
206 failure(errargs
, badnum
);
211 /* Check for overflow! */
212 new_limit
= limit
* rlimtab
[res
].divisor
;
213 if (new_limit
>= limit
) {
216 snprintf(errargs
, PATH_MAX
-1,
217 "%s: %s", argv
[0], args
);
218 failure(errargs
, badnum
);
223 if (getrlimit(res
, &rlimit
) < 0) {
224 failure(argv
[0], badnum
);
228 if (!hard
&& !soft
) {
233 rlimit
.rlim_max
= limit
;
236 rlimit
.rlim_cur
= limit
;
239 if (setrlimit(res
, &rlimit
) < 0) {
240 snprintf(errargs
, PATH_MAX
-1,
241 "%s: %s", argv
[0], argv
[optind
]);
242 failure(errargs
, badulimit
);