resource_limit unix impl

This commit is contained in:
Doug MacEachern 2005-07-08 01:03:42 +00:00
parent c6959b47e3
commit 9cfd042c6d
1 changed files with 68 additions and 0 deletions

View File

@ -749,6 +749,12 @@ SIGAR_DECLARE(int) sigar_who_list_get(sigar_t *sigar,
{ {
return SIGAR_ENOTIMPL; return SIGAR_ENOTIMPL;
} }
SIGAR_DECLARE(int) sigar_resource_limit_get(sigar_t *sigar,
sigar_resource_limit_t *rlimit)
{
return SIGAR_ENOTIMPL;
}
#else #else
#ifdef __sun #ifdef __sun
@ -815,6 +821,68 @@ int sigar_who_list_get(sigar_t *sigar,
return SIGAR_OK; return SIGAR_OK;
} }
#include <sys/resource.h>
#define OffsetOf(structure, field) \
(size_t)(&((structure *)NULL)->field)
#define RlimitOffsets(field) \
OffsetOf(sigar_resource_limit_t, field##_cur), \
OffsetOf(sigar_resource_limit_t, field##_max)
#define RlimitSet(structure, ptr, val) \
*(sigar_uint64_t *)((char *)structure + (int)(long)ptr) = val
typedef struct {
int resource;
size_t cur;
size_t max;
} rlimit_field_t;
#define RLIMIT_UNSUPPORTED (RLIM_NLIMITS+1)
#ifndef RLIMIT_RSS
#define RLIMIT_RSS RLIMIT_UNSUPPORTED
#endif
static rlimit_field_t sigar_rlimits[] = {
{ RLIMIT_CPU, RlimitOffsets(cpu) },
{ RLIMIT_FSIZE, RlimitOffsets(file_size) },
{ RLIMIT_DATA, RlimitOffsets(data) },
{ RLIMIT_STACK, RlimitOffsets(stack) },
{ RLIMIT_CORE, RlimitOffsets(core) },
{ RLIMIT_RSS, RlimitOffsets(rss) },
{ RLIMIT_NPROC, RlimitOffsets(processes) },
{ RLIMIT_NOFILE, RlimitOffsets(open_files) },
{ RLIMIT_AS, RlimitOffsets(address_space) },
{ -1 }
};
int sigar_resource_limit_get(sigar_t *sigar,
sigar_resource_limit_t *rlimit)
{
int i;
rlimit->unlimited = RLIM_INFINITY;
for (i=0; sigar_rlimits[i].resource != -1; i++) {
struct rlimit rl;
rlimit_field_t *r = &sigar_rlimits[i];
if ((r->resource == RLIMIT_UNSUPPORTED) ||
(getrlimit(r->resource, &rl) != 0))
{
rl.rlim_cur = SIGAR_FIELD_NOTIMPL;
rl.rlim_max = SIGAR_FIELD_NOTIMPL;
}
RlimitSet(rlimit, r->cur, rl.rlim_cur);
RlimitSet(rlimit, r->max, rl.rlim_max);
}
return SIGAR_OK;
}
#endif #endif
void sigar_hwaddr_format(char *buff, unsigned char *ptr) void sigar_hwaddr_format(char *buff, unsigned char *ptr)