1 #define _GNU_SOURCE
2 #include <sys/resource.h>
3 #include "syscall.h"
4
5 #define FIX(x) do{ if ((x)>=SYSCALL_RLIM_INFINITY) (x)=RLIM_INFINITY; }while(0)
6
prlimit(pid_t pid,int resource,const struct rlimit * new_limit,struct rlimit * old_limit)7 int prlimit(pid_t pid, int resource, const struct rlimit *new_limit, struct rlimit *old_limit)
8 {
9 struct rlimit tmp;
10 int r;
11 if (new_limit && SYSCALL_RLIM_INFINITY != RLIM_INFINITY) {
12 tmp = *new_limit;
13 FIX(tmp.rlim_cur);
14 FIX(tmp.rlim_max);
15 new_limit = &tmp;
16 }
17 r = syscall(SYS_prlimit64, pid, resource, new_limit, old_limit);
18 if (!r && old_limit && SYSCALL_RLIM_INFINITY != RLIM_INFINITY) {
19 FIX(old_limit->rlim_cur);
20 FIX(old_limit->rlim_max);
21 }
22 return r;
23 }
24
25 #undef prlimit64
26 weak_alias(prlimit, prlimit64);
27