Skip to content
Snippets Groups Projects
Commit d7eaa9c6 authored by Michiel van Baak's avatar Michiel van Baak
Browse files

Fix compilation on FreeBSD and OSX

This started as work to fix the 'core show sysinfo'
CLI command but while working on it oej
pointed out that read_credentials did not compile neither.
So while being there, fix that as well.

Thanks for all the testing oej!

(closes issue #14129)
Reported by: ys
Tested by: oej, mvanbaak


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@168609 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent 72fc03b6
Branches
Tags
No related merge requests found
...@@ -81,6 +81,12 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") ...@@ -81,6 +81,12 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#elif defined(HAVE_SYSCTL) #elif defined(HAVE_SYSCTL)
#include <sys/param.h> #include <sys/param.h>
#include <sys/sysctl.h> #include <sys/sysctl.h>
#if !defined(__OpenBSD__)
#include <sys/vmmeter.h>
#if defined(__FreeBSD__)
#include <vm/vm_param.h>
#endif
#endif
#if defined(HAVE_SWAPCTL) #if defined(HAVE_SWAPCTL)
#include <sys/swap.h> #include <sys/swap.h>
#endif #endif
...@@ -552,7 +558,7 @@ static int swapmode(int *used, int *total) ...@@ -552,7 +558,7 @@ static int swapmode(int *used, int *total)
static char *handle_show_sysinfo(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) static char *handle_show_sysinfo(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{ {
int64_t physmem, freeram; int64_t physmem, freeram;
int totalswap, freeswap, nprocs; int totalswap = 0, freeswap = 0, nprocs = 0;
long uptime = 0; long uptime = 0;
#if defined(HAVE_SYSINFO) #if defined(HAVE_SYSINFO)
struct sysinfo sys_info; struct sysinfo sys_info;
...@@ -568,7 +574,7 @@ static char *handle_show_sysinfo(struct ast_cli_entry *e, int cmd, struct ast_cl ...@@ -568,7 +574,7 @@ static char *handle_show_sysinfo(struct ast_cli_entry *e, int cmd, struct ast_cl
struct vmtotal vmtotal; struct vmtotal vmtotal;
struct timeval boottime; struct timeval boottime;
time_t now; time_t now;
int mib[2], pagesize, usedswap; int mib[2], pagesize, usedswap = 0;
size_t len; size_t len;
/* calculate the uptime by looking at boottime */ /* calculate the uptime by looking at boottime */
time(&now); time(&now);
...@@ -581,7 +587,11 @@ static char *handle_show_sysinfo(struct ast_cli_entry *e, int cmd, struct ast_cl ...@@ -581,7 +587,11 @@ static char *handle_show_sysinfo(struct ast_cli_entry *e, int cmd, struct ast_cl
uptime = uptime/3600; uptime = uptime/3600;
/* grab total physical memory */ /* grab total physical memory */
mib[0] = CTL_HW; mib[0] = CTL_HW;
#if defined(__OpenBSD__)
mib[1] = HW_PHYSMEM64; mib[1] = HW_PHYSMEM64;
#else
mib[1] = HW_PHYSMEM;
#endif
len = sizeof(physmem); len = sizeof(physmem);
sysctl(mib, 2, &physmem, &len, NULL, 0); sysctl(mib, 2, &physmem, &len, NULL, 0);
...@@ -605,10 +615,12 @@ static char *handle_show_sysinfo(struct ast_cli_entry *e, int cmd, struct ast_cl ...@@ -605,10 +615,12 @@ static char *handle_show_sysinfo(struct ast_cli_entry *e, int cmd, struct ast_cl
swapmode(&usedswap, &totalswap); swapmode(&usedswap, &totalswap);
freeswap = (totalswap - usedswap); freeswap = (totalswap - usedswap);
/* grab number of processes */ /* grab number of processes */
#if defined(__OpenBSD__)
mib[0] = CTL_KERN; mib[0] = CTL_KERN;
mib[1] = KERN_NPROCS; mib[1] = KERN_NPROCS;
len = sizeof(nprocs); len = sizeof(nprocs);
sysctl(mib, 2, &nprocs, &len, NULL, 0); sysctl(mib, 2, &nprocs, &len, NULL, 0);
#endif
#endif #endif
switch (cmd) { switch (cmd) {
...@@ -1137,7 +1149,13 @@ static int read_credentials(int fd, char *buffer, size_t size, struct console *c ...@@ -1137,7 +1149,13 @@ static int read_credentials(int fd, char *buffer, size_t size, struct console *c
struct ucred cred; struct ucred cred;
socklen_t len = sizeof(cred); socklen_t len = sizeof(cred);
#endif #endif
int result, uid, gid; #if defined(HAVE_GETPEEREID)
uid_t uid;
gid_t gid;
#else
int uid, gid;
#endif
int result;
result = read(fd, buffer, size); result = read(fd, buffer, size);
if (result < 0) { if (result < 0) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment