instance: improve portability of setting resource limits
authorFelix Fietkau <nbd@openwrt.org>
Mon, 24 Feb 2014 16:42:57 +0000 (17:42 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Mon, 24 Feb 2014 16:42:59 +0000 (17:42 +0100)
the data type varies for different implementations

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
service/instance.c

index 3e784bfc0dca029805b8d64d2bf8e148795ca22a..1b28a7a2407eaa38529affa277371a170b9bf27c 100644 (file)
@@ -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;
        }