summaryrefslogtreecommitdiff
path: root/src/misc/setrlimit.c
blob: bf03fe6f4e9e32c2bd45a32d35de598539ea766e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <sys/resource.h>
#include <errno.h>
#include "syscall.h"
#include "libc.h"

int __setrlimit(int resource, const struct rlimit *rlim)
{
	long k_rlim[2] = { rlim->rlim_cur, rlim->rlim_max };
	return __syscall(SYS_setrlimit, resource, k_rlim);
}

struct ctx {
	const struct rlimit *rlim;
	int res;
	int err;
};

static void do_setrlimit(void *p)
{
	struct ctx *c = p;
	if (c->err) return;
	c->err = -__setrlimit(c->res, c->rlim);
}

int setrlimit(int resource, const struct rlimit *rlim)
{
	struct ctx c = { .res = resource, .rlim = rlim };
	__synccall(do_setrlimit, &c);
	if (c.err) {
		errno = c.err;
		return -1;
	}
	return 0;
}

LFS64(setrlimit);