Index: configure =================================================================== --- configure (revision 141463) +++ configure (working copy) @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.ac Revision: 135405 . +# From configure.ac Revision: 136819 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.61 for asterisk 1.6. # @@ -205,7 +205,7 @@ echo as_func_ret_failure succeeded. fi -if ( set x; as_func_ret_success y && test x = \"\$1\" ); then +if (set x; as_func_ret_success y && test x = \"\$1\" ); then : else exitcode=1 @@ -409,7 +409,7 @@ echo as_func_ret_failure succeeded. fi -if ( set x; as_func_ret_success y && test x = \"\$1\" ); then +if (set x; as_func_ret_success y && test x = \"\$1\" ); then : else exitcode=1 @@ -6568,7 +6568,7 @@ GNU_MAKE_VERSION_MINOR=0 ; for a in make gmake gnumake ; do if test -z "$a" ; then continue ; fi ; - if ( sh -c "$a --version" 2> /dev/null | grep GNU 2>&1 > /dev/null ) ; then + if (sh -c "$a --version" 2> /dev/null | grep GNU 2>&1 > /dev/null ) ; then GNU_MAKE=$a ; GNU_MAKE_VERSION_MAJOR=`$GNU_MAKE --version | grep "GNU Make" | cut -f3 -d' ' | cut -f1 -d'.'` GNU_MAKE_VERSION_MINOR=`$GNU_MAKE --version | grep "GNU Make" | cut -f2 -d'.' | cut -c1-2` @@ -15246,7 +15246,8 @@ -for ac_func in asprintf atexit bzero dup2 endpwent ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday inet_ntoa isascii localtime_r memchr memmove memset mkdir munmap putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtol strtoq unsetenv utime vasprintf + +for ac_func in asprintf atexit bzero dup2 endpwent ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday inet_ntoa isascii localtime_r memchr memmove memset mkdir munmap putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtol strtoq sysctl unsetenv utime vasprintf do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` { echo "$as_me:$LINENO: checking for $ac_func" >&5 Index: configure.ac =================================================================== --- configure.ac (revision 141463) +++ configure.ac (working copy) @@ -313,7 +313,7 @@ AC_FUNC_STRTOD AC_FUNC_UTIME_NULL AC_FUNC_VPRINTF -AC_CHECK_FUNCS([asprintf atexit bzero dup2 endpwent ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday inet_ntoa isascii localtime_r memchr memmove memset mkdir munmap putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtol strtoq unsetenv utime vasprintf]) +AC_CHECK_FUNCS([asprintf atexit bzero dup2 endpwent ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday inet_ntoa isascii localtime_r memchr memmove memset mkdir munmap putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtol strtoq sysctl unsetenv utime vasprintf]) AC_CHECK_FUNCS([glob]) Index: include/asterisk/autoconfig.h.in =================================================================== --- include/asterisk/autoconfig.h.in (revision 141463) +++ include/asterisk/autoconfig.h.in (working copy) @@ -907,6 +907,9 @@ /* Define to indicate the ${SUPPSERV_DESCRIP} library version */ #undef HAVE_SUPPSERV_VERSION +/* Define to 1 if you have the `sysctl' function. */ +#undef HAVE_SYSCTL + /* Define to 1 if your system has sysinfo support */ #undef HAVE_SYSINFO Index: main/asterisk.c =================================================================== --- main/asterisk.c (revision 141463) +++ main/asterisk.c (working copy) @@ -72,6 +72,10 @@ #include #if defined(HAVE_SYSINFO) #include +#elif defined(HAVE_SYSCTL) +#include +#include +#include #endif #include @@ -476,11 +480,110 @@ return CLI_SUCCESS; } -#if defined(HAVE_SYSINFO) +#if defined (HAVE_SYSCTL) +/* + * swapmode is rewritten by Tobias Weingartner + * to be based on the new swapctl(2) system call. + */ +static int swapmode(int *used, int *total) +{ + struct swapent *swdev; + int nswap, rnswap, i; + + nswap = swapctl(SWAP_NSWAP, 0, 0); + if (nswap == 0) + return 0; + + swdev = calloc(nswap, sizeof(*swdev)); + if (swdev == NULL) + return 0; + + rnswap = swapctl(SWAP_STATS, swdev, nswap); + if (rnswap == -1) { + free(swdev); + return 0; + } + + /* if rnswap != nswap, then what? */ + + /* Total things up */ + *total = *used = 0; + for (i = 0; i < nswap; i++) { + if (swdev[i].se_flags & SWF_ENABLE) { + *used += (swdev[i].se_inuse / (1024 / DEV_BSIZE)); + *total += (swdev[i].se_nblks / (1024 / DEV_BSIZE)); + } + } + free(swdev); + return 1; +} +#endif + /*! \brief Give an overview of system statistics */ static char *handle_show_sysinfo(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { + int64_t physmem, freeram; + int totalswap, freeswap, nprocs; + long uptime = 0; +#if defined(HAVE_SYSINFO) struct sysinfo sys_info; + sysinfo(&sys_info) + uptime = sys_info.uptime/3600; + physmem = sys_info.totalram * sys_info.mem_unit; + freeram = (sys_info.freeram * sys_info.mem_unit)/1024; + totalswap = (sys_info.totalswap * sys_info.mem_unit)/1024; + freeswap = (sys_info.freeswap * sys_info.mem_unit)/1024; + nprocs = sys_info.nprocs; +#elif defined(HAVE_SYSCTL) + static int pageshift; + struct vmtotal vmtotal; + struct timeval boottime; + time_t now; + int mib[2], pagesize, usedswap; + /* , nprocs, swapused, swaptotal; + */ + size_t len; + /* calculate the uptime by looking at boottime */ + (void)time(&now); + mib[0] = CTL_KERN; + mib[1] = KERN_BOOTTIME; + len = sizeof(boottime); + if (sysctl(mib, 2, &boottime, &len, NULL, 0) != -1) { + uptime = now - boottime.tv_sec; + } + uptime = uptime/3600; + /* grab total physical memory */ + mib[0] = CTL_HW; + mib[1] = HW_PHYSMEM64; + len = sizeof(physmem); + sysctl(mib, 2, &physmem, &len, NULL, 0); + + pagesize = getpagesize(); + pageshift = 0; + while (pagesize > 1) { + pageshift++; + pagesize >>= 1; + } + + /* we only need the amount of log(2)1024 for our conversion */ + pageshift -= 10; + + /* grab vm totals */ + mib[0] = CTL_VM; + mib[1] = VM_METER; + len = sizeof(vmtotal); + sysctl(mib, 2, &vmtotal, &len, NULL, 0); + freeram = (vmtotal.t_free << pageshift); + /* generate swap usage and totals */ + swapmode(&usedswap, &totalswap); + freeswap = (totalswap-usedswap); + /* grab number of processes */ + mib[0] = CTL_KERN; + mib[1] = KERN_NPROCS; + len = sizeof(nprocs); + sysctl(mib, 2, &nprocs, &len, NULL, 0); +#endif + switch (cmd) { case CLI_INIT: e->command = "core show sysinfo"; @@ -491,22 +594,20 @@ case CLI_GENERATE: return NULL; } - if (sysinfo(&sys_info)) { - ast_cli(a->fd, "FAILED to retrieve system information\n\n"); - return CLI_FAILURE; - } + ast_cli(a->fd, "\nSystem Statistics\n"); ast_cli(a->fd, "-----------------\n"); - ast_cli(a->fd, " System Uptime: %ld hours\n", sys_info.uptime/3600); - ast_cli(a->fd, " Total RAM: %ld KiB\n", (sys_info.totalram * sys_info.mem_unit)/1024); - ast_cli(a->fd, " Free RAM: %ld KiB\n", (sys_info.freeram * sys_info.mem_unit)/1024); + ast_cli(a->fd, " System Uptime: %ld hours\n", uptime); + ast_cli(a->fd, " Total RAM: %ld KiB\n", (long)physmem/1024); + ast_cli(a->fd, " Free RAM: %ld KiB\n", (long)freeram); +#if defined(HAVE_SYSINFO) ast_cli(a->fd, " Buffer RAM: %ld KiB\n", (sys_info.bufferram * sys_info.mem_unit)/1024); - ast_cli(a->fd, " Total Swap Space: %ld KiB\n", (sys_info.totalswap * sys_info.mem_unit)/1024); - ast_cli(a->fd, " Free Swap Space: %ld KiB\n\n", (sys_info.freeswap * sys_info.mem_unit)/1024); - ast_cli(a->fd, " Number of Processes: %d \n\n", sys_info.procs); +#endif + ast_cli(a->fd, " Total Swap Space: %ld KiB\n", (long)totalswap); + ast_cli(a->fd, " Free Swap Space: %ld KiB\n\n", (long)freeswap); + ast_cli(a->fd, " Number of Processes: %d \n\n", nprocs); return CLI_SUCCESS; } -#endif struct profile_entry { const char *name; @@ -1890,7 +1991,7 @@ #if !defined(LOW_MEMORY) AST_CLI_DEFINE(handle_show_version_files, "List versions of files used to build Asterisk"), AST_CLI_DEFINE(handle_show_threads, "Show running threads"), -#if defined(HAVE_SYSINFO) +#if defined(HAVE_SYSINFO) || defined(HAVE_SYSCTL) AST_CLI_DEFINE(handle_show_sysinfo, "Show System Information"), #endif AST_CLI_DEFINE(handle_show_profile, "Display profiling info"),