]> granicus.if.org Git - strace/blob - tests/setrlimit.c
Update copyright headers
[strace] / tests / setrlimit.c
1 /*
2  * Check decoding of setrlimit syscall.
3  *
4  * Copyright (c) 2016-2018 Dmitry V. Levin <ldv@altlinux.org>
5  * All rights reserved.
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9
10 #include "tests.h"
11 #include <asm/unistd.h>
12
13 #ifdef __NR_setrlimit
14
15 # include "xgetrlimit.c"
16
17 int
18 main(void)
19 {
20         kernel_ulong_t *const rlimit = tail_alloc(sizeof(*rlimit) * 2);
21         const struct xlat *xlat;
22
23         for (xlat = resources; xlat->str; ++xlat) {
24                 unsigned long res = 0xfacefeed00000000ULL | xlat->val;
25                 long rc = syscall(__NR_setrlimit, res, 0);
26                 printf("setrlimit(%s, NULL) = %s\n", xlat->str, sprintrc(rc));
27
28                 struct rlimit libc_rlim = {};
29                 if (getrlimit((int) res, &libc_rlim))
30                         continue;
31                 rlimit[0] = libc_rlim.rlim_cur;
32                 rlimit[1] = libc_rlim.rlim_max;
33
34                 rc = syscall(__NR_setrlimit, res, rlimit);
35                 const char *errstr = sprintrc(rc);
36                 printf("setrlimit(%s, {rlim_cur=%s, rlim_max=%s}) = %s\n",
37                        xlat->str,
38                        sprint_rlim(rlimit[0]), sprint_rlim(rlimit[1]),
39                        errstr);
40         }
41
42         puts("+++ exited with 0 +++");
43         return 0;
44 }
45
46 #else
47
48 SKIP_MAIN_UNDEFINED("__NR_setrlimit")
49
50 #endif