RLIMIT_NPROC impl for non-linux

This commit is contained in:
Doug MacEachern 2005-07-21 22:46:57 +00:00
parent 2e5bc87f49
commit 76260ce6f3

View File

@ -939,14 +939,12 @@ typedef struct {
size_t max; size_t max;
} rlimit_field_t; } rlimit_field_t;
#define RLIMIT_UNSUPPORTED (RLIM_NLIMITS+1)
#ifndef RLIMIT_RSS #ifndef RLIMIT_RSS
#define RLIMIT_RSS RLIMIT_UNSUPPORTED #define RLIMIT_RSS (RLIM_NLIMITS+1)
#endif #endif
#ifndef RLIMIT_NPROC #ifndef RLIMIT_NPROC
#define RLIMIT_NPROC RLIMIT_UNSUPPORTED #define RLIMIT_NPROC (RLIM_NLIMITS+2)
#endif #endif
static rlimit_field_t sigar_rlimits[] = { static rlimit_field_t sigar_rlimits[] = {
@ -965,6 +963,9 @@ static rlimit_field_t sigar_rlimits[] = {
#define RlimitScale(val) \ #define RlimitScale(val) \
if (val != RLIM_INFINITY) val /= r->factor if (val != RLIM_INFINITY) val /= r->factor
#define RlimitHS(val) \
rl.rlim_cur = rl.rlim_max = (val)
int sigar_resource_limit_get(sigar_t *sigar, int sigar_resource_limit_get(sigar_t *sigar,
sigar_resource_limit_t *rlimit) sigar_resource_limit_t *rlimit)
{ {
@ -976,11 +977,18 @@ int sigar_resource_limit_get(sigar_t *sigar,
struct rlimit rl; struct rlimit rl;
rlimit_field_t *r = &sigar_rlimits[i]; rlimit_field_t *r = &sigar_rlimits[i];
if ((r->resource == RLIMIT_UNSUPPORTED) || if (r->resource > RLIM_NLIMITS) {
(getrlimit(r->resource, &rl) != 0)) switch (r->resource) {
{ case RLIMIT_NPROC:
rl.rlim_cur = RLIM_INFINITY; RlimitHS(sysconf(_SC_CHILD_MAX));
rl.rlim_max = RLIM_INFINITY; break;
default:
RlimitHS(RLIM_INFINITY);
break;
}
}
else if (getrlimit(r->resource, &rl) != 0) {
RlimitHS(RLIM_INFINITY);
} }
else { else {
RlimitScale(rl.rlim_cur); RlimitScale(rl.rlim_cur);