Merge "Fix GCC 8 build issues."
[asterisk/asterisk.git] / funcs / func_sysinfo.c
index b386b9f..5b7c4d8 100644 (file)
@@ -17,7 +17,7 @@
 /*! \file
  *
  * SYSINFO function to return various system data.
- * 
+ *
  * \note Inspiration and Guidance from Russell
  *
  * \author Jeff Peeler
  * \ingroup functions
  */
 
-#include "asterisk.h"
+/*** MODULEINFO
+       <support_level>core</support_level>
+ ***/
 
-ASTERISK_FILE_VERSION(__FILE__, "$Revision: 87233 $")
+#include "asterisk.h"
 
 #if defined(HAVE_SYSINFO)
 #include <sys/sysinfo.h>
@@ -36,6 +38,57 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision: 87233 $")
 #include "asterisk/module.h"
 #include "asterisk/pbx.h"
 
+/*** DOCUMENTATION
+       <function name="SYSINFO" language="en_US">
+               <synopsis>
+                       Returns system information specified by parameter.
+               </synopsis>
+               <syntax>
+                       <parameter name="parameter" required="true">
+                               <enumlist>
+                                       <enum name="loadavg">
+                                               <para>System load average from past minute.</para>
+                                       </enum>
+                                       <enum name="numcalls">
+                                               <para>Number of active calls currently in progress.</para>
+                                       </enum>
+                                       <enum name="uptime">
+                                               <para>System uptime in hours.</para>
+                                               <note><para>This parameter is dependant upon operating system.</para></note>
+                                       </enum>
+                                       <enum name="totalram">
+                                               <para>Total usable main memory size in KiB.</para>
+                                               <note><para>This parameter is dependant upon operating system.</para></note>
+                                       </enum>
+                                       <enum name="freeram">
+                                               <para>Available memory size in KiB.</para>
+                                               <note><para>This parameter is dependant upon operating system.</para></note>
+                                       </enum>
+                                       <enum name="bufferram">
+                                               <para>Memory used by buffers in KiB.</para>
+                                               <note><para>This parameter is dependant upon operating system.</para></note>
+                                       </enum>
+                                       <enum name="totalswap">
+                                               <para>Total swap space still available in KiB.</para>
+                                               <note><para>This parameter is dependant upon operating system.</para></note>
+                                       </enum>
+                                       <enum name="freeswap">
+                                               <para>Free swap space still available in KiB.</para>
+                                               <note><para>This parameter is dependant upon operating system.</para></note>
+                                       </enum>
+                                       <enum name="numprocs">
+                                               <para>Number of current processes.</para>
+                                               <note><para>This parameter is dependant upon operating system.</para></note>
+                                       </enum>
+                               </enumlist>
+                       </parameter>
+               </syntax>
+               <description>
+                       <para>Returns information from a given parameter.</para>
+               </description>
+       </function>
+ ***/
+
 static int sysinfo_helper(struct ast_channel *chan, const char *cmd, char *data,
                                         char *buf, size_t len)
 {
@@ -60,15 +113,15 @@ static int sysinfo_helper(struct ast_channel *chan, const char *cmd, char *data,
        else if (!strcasecmp("uptime", data)) {             /* in hours */
                snprintf(buf, len, "%ld", sys_info.uptime/3600);
        } else if (!strcasecmp("totalram", data)) {         /* in KiB */
-               snprintf(buf, len, "%ld",(sys_info.totalram / sys_info.mem_unit)/1024);
+               snprintf(buf, len, "%lu",(sys_info.totalram * sys_info.mem_unit)/1024);
        } else if (!strcasecmp("freeram", data)) {          /* in KiB */
-               snprintf(buf, len, "%ld",(sys_info.freeram / sys_info.mem_unit)/1024);
+               snprintf(buf, len, "%lu",(sys_info.freeram * sys_info.mem_unit)/1024);
        } else if (!strcasecmp("bufferram", data)) {        /* in KiB */
-               snprintf(buf, len, "%ld",(sys_info.bufferram / sys_info.mem_unit)/1024);
+               snprintf(buf, len, "%lu",(sys_info.bufferram * sys_info.mem_unit)/1024);
        } else if (!strcasecmp("totalswap", data)) {        /* in KiB */
-               snprintf(buf, len, "%ld",(sys_info.totalswap / sys_info.mem_unit)/1024);
+               snprintf(buf, len, "%lu",(sys_info.totalswap * sys_info.mem_unit)/1024);
        } else if (!strcasecmp("freeswap", data)) {         /* in KiB */
-               snprintf(buf, len, "%ld",(sys_info.freeswap / sys_info.mem_unit)/1024);
+               snprintf(buf, len, "%lu",(sys_info.freeswap * sys_info.mem_unit)/1024);
        } else if (!strcasecmp("numprocs", data)) {
                snprintf(buf, len, "%d", sys_info.procs);
        }
@@ -77,29 +130,14 @@ static int sysinfo_helper(struct ast_channel *chan, const char *cmd, char *data,
                ast_log(LOG_ERROR, "Unknown sysinfo parameter type '%s'.\n", data);
                return -1;
        }
-               
+
        return 0;
 }
 
 static struct ast_custom_function sysinfo_function = {
        .name = "SYSINFO",
-       .synopsis = "Returns system information specified by parameter.",
-       .syntax = "SYSINFO(<parameter>)",
        .read = sysinfo_helper,
-       .desc = 
-"Returns information from a given parameter\n"
-"  Options:\n"
-"    loadavg   - system load average from past minute\n"
-"    numcalls  - number of active calls currently in progress\n"
-#if defined(HAVE_SYSINFO)
-"    uptime    - system uptime in hours\n"
-"    totalram  - total usable main memory size in KiB\n"
-"    freeram   - available memory size in KiB\n"
-"    bufferram - memory used by buffers in KiB\n"
-"    totalswap - total swap space size in KiB\n"
-"    freeswap  - free swap space still available in KiB\n"
-"    numprocs  - number of current processes\n",
-#endif /* HAVE_SYSINFO */
+       .read_max = 22,
 };
 
 static int unload_module(void)
@@ -113,4 +151,3 @@ static int load_module(void)
 }
 
 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "System information related functions");
-