xref: /xnu-11215.81.4/tests/proc_rlimit.c (revision d4514f0bc1d3f944c22d92e68b646ac3fb40d452)
1*d4514f0bSApple OSS Distributions /*
2*d4514f0bSApple OSS Distributions  * cd $XNU/tests
3*d4514f0bSApple OSS Distributions  * xcrun -sdk macosx.internal/iphoneos.internal make proc_rlimit LDFLAGS="-ldarwintest"
4*d4514f0bSApple OSS Distributions  */
5*d4514f0bSApple OSS Distributions #include <stdio.h>
6*d4514f0bSApple OSS Distributions #include <unistd.h>
7*d4514f0bSApple OSS Distributions #include <sys/resource.h>
8*d4514f0bSApple OSS Distributions #include <errno.h>
9*d4514f0bSApple OSS Distributions #include <sys/sysctl.h>
10*d4514f0bSApple OSS Distributions #include <darwintest.h>
11*d4514f0bSApple OSS Distributions 
12*d4514f0bSApple OSS Distributions /* Defined in <sys/resource.h> but not visible to user space */
13*d4514f0bSApple OSS Distributions #define RLIMIT_NLIMITS 9
14*d4514f0bSApple OSS Distributions 
15*d4514f0bSApple OSS Distributions /* Defined in <sys/resource.h> and visible to user space */
16*d4514f0bSApple OSS Distributions static const char *RESOURCE_STRING[] = {
17*d4514f0bSApple OSS Distributions 	"RLIMIT_CPU",     /* #define RLIMIT_CPU      0 */
18*d4514f0bSApple OSS Distributions 	"RLIMIT_FSIZE",   /* #define RLIMIT_FSIZE    1 */
19*d4514f0bSApple OSS Distributions 	"RLIMIT_DATA",    /* #define RLIMIT_DATA     2 */
20*d4514f0bSApple OSS Distributions 	"RLIMIT_STACK",   /* #define RLIMIT_STACK    3 */
21*d4514f0bSApple OSS Distributions 	"RLIMIT_CORE",    /* #define RLIMIT_CORE     4 */
22*d4514f0bSApple OSS Distributions 	"RLIMIT_AS/RSS",  /* #define RLIMIT_AS       5 */
23*d4514f0bSApple OSS Distributions 	/* #define RLIMIT_RSS      RLIMIT_AS */
24*d4514f0bSApple OSS Distributions 	"RLIMIT_MEMLOCK", /* #define RLIMIT_MEMLOCK  6 */
25*d4514f0bSApple OSS Distributions 	"RLIMIT_NPROC",   /* #define RLIMIT_NPROC    7 */
26*d4514f0bSApple OSS Distributions 	"RLIMIT_NOFILE"   /* #define RLIMIT_NOFILE   8 */
27*d4514f0bSApple OSS Distributions };
28*d4514f0bSApple OSS Distributions 
29*d4514f0bSApple OSS Distributions /* Change limit values by this arbitrary amount */
30*d4514f0bSApple OSS Distributions #define LIMIT_DIFF 64
31*d4514f0bSApple OSS Distributions 
32*d4514f0bSApple OSS Distributions /* Limit type */
33*d4514f0bSApple OSS Distributions #define SOFT_LIMIT 0
34*d4514f0bSApple OSS Distributions #define HARD_LIMIT 1
35*d4514f0bSApple OSS Distributions 
36*d4514f0bSApple OSS Distributions /* Action on changing limit values */
37*d4514f0bSApple OSS Distributions #define LOWER 0
38*d4514f0bSApple OSS Distributions #define RAISE 1
39*d4514f0bSApple OSS Distributions 
40*d4514f0bSApple OSS Distributions static struct rlimit orig_rlimit[RLIMIT_NLIMITS];
41*d4514f0bSApple OSS Distributions 
42*d4514f0bSApple OSS Distributions /* Maximum number of open files allowed by normal user */
43*d4514f0bSApple OSS Distributions static rlim_t maxfilesperproc;
44*d4514f0bSApple OSS Distributions static size_t maxfilesperproc_size = sizeof(maxfilesperproc);
45*d4514f0bSApple OSS Distributions 
46*d4514f0bSApple OSS Distributions /* Maximum number of open files allowed by super user */
47*d4514f0bSApple OSS Distributions static rlim_t maxfiles;
48*d4514f0bSApple OSS Distributions static size_t maxfiles_size = sizeof(maxfiles);
49*d4514f0bSApple OSS Distributions 
50*d4514f0bSApple OSS Distributions /* Maximum number of simultaneous processes allowed by normal user */
51*d4514f0bSApple OSS Distributions static rlim_t maxprocperuid;
52*d4514f0bSApple OSS Distributions static size_t maxprocperuid_size = sizeof(maxprocperuid);
53*d4514f0bSApple OSS Distributions 
54*d4514f0bSApple OSS Distributions /* Maximum number of simultaneous processes allowed by super user */
55*d4514f0bSApple OSS Distributions static rlim_t maxproc;
56*d4514f0bSApple OSS Distributions static size_t maxproc_size = sizeof(maxproc);
57*d4514f0bSApple OSS Distributions 
58*d4514f0bSApple OSS Distributions static bool superuser = FALSE;
59*d4514f0bSApple OSS Distributions 
60*d4514f0bSApple OSS Distributions static int
get_initial_rlimits(void)61*d4514f0bSApple OSS Distributions get_initial_rlimits(void)
62*d4514f0bSApple OSS Distributions {
63*d4514f0bSApple OSS Distributions 	int err = -1;
64*d4514f0bSApple OSS Distributions 	int i;
65*d4514f0bSApple OSS Distributions 
66*d4514f0bSApple OSS Distributions 	for (i = 0; i < RLIMIT_NLIMITS; i++) {
67*d4514f0bSApple OSS Distributions 		err = getrlimit(i, &orig_rlimit[i]);
68*d4514f0bSApple OSS Distributions 		T_QUIET; T_EXPECT_EQ(0, err, "getrlimit(%15s, soft: 0x%16llx, hard 0x%16llx) %s", RESOURCE_STRING[i], orig_rlimit[i].rlim_cur, orig_rlimit[i].rlim_max, err == 0 ? "" : strerror(errno));
69*d4514f0bSApple OSS Distributions 	}
70*d4514f0bSApple OSS Distributions 	return err;
71*d4514f0bSApple OSS Distributions }
72*d4514f0bSApple OSS Distributions 
73*d4514f0bSApple OSS Distributions static void
print_rlimits(bool initial_limits)74*d4514f0bSApple OSS Distributions print_rlimits(bool initial_limits)
75*d4514f0bSApple OSS Distributions {
76*d4514f0bSApple OSS Distributions 	int err;
77*d4514f0bSApple OSS Distributions 	int i;
78*d4514f0bSApple OSS Distributions 
79*d4514f0bSApple OSS Distributions 	for (i = 0; i < RLIMIT_NLIMITS; i++) {
80*d4514f0bSApple OSS Distributions 		struct rlimit lim;
81*d4514f0bSApple OSS Distributions 
82*d4514f0bSApple OSS Distributions 		if (initial_limits) {
83*d4514f0bSApple OSS Distributions 			lim = orig_rlimit[i];
84*d4514f0bSApple OSS Distributions 		} else {
85*d4514f0bSApple OSS Distributions 			err = getrlimit(i, &lim);
86*d4514f0bSApple OSS Distributions 			T_QUIET; T_EXPECT_EQ(0, err, "getrlimit(%15s, soft: 0x%16llx, hard 0x%16llx) %s", RESOURCE_STRING[i], lim.rlim_cur, lim.rlim_max, err == 0 ? "" : strerror(errno));
87*d4514f0bSApple OSS Distributions 		}
88*d4514f0bSApple OSS Distributions 		T_LOG("%35s soft: 0x%16llx hard 0x%16llx", RESOURCE_STRING[i], lim.rlim_cur, lim.rlim_max);
89*d4514f0bSApple OSS Distributions 	}
90*d4514f0bSApple OSS Distributions }
91*d4514f0bSApple OSS Distributions 
92*d4514f0bSApple OSS Distributions /*
93*d4514f0bSApple OSS Distributions  * Change "limit_type" of all of the process's "rlimit" by amount
94*d4514f0bSApple OSS Distributions  *
95*d4514f0bSApple OSS Distributions  * limit_type: SOFT_LIMIT/HARD_LIMIT
96*d4514f0bSApple OSS Distributions  * amount:     rlim_t
97*d4514f0bSApple OSS Distributions  * action:     RAISE/LOWER
98*d4514f0bSApple OSS Distributions  */
99*d4514f0bSApple OSS Distributions static void
change_rlimits(int limit_type,rlim_t amount,int action)100*d4514f0bSApple OSS Distributions change_rlimits(int limit_type, rlim_t amount, int action)
101*d4514f0bSApple OSS Distributions {
102*d4514f0bSApple OSS Distributions 	int err = -1;
103*d4514f0bSApple OSS Distributions 	int i;
104*d4514f0bSApple OSS Distributions 
105*d4514f0bSApple OSS Distributions 	for (i = 0; i < RLIMIT_NLIMITS; i++) {
106*d4514f0bSApple OSS Distributions 		struct rlimit newlim;     // for setrlimit
107*d4514f0bSApple OSS Distributions 		struct rlimit verifylim;  // for getrlimit
108*d4514f0bSApple OSS Distributions 		bool expect_failure = FALSE;
109*d4514f0bSApple OSS Distributions 		int expect_errno = 0;
110*d4514f0bSApple OSS Distributions 
111*d4514f0bSApple OSS Distributions 		/* Get the current limit values */
112*d4514f0bSApple OSS Distributions 		err = getrlimit(i, &newlim);
113*d4514f0bSApple OSS Distributions 		T_EXPECT_EQ(0, err, "getrlimit(%15s, soft: 0x%16llx, hard 0x%16llx) %s", RESOURCE_STRING[i], newlim.rlim_cur, newlim.rlim_max, err == 0 ? "" : strerror(errno));
114*d4514f0bSApple OSS Distributions 
115*d4514f0bSApple OSS Distributions 		/* Changing soft limit */
116*d4514f0bSApple OSS Distributions 		if (limit_type == SOFT_LIMIT) {
117*d4514f0bSApple OSS Distributions 			if (action == RAISE) {
118*d4514f0bSApple OSS Distributions 				/* Raising soft limits to exceed hard limits is not allowed and we expect to see failure on setrlimit call later */
119*d4514f0bSApple OSS Distributions 				if (newlim.rlim_cur + amount > newlim.rlim_max) {
120*d4514f0bSApple OSS Distributions 					expect_failure = TRUE;
121*d4514f0bSApple OSS Distributions 					expect_errno = EINVAL;
122*d4514f0bSApple OSS Distributions 				}
123*d4514f0bSApple OSS Distributions 				newlim.rlim_cur += amount;
124*d4514f0bSApple OSS Distributions 			} else if (action == LOWER) {
125*d4514f0bSApple OSS Distributions 				if (newlim.rlim_cur == 0) {
126*d4514f0bSApple OSS Distributions 					/* Soft limit might be 0 already, if so skip lowering it */
127*d4514f0bSApple OSS Distributions 				} else {
128*d4514f0bSApple OSS Distributions 					newlim.rlim_cur -= amount;
129*d4514f0bSApple OSS Distributions 				}
130*d4514f0bSApple OSS Distributions 			} else {
131*d4514f0bSApple OSS Distributions 				T_FAIL("Unknown action on soft limit: %d", action);
132*d4514f0bSApple OSS Distributions 			}
133*d4514f0bSApple OSS Distributions 		}
134*d4514f0bSApple OSS Distributions 		/* Changing hard limit */
135*d4514f0bSApple OSS Distributions 		else if (limit_type == HARD_LIMIT) {
136*d4514f0bSApple OSS Distributions 			if (action == RAISE) {
137*d4514f0bSApple OSS Distributions 				newlim.rlim_max += amount;
138*d4514f0bSApple OSS Distributions 
139*d4514f0bSApple OSS Distributions 				/* Raising hard limits is not allowed for normal user and we expect to see failure on setrlimit call later */
140*d4514f0bSApple OSS Distributions 				expect_failure = TRUE;
141*d4514f0bSApple OSS Distributions 				expect_errno = EPERM;
142*d4514f0bSApple OSS Distributions 			} else if (action == LOWER) {
143*d4514f0bSApple OSS Distributions 				if (newlim.rlim_max == 0) {
144*d4514f0bSApple OSS Distributions 					/* Hard limit might be 0 already, if so skip lowering it (e.g., RLIMIT_CORE on iOS) */
145*d4514f0bSApple OSS Distributions 				} else {
146*d4514f0bSApple OSS Distributions 					newlim.rlim_max -= amount;
147*d4514f0bSApple OSS Distributions 				}
148*d4514f0bSApple OSS Distributions 				/* Soft limit might need to be changed as well since soft cannot be greater than hard  */
149*d4514f0bSApple OSS Distributions 				if (newlim.rlim_cur > newlim.rlim_max) {
150*d4514f0bSApple OSS Distributions 					newlim.rlim_cur = newlim.rlim_max;
151*d4514f0bSApple OSS Distributions 				}
152*d4514f0bSApple OSS Distributions 			} else {
153*d4514f0bSApple OSS Distributions 				T_FAIL("Unknown action on hard limit: %d", action);
154*d4514f0bSApple OSS Distributions 			}
155*d4514f0bSApple OSS Distributions 		}
156*d4514f0bSApple OSS Distributions 		/* Changing unknown limit type */
157*d4514f0bSApple OSS Distributions 		else {
158*d4514f0bSApple OSS Distributions 			T_FAIL("Unknown limit type: %d", limit_type);
159*d4514f0bSApple OSS Distributions 		}
160*d4514f0bSApple OSS Distributions 
161*d4514f0bSApple OSS Distributions 		/* Request the kernel to change limit values */
162*d4514f0bSApple OSS Distributions 		err = setrlimit(i, &newlim);
163*d4514f0bSApple OSS Distributions 
164*d4514f0bSApple OSS Distributions 		if (expect_failure) {
165*d4514f0bSApple OSS Distributions 			/* We expect the setrlimit call to fail */
166*d4514f0bSApple OSS Distributions 			T_EXPECT_EQ(-1, err, "setrlimit(%15s, soft: 0x%16llx, hard 0x%16llx) failed as expected: %s", RESOURCE_STRING[i], newlim.rlim_cur, newlim.rlim_max, strerror(errno));
167*d4514f0bSApple OSS Distributions 			T_EXPECT_EQ(expect_errno, errno, "Expect errno %d, errno returned %d", expect_errno, errno);
168*d4514f0bSApple OSS Distributions 			continue;
169*d4514f0bSApple OSS Distributions 		} else {
170*d4514f0bSApple OSS Distributions 			T_EXPECT_EQ(0, err, "setrlimit(%15s, soft: 0x%16llx, hard 0x%16llx) %s", RESOURCE_STRING[i], newlim.rlim_cur, newlim.rlim_max, err == 0 ? "" : strerror(errno));
171*d4514f0bSApple OSS Distributions 		}
172*d4514f0bSApple OSS Distributions 
173*d4514f0bSApple OSS Distributions 		/* Verify the kernel correctly changed the limit values */
174*d4514f0bSApple OSS Distributions 		err = getrlimit(i, &verifylim);
175*d4514f0bSApple OSS Distributions 		T_EXPECT_EQ(0, err, "getrlimit(%15s, soft: 0x%16llx, hard 0x%16llx) %s", RESOURCE_STRING[i], verifylim.rlim_cur, verifylim.rlim_max, err == 0 ? "" : strerror(errno));
176*d4514f0bSApple OSS Distributions 
177*d4514f0bSApple OSS Distributions 		/* The kernel forces the hard limit of RLIMIT_NOFILE to be at most maxfileperproc for normal user when changing the hard limit with setrlimit */
178*d4514f0bSApple OSS Distributions 		if (i == RLIMIT_NOFILE && limit_type == HARD_LIMIT && newlim.rlim_max > maxfilesperproc) {
179*d4514f0bSApple OSS Distributions 			if (newlim.rlim_cur != verifylim.rlim_cur ||
180*d4514f0bSApple OSS Distributions 			    maxfilesperproc != verifylim.rlim_max) {
181*d4514f0bSApple OSS Distributions 				T_FAIL("Mismatch limit values %s despite a successful setrlimit call (setrlimit'd soft 0x%16llx hard 0x%16llx but getrlimit'd soft 0x%16llx hard 0x%16llx)",
182*d4514f0bSApple OSS Distributions 				    RESOURCE_STRING[i], newlim.rlim_cur, newlim.rlim_max, verifylim.rlim_cur, verifylim.rlim_max);
183*d4514f0bSApple OSS Distributions 			}
184*d4514f0bSApple OSS Distributions 		}
185*d4514f0bSApple OSS Distributions 		/* The kernel forces the hard limit of RLIMIT_NPROC to be at most maxproc for normal user when changing either soft/hard limit with setrlimit */
186*d4514f0bSApple OSS Distributions 		else if (i == RLIMIT_NPROC && newlim.rlim_max > maxprocperuid) {
187*d4514f0bSApple OSS Distributions 			if (newlim.rlim_cur != verifylim.rlim_cur ||
188*d4514f0bSApple OSS Distributions 			    maxprocperuid != verifylim.rlim_max) {
189*d4514f0bSApple OSS Distributions 				T_FAIL("Mismatch limit values %s despite a successful setrlimit call (setrlimit'd soft 0x%16llx hard 0x%16llx but getrlimit'd soft 0x%16llx hard 0x%16llx)",
190*d4514f0bSApple OSS Distributions 				    RESOURCE_STRING[i], newlim.rlim_cur, newlim.rlim_max, verifylim.rlim_cur, verifylim.rlim_max);
191*d4514f0bSApple OSS Distributions 			}
192*d4514f0bSApple OSS Distributions 		} else {
193*d4514f0bSApple OSS Distributions 			if (newlim.rlim_cur != verifylim.rlim_cur ||
194*d4514f0bSApple OSS Distributions 			    newlim.rlim_max != verifylim.rlim_max) {
195*d4514f0bSApple OSS Distributions 				T_FAIL("Mismatch limit values %s despite a successful setrlimit call (setrlimit'd soft 0x%16llx hard 0x%16llx but getrlimit'd soft 0x%16llx hard 0x%16llx)",
196*d4514f0bSApple OSS Distributions 				    RESOURCE_STRING[i], newlim.rlim_cur, newlim.rlim_max, verifylim.rlim_cur, verifylim.rlim_max);
197*d4514f0bSApple OSS Distributions 			}
198*d4514f0bSApple OSS Distributions 		}
199*d4514f0bSApple OSS Distributions 	}
200*d4514f0bSApple OSS Distributions }
201*d4514f0bSApple OSS Distributions 
202*d4514f0bSApple OSS Distributions T_DECL(proc_rlimit,
203*d4514f0bSApple OSS Distributions     "Test basic functionalities of the getrlimit and setrlimit", T_META_TAG_VM_PREFERRED)
204*d4514f0bSApple OSS Distributions {
205*d4514f0bSApple OSS Distributions 	int err;
206*d4514f0bSApple OSS Distributions 	struct rlimit lim;
207*d4514f0bSApple OSS Distributions 
208*d4514f0bSApple OSS Distributions 	T_SETUPBEGIN;
209*d4514f0bSApple OSS Distributions 
210*d4514f0bSApple OSS Distributions 	if (geteuid() == 0) {
211*d4514f0bSApple OSS Distributions 		superuser = TRUE;
212*d4514f0bSApple OSS Distributions 		T_SKIP("This test should not be run as super user.");
213*d4514f0bSApple OSS Distributions 	}
214*d4514f0bSApple OSS Distributions 
215*d4514f0bSApple OSS Distributions 	/* Use sysctl to query the real limits of RLIMIT_NOFILE/RLIMIT_NPROC for normal user on Apple's systems */
216*d4514f0bSApple OSS Distributions 	err = sysctlbyname("kern.maxfilesperproc", &maxfilesperproc, &maxfilesperproc_size, NULL, 0);
217*d4514f0bSApple OSS Distributions 	T_EXPECT_EQ_INT(0, err, "maxfilesperproc: %llu", maxfilesperproc);
218*d4514f0bSApple OSS Distributions 
219*d4514f0bSApple OSS Distributions 	err = sysctlbyname("kern.maxprocperuid", &maxprocperuid, &maxprocperuid_size, NULL, 0);
220*d4514f0bSApple OSS Distributions 	T_EXPECT_EQ_INT(0, err, "maxprocperuid: %llu", maxprocperuid);
221*d4514f0bSApple OSS Distributions 
222*d4514f0bSApple OSS Distributions 	/* Use sysctl to query the real limits of RLIMIT_NOFILE/RLIMIT_NPROC for super user on Apple's systems (placeholder for adding super user tests) */
223*d4514f0bSApple OSS Distributions 	err = sysctlbyname("kern.maxfiles", &maxfiles, &maxfiles_size, NULL, 0);
224*d4514f0bSApple OSS Distributions 	T_EXPECT_EQ_INT(0, err, "maxfiles: %llu", maxfiles);
225*d4514f0bSApple OSS Distributions 
226*d4514f0bSApple OSS Distributions 	err = sysctlbyname("kern.maxproc", &maxproc, &maxproc_size, NULL, 0);
227*d4514f0bSApple OSS Distributions 	T_EXPECT_EQ_INT(0, err, "maxproc: %llu", maxproc);
228*d4514f0bSApple OSS Distributions 
229*d4514f0bSApple OSS Distributions 	/* Issue getrlimit syscall to retrieve the initial resource limit values before calling setrlimit */
230*d4514f0bSApple OSS Distributions 	err = get_initial_rlimits();
231*d4514f0bSApple OSS Distributions 	T_EXPECT_EQ(0, err, "Obtained initial resource values.");
232*d4514f0bSApple OSS Distributions 
233*d4514f0bSApple OSS Distributions 	/* Print out resource limit values to stdout for less-painful triage in case needed */
234*d4514f0bSApple OSS Distributions 	T_LOG("Resource limits before the test:");
235*d4514f0bSApple OSS Distributions 	print_rlimits(TRUE);
236*d4514f0bSApple OSS Distributions 
237*d4514f0bSApple OSS Distributions 	T_SETUPEND;
238*d4514f0bSApple OSS Distributions 
239*d4514f0bSApple OSS Distributions 	/* Lower soft limits by arbitrary amount */
240*d4514f0bSApple OSS Distributions 	T_LOG("---------Lowering soft limits by 0x%x---------:\n", LIMIT_DIFF);
241*d4514f0bSApple OSS Distributions 	change_rlimits(SOFT_LIMIT, LIMIT_DIFF, LOWER);
242*d4514f0bSApple OSS Distributions 
243*d4514f0bSApple OSS Distributions 	/* Raise soft limits back to the orginal values */
244*d4514f0bSApple OSS Distributions 	T_LOG("---------Raising soft limits by 0x%x---------:\n", LIMIT_DIFF);
245*d4514f0bSApple OSS Distributions 	change_rlimits(SOFT_LIMIT, LIMIT_DIFF, RAISE);
246*d4514f0bSApple OSS Distributions 
247*d4514f0bSApple OSS Distributions 	/* Lower hard limits */
248*d4514f0bSApple OSS Distributions 	T_LOG("---------Lowering hard limits by 0x%x---------:", LIMIT_DIFF);
249*d4514f0bSApple OSS Distributions 	change_rlimits(HARD_LIMIT, LIMIT_DIFF, LOWER);
250*d4514f0bSApple OSS Distributions 
251*d4514f0bSApple OSS Distributions 	/* Raise soft limits to exceed hard limits (setrlimit should fail, but the darwintest should pass) */
252*d4514f0bSApple OSS Distributions 	T_LOG("---------Attempting to raised soft limits by 0x%x to exceed hard limits---------:", LIMIT_DIFF);
253*d4514f0bSApple OSS Distributions 	change_rlimits(SOFT_LIMIT, LIMIT_DIFF, RAISE);
254*d4514f0bSApple OSS Distributions 
255*d4514f0bSApple OSS Distributions 	/* Raise hard limits (setrlimit should fail, but the darwintest should pass) */
256*d4514f0bSApple OSS Distributions 	T_LOG("---------Attempting to raise hard limits by 0x%x---------:", LIMIT_DIFF);
257*d4514f0bSApple OSS Distributions 	change_rlimits(HARD_LIMIT, LIMIT_DIFF, RAISE);
258*d4514f0bSApple OSS Distributions 
259*d4514f0bSApple OSS Distributions 	/* Get and set a non-existing resource limit */
260*d4514f0bSApple OSS Distributions 	T_LOG("---------Accessing a non-existing resource---------:");
261*d4514f0bSApple OSS Distributions 	err = getrlimit(RLIMIT_NLIMITS + 1, &lim);
262*d4514f0bSApple OSS Distributions 	T_EXPECT_EQ(-1, err, "Expect getrlimit to fail when accessing a non-existing resource: %s\n", strerror(errno));
263*d4514f0bSApple OSS Distributions 	T_EXPECT_EQ(EINVAL, errno, "Expect errno %d, errno returned %d", EINVAL, errno);
264*d4514f0bSApple OSS Distributions 
265*d4514f0bSApple OSS Distributions 	err = setrlimit(RLIMIT_NLIMITS + 1, &lim);
266*d4514f0bSApple OSS Distributions 	T_EXPECT_EQ(-1, err, "Expect setrlimit to fail when accessing a non-existing resource: %s\n", strerror(errno));
267*d4514f0bSApple OSS Distributions 	T_EXPECT_EQ(EINVAL, errno, "Expect errno %d, errno returned %d", EINVAL, errno);
268*d4514f0bSApple OSS Distributions 
269*d4514f0bSApple OSS Distributions 	T_LOG("Resource limits after the test:");
270*d4514f0bSApple OSS Distributions 	print_rlimits(FALSE);
271*d4514f0bSApple OSS Distributions }
272