From 0dc263af065cb1e38f3b41dfd80198eae1b81172 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Mon, 24 Feb 2014 17:42:57 +0100 Subject: instance: improve portability of setting resource limits the data type varies for different implementations Signed-off-by: Felix Fietkau --- service/instance.c | 17 ++++++++++++++--- 1 file 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; } -- cgit v1.2.3