Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / lib / libproc / common / pr_getrlimit.c
blob027523dfc6346306272e25e5830778a6b010220f
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright (c) 1997-2000 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <errno.h>
30 #include <sys/resource.h>
31 #include "libproc.h"
34 * getrlimit() system call -- executed by subject process.
36 int
37 pr_getrlimit(struct ps_prochandle *Pr,
38 int resource, struct rlimit *rlp)
40 sysret_t rval; /* return value from getrlimit() */
41 argdes_t argd[2]; /* arg descriptors for getrlimit() */
42 argdes_t *adp;
43 int sysnum;
44 int error;
46 if (Pr == NULL) /* no subject process */
47 return (getrlimit(resource, rlp));
49 adp = &argd[0]; /* resource argument */
50 adp->arg_value = resource;
51 adp->arg_object = NULL;
52 adp->arg_type = AT_BYVAL;
53 adp->arg_inout = AI_INPUT;
54 adp->arg_size = 0;
56 adp++; /* rlp argument */
57 adp->arg_value = 0;
58 adp->arg_object = rlp;
59 adp->arg_type = AT_BYREF;
60 adp->arg_inout = AI_OUTPUT;
61 adp->arg_size = sizeof (*rlp);
63 sysnum = SYS_getrlimit;
65 error = Psyscall(Pr, &rval, sysnum, 2, &argd[0]);
67 if (error) {
68 errno = (error > 0)? error : ENOSYS;
69 return (-1);
71 return (rval.sys_rval1);
75 * setrlimit() system call -- executed by subject process.
77 int
78 pr_setrlimit(struct ps_prochandle *Pr,
79 int resource, const struct rlimit *rlp)
81 sysret_t rval; /* return value from setrlimit() */
82 argdes_t argd[2]; /* arg descriptors for setrlimit() */
83 argdes_t *adp;
84 int sysnum;
85 int error;
87 if (Pr == NULL) /* no subject process */
88 return (setrlimit(resource, rlp));
90 adp = &argd[0]; /* resource argument */
91 adp->arg_value = resource;
92 adp->arg_object = NULL;
93 adp->arg_type = AT_BYVAL;
94 adp->arg_inout = AI_INPUT;
95 adp->arg_size = 0;
97 adp++; /* rlp argument */
98 adp->arg_value = 0;
99 adp->arg_object = (void *)rlp;
100 adp->arg_type = AT_BYREF;
101 adp->arg_inout = AI_INPUT;
102 adp->arg_size = sizeof (*rlp);
104 sysnum = SYS_setrlimit;
106 error = Psyscall(Pr, &rval, sysnum, 2, &argd[0]);
108 if (error) {
109 errno = (error > 0)? error : ENOSYS;
110 return (-1);
112 return (rval.sys_rval1);