diff options
Diffstat (limited to 'src/misc/setrlimit.c')
-rw-r--r-- | src/misc/setrlimit.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/misc/setrlimit.c b/src/misc/setrlimit.c index ddc13e98..8a1b8cc6 100644 --- a/src/misc/setrlimit.c +++ b/src/misc/setrlimit.c @@ -4,14 +4,22 @@ #include "libc.h" #define MIN(a, b) ((a)<(b) ? (a) : (b)) +#define FIX(x) do{ if ((x)>=SYSCALL_RLIM_INFINITY) (x)=RLIM_INFINITY; }while(0) int __setrlimit(int resource, const struct rlimit *rlim) { unsigned long k_rlim[2]; + struct rlimit tmp; + if (SYSCALL_RLIM_INFINITY != RLIM_INFINITY) { + tmp = *rlim; + FIX(tmp.rlim_cur); + FIX(tmp.rlim_max); + rlim = &tmp; + } int ret = __syscall(SYS_prlimit64, 0, resource, rlim, 0); if (ret != -ENOSYS) return ret; - k_rlim[0] = MIN(rlim->rlim_cur, -1UL); - k_rlim[1] = MIN(rlim->rlim_max, -1UL); + k_rlim[0] = MIN(rlim->rlim_cur, MIN(-1UL, SYSCALL_RLIM_INFINITY)); + k_rlim[1] = MIN(rlim->rlim_max, MIN(-1UL, SYSCALL_RLIM_INFINITY)); return __syscall(SYS_setrlimit, resource, k_rlim); } |