From: Felix Fietkau Date: Mon, 24 Feb 2014 16:42:57 +0000 (+0100) Subject: instance: improve portability of setting resource limits X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=0dc263af065cb1e38f3b41dfd80198eae1b81172;p=project%2Fprocd.git instance: improve portability of setting resource limits the data type varies for different implementations Signed-off-by: Felix Fietkau --- 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; }