Allow limitation by loadavg not just calls (should be BSD friendly)...
[asterisk/asterisk.git] / asterisk.c
index 4c3bef8..1596959 100755 (executable)
@@ -143,6 +143,7 @@ int option_overrideconfig = 0;
 int option_reconnect = 0;
 int option_transcode_slin = 1;
 int option_maxcalls = 0;
+double option_maxload = 0.0;
 int option_dontwarn = 0;
 int option_priority_jumping = 1;
 int fully_booted = 0;
@@ -1872,6 +1873,10 @@ static void ast_readconfig(void) {
                        if ((sscanf(v->value, "%d", &option_maxcalls) != 1) || (option_maxcalls < 0)) {
                                option_maxcalls = 0;
                        }
+               } else if (!strcasecmp(v->name, "maxload")) {
+                       if ((sscanf(v->value, "%lf", &option_maxload) != 1) || (option_maxload < 0.0)) {
+                               option_maxload = 0.0;
+                       }
                }
                v = v->next;
        }
@@ -1930,7 +1935,7 @@ int main(int argc, char *argv[])
        }
        */
        /* Check for options */
-       while((c=getopt(argc, argv, "tThfdvVqprRgcinx:U:G:C:M:")) != -1) {
+       while((c=getopt(argc, argv, "tThfdvVqprRgcinx:U:G:C:L:M:")) != -1) {
                switch(c) {
                case 'd':
                        option_debug++;
@@ -1966,6 +1971,10 @@ int main(int argc, char *argv[])
                        if ((sscanf(optarg, "%d", &option_maxcalls) != 1) || (option_maxcalls < 0))
                                option_maxcalls = 0;
                        break;
+               case 'L':
+                       if ((sscanf(optarg, "%lf", &option_maxload) != 1) || (option_maxload < 0.0))
+                               option_maxload = 0.0;
+                       break;
                case 'q':
                        option_quiet++;
                        break;