Index: asterisk.c =================================================================== RCS file: /usr/cvsroot/asterisk/asterisk.c,v retrieving revision 1.186 diff -u -r1.186 asterisk.c --- asterisk.c 26 Oct 2005 18:54:24 -0000 1.186 +++ asterisk.c 30 Oct 2005 15:05:55 -0000 @@ -1874,7 +1874,11 @@ option_maxcalls = 0; } } else if (!strcasecmp(v->name, "maxload")) { - if ((sscanf(v->value, "%lf", &option_maxload) != 1) || (option_maxload < 0.0)) { + double test[1]; + if (getloadavg(test, 1) == -1) { + ast_log(LOG_ERROR, "Cannot obtain load average on this system. Maxload disabled.\n"); + option_maxload = 0.0; + } else if ((sscanf(v->value, "%lf", &option_maxload) != 1) || (option_maxload < 0.0)) { option_maxload = 0.0; } } Index: utils.c =================================================================== RCS file: /usr/cvsroot/asterisk/utils.c,v retrieving revision 1.79 diff -u -r1.79 utils.c --- utils.c 26 Oct 2005 18:54:24 -0000 1.79 +++ utils.c 30 Oct 2005 15:05:55 -0000 @@ -691,7 +691,7 @@ return NULL; } } -#endif +#endif /* LINUX */ #ifndef HAVE_STRNLEN size_t strnlen(const char *s, size_t n) @@ -837,6 +837,41 @@ } #endif +#if (!defined(getloadavg)) +#ifdef linux +/* Alternative method of getting load avg on Linux only */ +int getloadavg(double *list, int nelem) +{ + FILE *LOADAVG; + double avg[3] = { 0.0, 0.0, 0.0 }; + int i, res = -1;; + + if ((LOADAVG = fopen("/proc/loadavg", "r"))) { + fscanf(LOADAVG, "%lf %lf %lf", &avg[0], &avg[1], &avg[2]); + res = 0; + fclose(LOADAVG); + } + + for (i = 0; (i < nelem) && (i < 3); i++) { + list[i] = avg[i]; + } + + return res; +} +#else +/* Return something that won't cancel the call, but still return -1, in case + * we correct the implementation to check return value */ +int getloadavg(double *list, int nelem) +{ + int i; + for (i = 0; i < nelem; i++) { + list[i] = 0.1; + } + return -1; +} +#endif +#endif + char *ast_process_quotes_and_slashes(char *start, char find, char replace_with) { char *dataPut = start;