summaryrefslogtreecommitdiff
path: root/src/misc/setrlimit.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012-01-20 22:30:52 -0500
committerRich Felker <dalias@aerifal.cx>2012-01-20 22:30:52 -0500
commit5235a2a5a4d372cf7ebda7ccadf0325c7d4bad82 (patch)
tree7a150780fcaa85167a7d920dc2e6855a54bb7f85 /src/misc/setrlimit.c
parent26f38328d66f4bd525e9d21a9245ba4c54d6ca10 (diff)
downloadmusl-5235a2a5a4d372cf7ebda7ccadf0325c7d4bad82.tar.gz
use prlimit syscall for getrlimit/setrlimit
this allows the full range of 64-bit limit arguments even on 32-bit systems. fallback to the old syscalls on old kernels that don't support prlimit.
Diffstat (limited to 'src/misc/setrlimit.c')
-rw-r--r--src/misc/setrlimit.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/misc/setrlimit.c b/src/misc/setrlimit.c
index bf03fe6f..ddc13e98 100644
--- a/src/misc/setrlimit.c
+++ b/src/misc/setrlimit.c
@@ -3,9 +3,15 @@
#include "syscall.h"
#include "libc.h"
+#define MIN(a, b) ((a)<(b) ? (a) : (b))
+
int __setrlimit(int resource, const struct rlimit *rlim)
{
- long k_rlim[2] = { rlim->rlim_cur, rlim->rlim_max };
+ unsigned long k_rlim[2];
+ 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);
return __syscall(SYS_setrlimit, resource, k_rlim);
}