jengelh-datetimespielwiese
Last change
on this file since ff8e86 was
ff8e86,
checked in by Andreas Steenpass <steenpass@…>, 9 years ago
|
fix: avoid int overflow in rlimit.c
(cherry picked from commit 6ace3051babf6d4083ff3aabc1f7e6885356e220)
Signed-off-by: Andreas Steenpass <steenpass@mathematik.uni-kl.de>
|
-
Property mode set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /*************************************************************** |
---|
5 | * File: rlimit.c |
---|
6 | * Purpose: set resource limits |
---|
7 | ***************************************************************/ |
---|
8 | |
---|
9 | #include <stdint.h> |
---|
10 | #include <sys/resource.h> |
---|
11 | |
---|
12 | #include "rlimit.h" |
---|
13 | |
---|
14 | /* raise the maximum number of processes (or threads), |
---|
15 | * return 0 on success, |
---|
16 | * -1 on error |
---|
17 | */ |
---|
18 | int raise_rlimit_nproc() |
---|
19 | { |
---|
20 | #ifdef RLIMIT_NPROC |
---|
21 | struct rlimit nproc; |
---|
22 | getrlimit(RLIMIT_NPROC, &nproc); |
---|
23 | if (nproc.rlim_cur == RLIM_INFINITY |
---|
24 | || (nproc.rlim_max != RLIM_INFINITY && nproc.rlim_cur >= nproc.rlim_max)) |
---|
25 | { |
---|
26 | return(-1); |
---|
27 | } |
---|
28 | if (nproc.rlim_cur < 512) |
---|
29 | { |
---|
30 | nproc.rlim_cur = 512; |
---|
31 | } |
---|
32 | if ((nproc.rlim_max == RLIM_INFINITY || 2*nproc.rlim_cur <= nproc.rlim_max) |
---|
33 | && nproc.rlim_cur < 65536) |
---|
34 | { |
---|
35 | nproc.rlim_cur = 2*nproc.rlim_cur; |
---|
36 | } |
---|
37 | else |
---|
38 | { |
---|
39 | nproc.rlim_cur = nproc.rlim_max; |
---|
40 | } |
---|
41 | int res = setrlimit(RLIMIT_NPROC, &nproc); |
---|
42 | return(res); |
---|
43 | #else |
---|
44 | return(-1); |
---|
45 | #endif |
---|
46 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.