summaryrefslogtreecommitdiffstats
path: root/service
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2014-02-24 17:42:57 +0100
committerFelix Fietkau <nbd@openwrt.org>2014-02-24 17:42:59 +0100
commit0dc263af065cb1e38f3b41dfd80198eae1b81172 (patch)
tree0fd437bf65080c749ff595c963d48d1102fd45b0 /service
parent3a225cfa1782763980c86e9811c683ade33012cc (diff)
downloadunitd-0dc263af065cb1e38f3b41dfd80198eae1b81172.tar
unitd-0dc263af065cb1e38f3b41dfd80198eae1b81172.zip
instance: improve portability of setting resource limits
the data type varies for different implementations Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Diffstat (limited to 'service')
-rw-r--r--service/instance.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/service/instance.c b/service/instance.c
index 3e784bf..1b28a7a 100644
--- a/service/instance.c
+++ b/service/instance.c
@@ -91,6 +91,7 @@ instance_limits(const char *limit, const char *value)
{
int i;
struct rlimit rlim;
+ unsigned long cur, max;
for (i = 0; rlimit_names[i].name != NULL; i++) {
if (strcmp(rlimit_names[i].name, limit))
@@ -98,10 +99,20 @@ instance_limits(const char *limit, const char *value)
if (!strcmp(value, "unlimited")) {
rlim.rlim_cur = RLIM_INFINITY;
rlim.rlim_max = RLIM_INFINITY;
+ } else {
+ if (getrlimit(rlimit_names[i].resource, &rlim))
+ return;
+
+ cur = rlim.rlim_cur;
+ max = rlim.rlim_max;
+
+ if (sscanf(value, "%lu %lu", &cur, &max) < 1)
+ return;
+
+ rlim.rlim_cur = cur;
+ rlim.rlim_max = max;
}
- else if (getrlimit(rlimit_names[i].resource, &rlim) ||
- sscanf(value, "%lu %lu", &rlim.rlim_cur, &rlim.rlim_max) == 0)
- return;
+
setrlimit(rlimit_names[i].resource, &rlim);
return;
}