summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorDwayne M. Hubbard <dwayne.hubbard@gmail.com>2007-04-11 20:59:08 +0000
committerDwayne M. Hubbard <dwayne.hubbard@gmail.com>2007-04-11 20:59:08 +0000
commit6a5f3599bb7a75c00e82e831501d7e001e1f30a0 (patch)
tree7b9dbbf4a9b21e666ae7e463f54805043acf2251 /main
parent97d93d091befc9c69ca042c9ff8a4c5ba32c8d1a (diff)
added HAVE_SYSINFO preprocessor directives for portability and general happiness
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@61575 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main')
-rw-r--r--main/asterisk.c16
-rw-r--r--main/pbx.c6
2 files changed, 21 insertions, 1 deletions
diff --git a/main/asterisk.c b/main/asterisk.c
index 66022bf3e..ee4a4125a 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -80,7 +80,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include <grp.h>
#include <pwd.h>
#include <sys/stat.h>
+#if HAVE_SYSINFO
#include <sys/sysinfo.h>
+#endif
#ifdef linux
#include <sys/prctl.h>
#ifdef HAVE_CAP
@@ -164,7 +166,9 @@ int option_debug; /*!< Debug level */
double option_maxload; /*!< Max load avg on system */
int option_maxcalls; /*!< Max number of active calls */
int option_maxfiles; /*!< Max number of open file handles (files, sockets) */
+#if HAVE_SYSINFO
long option_minmemfree; /*!< Minimum amount of free system memory - stop accepting calls if free memory falls below this watermark */
+#endif
/*! @} */
@@ -356,7 +360,9 @@ static int handle_show_settings(int fd, int argc, char *argv[])
ast_cli(fd, " Verbosity: %d\n", option_verbose);
ast_cli(fd, " Debug level: %d\n", option_debug);
ast_cli(fd, " Max load avg: %lf\n", option_maxload);
+#if HAVE_SYSINFO
ast_cli(fd, " Min Free Memory: %ld MB\n", option_minmemfree);
+#endif
if (localtime_r(&ast_startuptime, &tm)) {
strftime(buf, sizeof(buf), "%H:%M:%S", &tm);
ast_cli(fd, " Startup time: %s\n", buf);
@@ -410,6 +416,7 @@ static int handle_show_threads(int fd, int argc, char *argv[])
return 0;
}
+#if HAVE_SYSINFO
static const char show_sysinfo_help[] =
"Usage: core show sysinfo\n"
" List current system information.\n";
@@ -434,6 +441,7 @@ static int handle_show_sysinfo(int fd, int argc, char *argv[])
ast_cli(fd, " Number of Processes: %d \n\n", sys_info.procs);
return 0;
}
+#endif
struct profile_entry {
const char *name;
@@ -1719,9 +1727,11 @@ static struct ast_cli_entry cli_asterisk[] = {
handle_show_threads, "Show running threads",
show_threads_help },
+#if HAVE_SYSINFO
{ { "core", "show", "sysinfo", NULL },
handle_show_sysinfo, "Show System Information",
show_sysinfo_help },
+#endif
{ { "core", "show", "profile", NULL },
handle_show_profile, "Display profiling info",
@@ -2515,12 +2525,14 @@ static void ast_readconfig(void)
ast_copy_string(ast_config_AST_SYSTEM_NAME, v->value, sizeof(ast_config_AST_SYSTEM_NAME));
} else if (!strcasecmp(v->name, "languageprefix")) {
ast_language_is_prefix = ast_true(v->value);
+#if HAVE_SYSINFO
} else if (!strcasecmp(v->name, "minmemfree")) {
/* specify the minimum amount of free memory to retain. Asterisk should stop accepting new calls
* if the amount of free memory falls below this watermark */
if ((sscanf(v->value, "%ld", &option_minmemfree) != 1) || (option_minmemfree < 0)) {
option_minmemfree = 0;
}
+#endif
}
}
ast_config_destroy(cfg);
@@ -2591,13 +2603,15 @@ int main(int argc, char *argv[])
if (getenv("HOME"))
snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
/* Check for options */
- while ((c = getopt(argc, argv, "mtThfFdvVqprRgciInx:U:G:C:L:M:")) != -1) {
+ while ((c = getopt(argc, argv, "mtThfFdvVqprRgciInx:U:G:C:L:M:e:")) != -1) {
switch (c) {
+#if HAVE_SYSINFO
case 'e':
if ((sscanf(optarg, "%ld", &option_minmemfree) != 1) || (option_minmemfree < 0)) {
option_minmemfree = 0;
}
break;
+#endif
#if HAVE_WORKING_FORK
case 'F':
ast_set_flag(&ast_options, AST_OPT_FLAG_ALWAYS_FORK);
diff --git a/main/pbx.c b/main/pbx.c
index 0f82e9a56..c90df8338 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -37,7 +37,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include <time.h>
#include <sys/time.h>
#include <limits.h>
+#if HAVE_SYSINFO
#include <sys/sysinfo.h>
+#endif
#include "asterisk/lock.h"
#include "asterisk/cli.h"
@@ -2453,8 +2455,10 @@ static int increase_call_count(const struct ast_channel *c)
{
int failed = 0;
double curloadavg;
+#if HAVE_SYSINFO
long curfreemem;
struct sysinfo sys_info;
+#endif
ast_mutex_lock(&maxcalllock);
if (option_maxcalls) {
@@ -2470,6 +2474,7 @@ static int increase_call_count(const struct ast_channel *c)
failed = -1;
}
}
+#if HAVE_SYSINFO
if (option_minmemfree) {
if (!sysinfo(&sys_info)) {
/* make sure that the free system memory is above the configured low watermark
@@ -2482,6 +2487,7 @@ static int increase_call_count(const struct ast_channel *c)
}
}
}
+#endif
if (!failed)
countcalls++;