Re-indent machine* files.
This commit is contained in:
@@ -195,7 +195,9 @@ int machine_get_smpload(load_type *result, int *numcpus);
|
|||||||
int machine_get_uptime(double *up, double *idle);
|
int machine_get_uptime(double *up, double *idle);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get network interface status.
|
* Read network interface statistics for a single interface from system and
|
||||||
|
* store results in the struct IfaceInfo.
|
||||||
|
*
|
||||||
* \param interface Pointer where to store interface info.
|
* \param interface Pointer where to store interface info.
|
||||||
* \retval FALSE Error, do not trust the contents of the parameter pointers.
|
* \retval FALSE Error, do not trust the contents of the parameter pointers.
|
||||||
* \retval TRUE OK, parameter pointers are filled with sensible data.
|
* \retval TRUE OK, parameter pointers are filled with sensible data.
|
||||||
|
|||||||
@@ -2,8 +2,11 @@
|
|||||||
* Collects system information on MacOS / Darwin.
|
* Collects system information on MacOS / Darwin.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Copyright (c) 2003 Thomas Runge (coto@core.de)
|
/*-
|
||||||
* Mach and Darwin specific code is Copyright (c) 2006 Eric Pooch (epooch@tenon.com)
|
* Copyright (c) 2003 Thomas Runge (coto@core.de)
|
||||||
|
*
|
||||||
|
* Mach and Darwin specific code is:
|
||||||
|
* Copyright (c) 2006 Eric Pooch (epooch@tenon.com)
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -72,17 +75,20 @@ static int swapmode(int *rettotal, int *retfree);
|
|||||||
static mach_port_t lcdproc_port;
|
static mach_port_t lcdproc_port;
|
||||||
|
|
||||||
|
|
||||||
int machine_init(void)
|
int
|
||||||
|
machine_init(void)
|
||||||
{
|
{
|
||||||
/* get the page size with "getpagesize" and calculate pageshift from it */
|
/*
|
||||||
|
* get the page size with "getpagesize" and calculate pageshift from
|
||||||
|
* it
|
||||||
|
*/
|
||||||
unsigned int pagesize = 0;
|
unsigned int pagesize = 0;
|
||||||
pageshift = 0;
|
pageshift = 0;
|
||||||
|
|
||||||
lcdproc_port = mach_host_self();
|
lcdproc_port = mach_host_self();
|
||||||
host_page_size(lcdproc_port, &pagesize);
|
host_page_size(lcdproc_port, &pagesize);
|
||||||
|
|
||||||
while (pagesize > 1)
|
while (pagesize > 1) {
|
||||||
{
|
|
||||||
pageshift++;
|
pageshift++;
|
||||||
pagesize >>= 1;
|
pagesize >>= 1;
|
||||||
}
|
}
|
||||||
@@ -93,12 +99,14 @@ int machine_init(void)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_close(void)
|
int
|
||||||
|
machine_close(void)
|
||||||
{
|
{
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_battstat(int *acstat, int *battflag, int *percent)
|
int
|
||||||
|
machine_get_battstat(int *acstat, int *battflag, int *percent)
|
||||||
{
|
{
|
||||||
CFTypeRef blob = IOPSCopyPowerSourcesInfo();
|
CFTypeRef blob = IOPSCopyPowerSourcesInfo();
|
||||||
CFArrayRef sources = IOPSCopyPowerSourcesList(blob);
|
CFArrayRef sources = IOPSCopyPowerSourcesList(blob);
|
||||||
@@ -111,29 +119,30 @@ int machine_get_battstat(int *acstat, int *battflag, int *percent)
|
|||||||
*battflag = LCDP_BATT_ABSENT;
|
*battflag = LCDP_BATT_ABSENT;
|
||||||
*percent = 100;
|
*percent = 100;
|
||||||
|
|
||||||
if (CFArrayGetCount(sources) == 0) return(FALSE);
|
if (CFArrayGetCount(sources) == 0)
|
||||||
|
return (FALSE);
|
||||||
|
|
||||||
for (i = 0; i < CFArrayGetCount(sources); i++)
|
for (i = 0; i < CFArrayGetCount(sources); i++) {
|
||||||
{
|
|
||||||
pSource = IOPSGetPowerSourceDescription(blob, CFArrayGetValueAtIndex(sources, i));
|
pSource = IOPSGetPowerSourceDescription(blob, CFArrayGetValueAtIndex(sources, i));
|
||||||
if (!pSource) break;
|
if (!pSource)
|
||||||
|
break;
|
||||||
|
|
||||||
psValue = (CFStringRef) CFDictionaryGetValue(pSource, CFSTR(kIOPSNameKey));
|
psValue = (CFStringRef) CFDictionaryGetValue(pSource, CFSTR(kIOPSNameKey));
|
||||||
|
|
||||||
if (CFDictionaryGetValueIfPresent(pSource, CFSTR(kIOPSIsPresentKey), &psValue) && (CFBooleanGetValue(psValue) > 0))
|
if (CFDictionaryGetValueIfPresent(pSource, CFSTR(kIOPSIsPresentKey), &psValue) && (CFBooleanGetValue(psValue) > 0)) {
|
||||||
{
|
|
||||||
psValue = (CFStringRef) CFDictionaryGetValue(pSource, CFSTR(kIOPSPowerSourceStateKey));
|
psValue = (CFStringRef) CFDictionaryGetValue(pSource, CFSTR(kIOPSPowerSourceStateKey));
|
||||||
|
|
||||||
if (CFStringCompare(psValue,CFSTR(kIOPSBatteryPowerValue),0)==kCFCompareEqualTo)
|
if (CFStringCompare(psValue, CFSTR(kIOPSBatteryPowerValue), 0) == kCFCompareEqualTo) {
|
||||||
{
|
|
||||||
/* We are running on a battery power source. */
|
/* We are running on a battery power source. */
|
||||||
*battflag = LCDP_BATT_UNKNOWN;
|
*battflag = LCDP_BATT_UNKNOWN;
|
||||||
*acstat = LCDP_AC_OFF;
|
*acstat = LCDP_AC_OFF;
|
||||||
}
|
}
|
||||||
else if (CFDictionaryGetValueIfPresent(pSource, CFSTR(kIOPSIsChargingKey), &psValue))
|
else if (CFDictionaryGetValueIfPresent(pSource, CFSTR(kIOPSIsChargingKey), &psValue)) {
|
||||||
{
|
/*
|
||||||
/* We are running on an AC power source,
|
* We are running on an AC power source, but
|
||||||
but we also have a battery power source present. */
|
* we also have a battery power source
|
||||||
|
* present.
|
||||||
|
*/
|
||||||
|
|
||||||
if (CFBooleanGetValue(psValue) > 0)
|
if (CFBooleanGetValue(psValue) > 0)
|
||||||
*battflag = LCDP_BATT_CHARGING;
|
*battflag = LCDP_BATT_CHARGING;
|
||||||
@@ -141,8 +150,7 @@ int machine_get_battstat(int *acstat, int *battflag, int *percent)
|
|||||||
*battflag = LCDP_BATT_UNKNOWN;
|
*battflag = LCDP_BATT_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*battflag != LCDP_BATT_ABSENT)
|
if (*battflag != LCDP_BATT_ABSENT) {
|
||||||
{
|
|
||||||
int curCapacity = 0;
|
int curCapacity = 0;
|
||||||
int maxCapacity = 0;
|
int maxCapacity = 0;
|
||||||
|
|
||||||
@@ -154,9 +162,11 @@ int machine_get_battstat(int *acstat, int *battflag, int *percent)
|
|||||||
|
|
||||||
*percent = (int)((double)curCapacity / (double)maxCapacity * 100);
|
*percent = (int)((double)curCapacity / (double)maxCapacity * 100);
|
||||||
|
|
||||||
/* There is a way to check this through the IOKit,
|
/*
|
||||||
but I am not sure what gets returned for kIOPSLowWarnLevelKey and kIOPSDeadWarnLevelKey,
|
* There is a way to check this through the
|
||||||
and this is easier.
|
* IOKit, but I am not sure what gets
|
||||||
|
* returned for kIOPSLowWarnLevelKey and
|
||||||
|
* kIOPSDeadWarnLevelKey, and this is easier.
|
||||||
*/
|
*/
|
||||||
if (*battflag == LCDP_BATT_UNKNOWN) {
|
if (*battflag == LCDP_BATT_UNKNOWN) {
|
||||||
if (*percent > 50)
|
if (*percent > 50)
|
||||||
@@ -167,7 +177,6 @@ int machine_get_battstat(int *acstat, int *battflag, int *percent)
|
|||||||
*battflag = LCDP_BATT_CRITICAL;
|
*battflag = LCDP_BATT_CRITICAL;
|
||||||
}
|
}
|
||||||
/* printf ("powerSource %d of %d: percent: %d/%d %d\n", i, CFArrayGetCount(sources), curCapacity, maxCapacity, *percent);*/
|
/* printf ("powerSource %d of %d: percent: %d/%d %d\n", i, CFArrayGetCount(sources), curCapacity, maxCapacity, *percent);*/
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -178,20 +187,19 @@ int machine_get_battstat(int *acstat, int *battflag, int *percent)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_fs(mounts_type fs[], int *cnt)
|
int
|
||||||
|
machine_get_fs(mounts_type fs[], int *cnt)
|
||||||
{
|
{
|
||||||
struct statfs *mntbuf;
|
struct statfs *mntbuf;
|
||||||
struct statfs *pp;
|
struct statfs *pp;
|
||||||
int statcnt, fscnt, i;
|
int statcnt, fscnt, i;
|
||||||
|
|
||||||
fscnt = getmntinfo(&mntbuf, MNT_WAIT);
|
fscnt = getmntinfo(&mntbuf, MNT_WAIT);
|
||||||
if (fscnt == 0)
|
if (fscnt == 0) {
|
||||||
{
|
|
||||||
perror("getmntinfo");
|
perror("getmntinfo");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
for (statcnt = 0, pp = mntbuf, i = 0; i < fscnt; pp++, i++)
|
for (statcnt = 0, pp = mntbuf, i = 0; i < fscnt; pp++, i++) {
|
||||||
{
|
|
||||||
if (strcmp(pp->f_fstypename, "procfs")
|
if (strcmp(pp->f_fstypename, "procfs")
|
||||||
&& strcmp(pp->f_fstypename, "kernfs")
|
&& strcmp(pp->f_fstypename, "kernfs")
|
||||||
&& strcmp(pp->f_fstypename, "linprocfs")
|
&& strcmp(pp->f_fstypename, "linprocfs")
|
||||||
@@ -201,15 +209,13 @@ int machine_get_fs(mounts_type fs[], int *cnt)
|
|||||||
#ifndef STAT_SMBFS
|
#ifndef STAT_SMBFS
|
||||||
&& strcmp(pp->f_fstypename, "smbfs")
|
&& strcmp(pp->f_fstypename, "smbfs")
|
||||||
#endif
|
#endif
|
||||||
)
|
) {
|
||||||
{
|
|
||||||
snprintf(fs[statcnt].dev, 255, "%s", pp->f_mntfromname);
|
snprintf(fs[statcnt].dev, 255, "%s", pp->f_mntfromname);
|
||||||
snprintf(fs[statcnt].mpoint, 255, "%s", pp->f_mntonname);
|
snprintf(fs[statcnt].mpoint, 255, "%s", pp->f_mntonname);
|
||||||
snprintf(fs[statcnt].type, 63, "%s", pp->f_fstypename);
|
snprintf(fs[statcnt].type, 63, "%s", pp->f_fstypename);
|
||||||
|
|
||||||
fs[statcnt].blocks = pp->f_blocks;
|
fs[statcnt].blocks = pp->f_blocks;
|
||||||
if (fs[statcnt].blocks > 0)
|
if (fs[statcnt].blocks > 0) {
|
||||||
{
|
|
||||||
fs[statcnt].bsize = pp->f_bsize;
|
fs[statcnt].bsize = pp->f_bsize;
|
||||||
fs[statcnt].bfree = pp->f_bfree;
|
fs[statcnt].bfree = pp->f_bfree;
|
||||||
fs[statcnt].files = pp->f_files;
|
fs[statcnt].files = pp->f_files;
|
||||||
@@ -224,7 +230,8 @@ int machine_get_fs(mounts_type fs[], int *cnt)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_load(load_type *curr_load)
|
int
|
||||||
|
machine_get_load(load_type * curr_load)
|
||||||
{
|
{
|
||||||
static load_type last_load = {0, 0, 0, 0, 0};
|
static load_type last_load = {0, 0, 0, 0, 0};
|
||||||
static load_type last_ret_load;
|
static load_type last_ret_load;
|
||||||
@@ -234,8 +241,7 @@ int machine_get_load(load_type *curr_load)
|
|||||||
mach_msg_type_number_t info_count;
|
mach_msg_type_number_t info_count;
|
||||||
|
|
||||||
info_count = HOST_CPU_LOAD_INFO_COUNT;
|
info_count = HOST_CPU_LOAD_INFO_COUNT;
|
||||||
if (host_statistics(lcdproc_port, HOST_CPU_LOAD_INFO, (host_info_t)&load_info, &info_count))
|
if (host_statistics(lcdproc_port, HOST_CPU_LOAD_INFO, (host_info_t) & load_info, &info_count)) {
|
||||||
{
|
|
||||||
perror("host_statistics");
|
perror("host_statistics");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
@@ -246,8 +252,7 @@ int machine_get_load(load_type *curr_load)
|
|||||||
load.idle = (unsigned long)(load_info.cpu_ticks[CPU_STATE_IDLE]);
|
load.idle = (unsigned long)(load_info.cpu_ticks[CPU_STATE_IDLE]);
|
||||||
load.total = load.user + load.nice + load.system + load.idle;
|
load.total = load.user + load.nice + load.system + load.idle;
|
||||||
|
|
||||||
if (load.total != last_load.total)
|
if (load.total != last_load.total) {
|
||||||
{
|
|
||||||
curr_load->user = load.user - last_load.user;
|
curr_load->user = load.user - last_load.user;
|
||||||
curr_load->nice = load.nice - last_load.nice;
|
curr_load->nice = load.nice - last_load.nice;
|
||||||
curr_load->system = load.system - last_load.system;
|
curr_load->system = load.system - last_load.system;
|
||||||
@@ -256,8 +261,7 @@ int machine_get_load(load_type *curr_load)
|
|||||||
last_ret_load = *curr_load;
|
last_ret_load = *curr_load;
|
||||||
last_load = load;
|
last_load = load;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
*curr_load = last_ret_load;
|
*curr_load = last_ret_load;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,7 +269,8 @@ int machine_get_load(load_type *curr_load)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int machine_get_loadavg(double *load)
|
int
|
||||||
|
machine_get_loadavg(double *load)
|
||||||
{
|
{
|
||||||
double loadavg[LOADAVG_NSTATS];
|
double loadavg[LOADAVG_NSTATS];
|
||||||
|
|
||||||
@@ -277,7 +282,8 @@ int machine_get_loadavg(double *load)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_meminfo(meminfo_type *result)
|
int
|
||||||
|
machine_get_meminfo(meminfo_type * result)
|
||||||
{
|
{
|
||||||
int total_pages, free_pages;
|
int total_pages, free_pages;
|
||||||
|
|
||||||
@@ -285,8 +291,7 @@ int machine_get_meminfo(meminfo_type *result)
|
|||||||
mach_msg_type_number_t info_count;
|
mach_msg_type_number_t info_count;
|
||||||
|
|
||||||
info_count = HOST_VM_INFO_COUNT;
|
info_count = HOST_VM_INFO_COUNT;
|
||||||
if (host_statistics(lcdproc_port, HOST_VM_INFO, (host_info_t)&vm_info, &info_count))
|
if (host_statistics(lcdproc_port, HOST_VM_INFO, (host_info_t) & vm_info, &info_count)) {
|
||||||
{
|
|
||||||
perror("host_statistics");
|
perror("host_statistics");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
@@ -302,8 +307,7 @@ int machine_get_meminfo(meminfo_type *result)
|
|||||||
result[1].total = 0;
|
result[1].total = 0;
|
||||||
result[1].free = 0;
|
result[1].free = 0;
|
||||||
|
|
||||||
if (swapmode(&total_pages, &free_pages) != -1)
|
if (swapmode(&total_pages, &free_pages) != -1) {
|
||||||
{
|
|
||||||
result[1].total = total_pages;
|
result[1].total = total_pages;
|
||||||
result[1].free = free_pages;
|
result[1].free = free_pages;
|
||||||
}
|
}
|
||||||
@@ -311,7 +315,8 @@ int machine_get_meminfo(meminfo_type *result)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_procs(LinkedList *procs)
|
int
|
||||||
|
machine_get_procs(LinkedList * procs)
|
||||||
{
|
{
|
||||||
struct kinfo_proc *kprocs;
|
struct kinfo_proc *kprocs;
|
||||||
|
|
||||||
@@ -322,29 +327,25 @@ int machine_get_procs(LinkedList *procs)
|
|||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
|
|
||||||
/* Call sysctl with a NULL buffer as a dry run. */
|
/* Call sysctl with a NULL buffer as a dry run. */
|
||||||
if ( sysctl(mib, 4, NULL, &size, NULL, 0 ) < 0)
|
if (sysctl(mib, 4, NULL, &size, NULL, 0) < 0) {
|
||||||
{
|
|
||||||
perror("Failure calling sysctl");
|
perror("Failure calling sysctl");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
/* Allocate a buffer based on previous results of sysctl. */
|
/* Allocate a buffer based on previous results of sysctl. */
|
||||||
kprocs = (struct kinfo_proc *)alloca(size);
|
kprocs = (struct kinfo_proc *)alloca(size);
|
||||||
if (kprocs == NULL)
|
if (kprocs == NULL) {
|
||||||
{
|
|
||||||
perror("mem_alloca");
|
perror("mem_alloca");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
/* Call sysctl again with the new buffer. */
|
/* Call sysctl again with the new buffer. */
|
||||||
if ( sysctl(mib, 4, kprocs, &size, NULL, 0 ) < 0)
|
if (sysctl(mib, 4, kprocs, &size, NULL, 0) < 0) {
|
||||||
{
|
|
||||||
perror("Failure calling sysctl");
|
perror("Failure calling sysctl");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
nproc = size / sizeof(struct kinfo_proc);
|
nproc = size / sizeof(struct kinfo_proc);
|
||||||
|
|
||||||
for (i = 0; i < nproc; i++, kprocs++)
|
for (i = 0; i < nproc; i++, kprocs++) {
|
||||||
{
|
|
||||||
mach_port_t task;
|
mach_port_t task;
|
||||||
unsigned int status = kprocs->kp_proc.p_stat;
|
unsigned int status = kprocs->kp_proc.p_stat;
|
||||||
|
|
||||||
@@ -352,8 +353,7 @@ int machine_get_procs(LinkedList *procs)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
p = malloc(sizeof(procinfo_type));
|
p = malloc(sizeof(procinfo_type));
|
||||||
if (!p)
|
if (!p) {
|
||||||
{
|
|
||||||
perror("mem_malloc");
|
perror("mem_malloc");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -369,20 +369,22 @@ int machine_get_procs(LinkedList *procs)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Get the memory data for each pid from Mach. */
|
/* Get the memory data for each pid from Mach. */
|
||||||
if (task_for_pid(mach_task_self(), kprocs->kp_proc.p_pid, &task) == KERN_SUCCESS)
|
if (task_for_pid(mach_task_self(), kprocs->kp_proc.p_pid, &task) == KERN_SUCCESS) {
|
||||||
{
|
|
||||||
task_basic_info_data_t info;
|
task_basic_info_data_t info;
|
||||||
mach_msg_type_number_t count = TASK_BASIC_INFO_COUNT;
|
mach_msg_type_number_t count = TASK_BASIC_INFO_COUNT;
|
||||||
|
|
||||||
if (task_info(task, TASK_BASIC_INFO, (task_info_t) & info, &count) == KERN_SUCCESS) {
|
if (task_info(task, TASK_BASIC_INFO, (task_info_t) & info, &count) == KERN_SUCCESS) {
|
||||||
p->totl = (unsigned long)( /* info.virtual_size */ info.resident_size / 1024);
|
p->totl = (unsigned long)( /* info.virtual_size */ info.resident_size / 1024);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
/* This error pops up very often because of Mac OS X security fixes.
|
else {
|
||||||
It might pop up all of the time on an intel Mac.
|
/*
|
||||||
Basically, we cannot get many tasks unless we are root.
|
* This error pops up very often because of Mac OS X
|
||||||
perror("task_for_pid");
|
* security fixes. It might pop up all of the time on
|
||||||
printf("process: %s, owner:%d\n", kprocs->kp_proc.p_comm, kprocs->kp_eproc.e_pcred.p_ruid); */
|
* an intel Mac. Basically, we cannot get many tasks
|
||||||
|
* unless we are root.
|
||||||
|
*/
|
||||||
|
/* perror("task_for_pid"); */
|
||||||
p->totl = 0;
|
p->totl = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -392,7 +394,8 @@ int machine_get_procs(LinkedList *procs)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_smpload(load_type *result, int *numcpus)
|
int
|
||||||
|
machine_get_smpload(load_type * result, int *numcpus)
|
||||||
{
|
{
|
||||||
int i, num;
|
int i, num;
|
||||||
size_t size;
|
size_t size;
|
||||||
@@ -422,7 +425,8 @@ int machine_get_smpload(load_type *result, int *numcpus)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_uptime(double *up, double *idle)
|
int
|
||||||
|
machine_get_uptime(double *up, double *idle)
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
time_t now;
|
time_t now;
|
||||||
@@ -437,7 +441,6 @@ int machine_get_uptime(double *up, double *idle)
|
|||||||
time(&now);
|
time(&now);
|
||||||
if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 &&
|
if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 &&
|
||||||
boottime.tv_sec != 0)
|
boottime.tv_sec != 0)
|
||||||
|
|
||||||
*up = (double)(now - boottime.tv_sec);
|
*up = (double)(now - boottime.tv_sec);
|
||||||
|
|
||||||
if (machine_get_load(&curr_load) == FALSE)
|
if (machine_get_load(&curr_load) == FALSE)
|
||||||
@@ -448,7 +451,8 @@ int machine_get_uptime(double *up, double *idle)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int swapmode(int *rettotal, int *retfree)
|
static int
|
||||||
|
swapmode(int *rettotal, int *retfree)
|
||||||
{
|
{
|
||||||
#ifdef VM_SWAPUSAGE
|
#ifdef VM_SWAPUSAGE
|
||||||
size_t size;
|
size_t size;
|
||||||
@@ -462,8 +466,7 @@ static int swapmode(int *rettotal, int *retfree)
|
|||||||
*rettotal = 0;
|
*rettotal = 0;
|
||||||
*retfree = 0;
|
*retfree = 0;
|
||||||
|
|
||||||
if (sysctl(mib, 2, &xsu, &size, NULL, 0) != 0)
|
if (sysctl(mib, 2, &xsu, &size, NULL, 0) != 0) {
|
||||||
{
|
|
||||||
perror("sysctl");
|
perror("sysctl");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
@@ -481,7 +484,8 @@ static int swapmode(int *rettotal, int *retfree)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get network statistics */
|
/* Get network statistics */
|
||||||
int machine_get_iface_stats (IfaceInfo *interface)
|
int
|
||||||
|
machine_get_iface_stats(IfaceInfo * interface)
|
||||||
{
|
{
|
||||||
int rows;
|
int rows;
|
||||||
int name[6] = {CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_SYSTEM, IFMIB_IFCOUNT};
|
int name[6] = {CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_SYSTEM, IFMIB_IFCOUNT};
|
||||||
@@ -498,7 +502,10 @@ int machine_get_iface_stats (IfaceInfo *interface)
|
|||||||
name[5] = IFDATA_GENERAL;
|
name[5] = IFDATA_GENERAL;
|
||||||
|
|
||||||
len = sizeof(ifmd);
|
len = sizeof(ifmd);
|
||||||
/* walk through all interfaces in the ifmib table from last to first */
|
/*
|
||||||
|
* walk through all interfaces in the ifmib table from last
|
||||||
|
* to first
|
||||||
|
*/
|
||||||
for (; rows > 0; rows--) {
|
for (; rows > 0; rows--) {
|
||||||
name[4] = rows; /* set the interface index */
|
name[4] = rows; /* set the interface index */
|
||||||
/* retrive the ifmibdata for the current index */
|
/* retrive the ifmibdata for the current index */
|
||||||
@@ -531,11 +538,12 @@ int machine_get_iface_stats (IfaceInfo *interface)
|
|||||||
}
|
}
|
||||||
/* if we are here there is no interface with the given name */
|
/* if we are here there is no interface with the given name */
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
perror("read sysctl IFMIB_IFCOUNT");
|
perror("read sysctl IFMIB_IFCOUNT");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
} /* get_iface_stats() */
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif /* __APPLE__ */
|
#endif /* __APPLE__ */
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
* Collects system information on FreeBSD.
|
* Collects system information on FreeBSD.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Copyright (c) 2003 Thomas Runge (coto@core.de)
|
/*-
|
||||||
|
* Copyright (c) 2003 Thomas Runge (coto@core.de)
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -76,13 +77,16 @@ static kvm_t *kvmd;
|
|||||||
static int swapmode(int *retavail, int *retfree);
|
static int swapmode(int *retavail, int *retfree);
|
||||||
|
|
||||||
|
|
||||||
int machine_init(void)
|
int
|
||||||
|
machine_init(void)
|
||||||
{
|
{
|
||||||
/* get the page size with "getpagesize" and calculate pageshift from it */
|
/*
|
||||||
|
* get the page size with "getpagesize" and calculate pageshift from
|
||||||
|
* it
|
||||||
|
*/
|
||||||
int pagesize = getpagesize();
|
int pagesize = getpagesize();
|
||||||
pageshift = 0;
|
pageshift = 0;
|
||||||
while (pagesize > 1)
|
while (pagesize > 1) {
|
||||||
{
|
|
||||||
pageshift++;
|
pageshift++;
|
||||||
pagesize >>= 1;
|
pagesize >>= 1;
|
||||||
}
|
}
|
||||||
@@ -91,8 +95,7 @@ int machine_init(void)
|
|||||||
pageshift -= 10;
|
pageshift -= 10;
|
||||||
|
|
||||||
/* open kernel virtual memory */
|
/* open kernel virtual memory */
|
||||||
if ((kvmd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) == NULL)
|
if ((kvmd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) == NULL) {
|
||||||
{
|
|
||||||
perror("kvm_open");
|
perror("kvm_open");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
@@ -100,13 +103,15 @@ int machine_init(void)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_close(void)
|
int
|
||||||
|
machine_close(void)
|
||||||
{
|
{
|
||||||
kvm_close(kvmd);
|
kvm_close(kvmd);
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_battstat(int *acstat, int *battflag, int *percent)
|
int
|
||||||
|
machine_get_battstat(int *acstat, int *battflag, int *percent)
|
||||||
{
|
{
|
||||||
*acstat = LCDP_AC_ON;
|
*acstat = LCDP_AC_ON;
|
||||||
*battflag = LCDP_BATT_ABSENT;
|
*battflag = LCDP_BATT_ABSENT;
|
||||||
@@ -116,20 +121,17 @@ int machine_get_battstat(int *acstat, int *battflag, int *percent)
|
|||||||
int apmd;
|
int apmd;
|
||||||
struct apm_info aip;
|
struct apm_info aip;
|
||||||
|
|
||||||
if ((apmd = open("/dev/apm", O_RDONLY)) == -1)
|
if ((apmd = open("/dev/apm", O_RDONLY)) == -1) {
|
||||||
{
|
|
||||||
perror("get_battstat_open");
|
perror("get_battstat_open");
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ioctl(apmd, APMIO_GETINFO, &aip) == -1)
|
if (ioctl(apmd, APMIO_GETINFO, &aip) == -1) {
|
||||||
{
|
|
||||||
perror("get_battstat_ioctl");
|
perror("get_battstat_ioctl");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(aip.ai_acline)
|
switch (aip.ai_acline) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
*acstat = LCDP_AC_OFF;
|
*acstat = LCDP_AC_OFF;
|
||||||
break;
|
break;
|
||||||
@@ -141,8 +143,7 @@ int machine_get_battstat(int *acstat, int *battflag, int *percent)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(aip.ai_batt_stat)
|
switch (aip.ai_batt_stat) {
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
*battflag = LCDP_BATT_HIGH;
|
*battflag = LCDP_BATT_HIGH;
|
||||||
break;
|
break;
|
||||||
@@ -170,20 +171,19 @@ int machine_get_battstat(int *acstat, int *battflag, int *percent)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_fs(mounts_type fs[], int *cnt)
|
int
|
||||||
|
machine_get_fs(mounts_type fs[], int *cnt)
|
||||||
{
|
{
|
||||||
struct statfs *mntbuf;
|
struct statfs *mntbuf;
|
||||||
struct statfs *pp;
|
struct statfs *pp;
|
||||||
int statcnt, fscnt, i;
|
int statcnt, fscnt, i;
|
||||||
|
|
||||||
fscnt = getmntinfo(&mntbuf, MNT_WAIT);
|
fscnt = getmntinfo(&mntbuf, MNT_WAIT);
|
||||||
if (fscnt == 0)
|
if (fscnt == 0) {
|
||||||
{
|
|
||||||
perror("getmntinfo");
|
perror("getmntinfo");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
for (statcnt = 0, pp = mntbuf, i = 0; i < fscnt; pp++, i++)
|
for (statcnt = 0, pp = mntbuf, i = 0; i < fscnt; pp++, i++) {
|
||||||
{
|
|
||||||
if (strcmp(pp->f_fstypename, "procfs")
|
if (strcmp(pp->f_fstypename, "procfs")
|
||||||
&& strcmp(pp->f_fstypename, "devfs")
|
&& strcmp(pp->f_fstypename, "devfs")
|
||||||
&& strcmp(pp->f_fstypename, "kernfs")
|
&& strcmp(pp->f_fstypename, "kernfs")
|
||||||
@@ -194,15 +194,13 @@ int machine_get_fs(mounts_type fs[], int *cnt)
|
|||||||
#ifndef STAT_SMBFS
|
#ifndef STAT_SMBFS
|
||||||
&& strcmp(pp->f_fstypename, "smbfs")
|
&& strcmp(pp->f_fstypename, "smbfs")
|
||||||
#endif
|
#endif
|
||||||
)
|
) {
|
||||||
{
|
|
||||||
snprintf(fs[statcnt].dev, 255, "%s", pp->f_mntfromname);
|
snprintf(fs[statcnt].dev, 255, "%s", pp->f_mntfromname);
|
||||||
snprintf(fs[statcnt].mpoint, 255, "%s", pp->f_mntonname);
|
snprintf(fs[statcnt].mpoint, 255, "%s", pp->f_mntonname);
|
||||||
snprintf(fs[statcnt].type, 63, "%s", pp->f_fstypename);
|
snprintf(fs[statcnt].type, 63, "%s", pp->f_fstypename);
|
||||||
|
|
||||||
fs[statcnt].blocks = pp->f_blocks;
|
fs[statcnt].blocks = pp->f_blocks;
|
||||||
if (fs[statcnt].blocks > 0)
|
if (fs[statcnt].blocks > 0) {
|
||||||
{
|
|
||||||
fs[statcnt].bsize = pp->f_bsize;
|
fs[statcnt].bsize = pp->f_bsize;
|
||||||
fs[statcnt].bfree = pp->f_bfree;
|
fs[statcnt].bfree = pp->f_bfree;
|
||||||
fs[statcnt].files = pp->f_files;
|
fs[statcnt].files = pp->f_files;
|
||||||
@@ -217,7 +215,8 @@ int machine_get_fs(mounts_type fs[], int *cnt)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_load(load_type *curr_load)
|
int
|
||||||
|
machine_get_load(load_type * curr_load)
|
||||||
{
|
{
|
||||||
static load_type last_load = {0, 0, 0, 0, 0};
|
static load_type last_load = {0, 0, 0, 0, 0};
|
||||||
static load_type last_ret_load;
|
static load_type last_ret_load;
|
||||||
@@ -226,8 +225,7 @@ int machine_get_load(load_type *curr_load)
|
|||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
size = sizeof(cp_time);
|
size = sizeof(cp_time);
|
||||||
if (sysctlbyname("kern.cp_time", cp_time, &size, NULL, 0) < 0)
|
if (sysctlbyname("kern.cp_time", cp_time, &size, NULL, 0) < 0) {
|
||||||
{
|
|
||||||
perror("sysctl kern.cp_time failed");
|
perror("sysctl kern.cp_time failed");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
@@ -238,8 +236,7 @@ int machine_get_load(load_type *curr_load)
|
|||||||
load.idle = (unsigned long)(cp_time[CP_IDLE]);
|
load.idle = (unsigned long)(cp_time[CP_IDLE]);
|
||||||
load.total = load.user + load.nice + load.system + load.idle;
|
load.total = load.user + load.nice + load.system + load.idle;
|
||||||
|
|
||||||
if (load.total != last_load.total)
|
if (load.total != last_load.total) {
|
||||||
{
|
|
||||||
curr_load->user = load.user - last_load.user;
|
curr_load->user = load.user - last_load.user;
|
||||||
curr_load->nice = load.nice - last_load.nice;
|
curr_load->nice = load.nice - last_load.nice;
|
||||||
curr_load->system = load.system - last_load.system;
|
curr_load->system = load.system - last_load.system;
|
||||||
@@ -248,15 +245,15 @@ int machine_get_load(load_type *curr_load)
|
|||||||
last_ret_load = *curr_load;
|
last_ret_load = *curr_load;
|
||||||
last_load = load;
|
last_load = load;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
*curr_load = last_ret_load;
|
*curr_load = last_ret_load;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_loadavg(double *load)
|
int
|
||||||
|
machine_get_loadavg(double *load)
|
||||||
{
|
{
|
||||||
double loadavg[LOADAVG_NSTATS];
|
double loadavg[LOADAVG_NSTATS];
|
||||||
|
|
||||||
@@ -268,21 +265,20 @@ int machine_get_loadavg(double *load)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_meminfo(meminfo_type *result)
|
int
|
||||||
|
machine_get_meminfo(meminfo_type * result)
|
||||||
{
|
{
|
||||||
int total_pages, free_pages;
|
int total_pages, free_pages;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
size = sizeof(int);
|
size = sizeof(int);
|
||||||
|
|
||||||
if (sysctlbyname("vm.stats.vm.v_page_count", &total_pages, &size, NULL, 0) < 0)
|
if (sysctlbyname("vm.stats.vm.v_page_count", &total_pages, &size, NULL, 0) < 0) {
|
||||||
{
|
|
||||||
perror("sysctl vm.stats.vm.v_page_count");
|
perror("sysctl vm.stats.vm.v_page_count");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sysctlbyname("vm.stats.vm.v_free_count", &free_pages, &size, NULL, 0) < 0)
|
if (sysctlbyname("vm.stats.vm.v_free_count", &free_pages, &size, NULL, 0) < 0) {
|
||||||
{
|
|
||||||
perror("sysctl vm.stats.vm.v_free_count");
|
perror("sysctl vm.stats.vm.v_free_count");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
@@ -300,8 +296,7 @@ int machine_get_meminfo(meminfo_type *result)
|
|||||||
result[1].total = 0;
|
result[1].total = 0;
|
||||||
result[1].free = 0;
|
result[1].free = 0;
|
||||||
|
|
||||||
if (swapmode(&total_pages, &free_pages) != -1)
|
if (swapmode(&total_pages, &free_pages) != -1) {
|
||||||
{
|
|
||||||
result[1].total = total_pages;
|
result[1].total = total_pages;
|
||||||
result[1].free = free_pages;
|
result[1].free = free_pages;
|
||||||
}
|
}
|
||||||
@@ -309,25 +304,23 @@ int machine_get_meminfo(meminfo_type *result)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_procs(LinkedList *procs)
|
int
|
||||||
|
machine_get_procs(LinkedList * procs)
|
||||||
{
|
{
|
||||||
struct kinfo_proc *kprocs;
|
struct kinfo_proc *kprocs;
|
||||||
int nproc, i;
|
int nproc, i;
|
||||||
procinfo_type *p;
|
procinfo_type *p;
|
||||||
|
|
||||||
kprocs = kvm_getprocs(kvmd, KERN_PROC_ALL, 0, &nproc);
|
kprocs = kvm_getprocs(kvmd, KERN_PROC_ALL, 0, &nproc);
|
||||||
if (kprocs == NULL)
|
if (kprocs == NULL) {
|
||||||
{
|
|
||||||
perror("kvm_getprocs");
|
perror("kvm_getprocs");
|
||||||
kvm_close(kvmd);
|
kvm_close(kvmd);
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < nproc; i++)
|
for (i = 0; i < nproc; i++) {
|
||||||
{
|
|
||||||
p = malloc(sizeof(procinfo_type));
|
p = malloc(sizeof(procinfo_type));
|
||||||
if (!p)
|
if (!p) {
|
||||||
{
|
|
||||||
perror("mem_top_malloc");
|
perror("mem_top_malloc");
|
||||||
kvm_close(kvmd);
|
kvm_close(kvmd);
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
@@ -353,7 +346,8 @@ int machine_get_procs(LinkedList *procs)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_smpload(load_type *result, int *numcpus)
|
int
|
||||||
|
machine_get_smpload(load_type * result, int *numcpus)
|
||||||
{
|
{
|
||||||
int i, num;
|
int i, num;
|
||||||
size_t size;
|
size_t size;
|
||||||
@@ -420,7 +414,8 @@ int machine_get_smpload(load_type *result, int *numcpus)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_uptime(double *up, double *idle)
|
int
|
||||||
|
machine_get_uptime(double *up, double *idle)
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
time_t now;
|
time_t now;
|
||||||
@@ -429,8 +424,7 @@ int machine_get_uptime(double *up, double *idle)
|
|||||||
|
|
||||||
size = sizeof(boottime);
|
size = sizeof(boottime);
|
||||||
time(&now);
|
time(&now);
|
||||||
if (sysctlbyname("kern.boottime", &boottime, &size, NULL, 0) < 0)
|
if (sysctlbyname("kern.boottime", &boottime, &size, NULL, 0) < 0) {
|
||||||
{
|
|
||||||
perror("sysctl kern.cp_time failed");
|
perror("sysctl kern.cp_time failed");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
@@ -445,7 +439,8 @@ int machine_get_uptime(double *up, double *idle)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int swapmode(int *retavail, int *retfree)
|
static int
|
||||||
|
swapmode(int *retavail, int *retfree)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
struct kvm_swap swapary[1];
|
struct kvm_swap swapary[1];
|
||||||
@@ -454,19 +449,16 @@ static int swapmode(int *retavail, int *retfree)
|
|||||||
*retavail = 0;
|
*retavail = 0;
|
||||||
*retfree = 0;
|
*retfree = 0;
|
||||||
|
|
||||||
if ((kvmd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) == NULL)
|
if ((kvmd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) == NULL) {
|
||||||
{
|
|
||||||
perror("read kvm");
|
perror("read kvm");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
n = kvm_getswapinfo(kvmd, swapary, 1, 0);
|
n = kvm_getswapinfo(kvmd, swapary, 1, 0);
|
||||||
if (n < 0 || swapary[0].ksw_total == 0)
|
if (n < 0 || swapary[0].ksw_total == 0) {
|
||||||
{
|
|
||||||
/* strange */
|
/* strange */
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
*retavail = pagetok(swapary[0].ksw_total);
|
*retavail = pagetok(swapary[0].ksw_total);
|
||||||
*retfree = pagetok(swapary[0].ksw_total - swapary[0].ksw_used);
|
*retfree = pagetok(swapary[0].ksw_total - swapary[0].ksw_used);
|
||||||
}
|
}
|
||||||
@@ -476,13 +468,8 @@ static int swapmode(int *retavail, int *retfree)
|
|||||||
return (n);
|
return (n);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
int
|
||||||
* Read interface statistics from system and store in the struct
|
machine_get_iface_stats(IfaceInfo * interface)
|
||||||
* passed as a pointer. If there are no errors, it returns 1. If errors,
|
|
||||||
* returns 0.
|
|
||||||
*************************************************************************
|
|
||||||
*/
|
|
||||||
int machine_get_iface_stats (IfaceInfo *interface)
|
|
||||||
{
|
{
|
||||||
int rows;
|
int rows;
|
||||||
int name[6] = {CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_IFDATA, 0, IFDATA_GENERAL};
|
int name[6] = {CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_IFDATA, 0, IFDATA_GENERAL};
|
||||||
@@ -495,7 +482,10 @@ int machine_get_iface_stats (IfaceInfo *interface)
|
|||||||
interface->status = down; /* set status down by default */
|
interface->status = down; /* set status down by default */
|
||||||
|
|
||||||
len = sizeof(ifmd);
|
len = sizeof(ifmd);
|
||||||
/* walk through all interfaces in the ifmib table from last to first */
|
/*
|
||||||
|
* walk through all interfaces in the ifmib table from last
|
||||||
|
* to first
|
||||||
|
*/
|
||||||
for (; rows > 0; rows--) {
|
for (; rows > 0; rows--) {
|
||||||
name[4] = rows; /* set the interface index */
|
name[4] = rows; /* set the interface index */
|
||||||
/* retrive the ifmibdata for the current index */
|
/* retrive the ifmibdata for the current index */
|
||||||
@@ -528,11 +518,11 @@ int machine_get_iface_stats (IfaceInfo *interface)
|
|||||||
}
|
}
|
||||||
/* if we are here there is no interface with the given name */
|
/* if we are here there is no interface with the given name */
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
perror("read sysctlbyname");
|
perror("read sysctlbyname");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
} /* get_iface_stats() */
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif /* __FreeBSD__ */
|
#endif /* __FreeBSD__ */
|
||||||
|
|||||||
@@ -70,12 +70,13 @@ static int loadavg_fd;
|
|||||||
static int meminfo_fd;
|
static int meminfo_fd;
|
||||||
static int uptime_fd;
|
static int uptime_fd;
|
||||||
|
|
||||||
static char procbuf[1024]; //TODO ugly hack!
|
static char procbuf[1024]; /* TODO ugly hack! */
|
||||||
|
|
||||||
static FILE *mtab_fd;
|
static FILE *mtab_fd;
|
||||||
|
|
||||||
|
|
||||||
int machine_init(void)
|
int
|
||||||
|
machine_init(void)
|
||||||
{
|
{
|
||||||
uptime_fd = -1;
|
uptime_fd = -1;
|
||||||
batt_fd = -1;
|
batt_fd = -1;
|
||||||
@@ -120,7 +121,6 @@ int machine_init(void)
|
|||||||
if (batt_fd < 0) {
|
if (batt_fd < 0) {
|
||||||
batt_fd = open("/proc/apm", O_RDONLY);
|
batt_fd = open("/proc/apm", O_RDONLY);
|
||||||
if (batt_fd < 0) {
|
if (batt_fd < 0) {
|
||||||
//perror("open /proc/apm");
|
|
||||||
/* allow opening /proc/apm to fail */
|
/* allow opening /proc/apm to fail */
|
||||||
batt_fd = -1;
|
batt_fd = -1;
|
||||||
}
|
}
|
||||||
@@ -129,7 +129,8 @@ int machine_init(void)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_close(void)
|
int
|
||||||
|
machine_close(void)
|
||||||
{
|
{
|
||||||
if (batt_fd >= 0)
|
if (batt_fd >= 0)
|
||||||
close(batt_fd);
|
close(batt_fd);
|
||||||
@@ -190,7 +191,8 @@ getentry (const char *tag, const char *bufptr, long *value)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_battstat(int *acstat, int *battflag, int *percent)
|
int
|
||||||
|
machine_get_battstat(int *acstat, int *battflag, int *percent)
|
||||||
{
|
{
|
||||||
char str[64];
|
char str[64];
|
||||||
int battstat;
|
int battstat;
|
||||||
@@ -245,7 +247,8 @@ int machine_get_battstat(int *acstat, int *battflag, int *percent)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_fs(mounts_type fs[], int *cnt)
|
int
|
||||||
|
machine_get_fs(mounts_type fs[], int *cnt)
|
||||||
{
|
{
|
||||||
#ifdef STAT_STATVFS
|
#ifdef STAT_STATVFS
|
||||||
struct statvfs fsinfo;
|
struct statvfs fsinfo;
|
||||||
@@ -261,7 +264,7 @@ int machine_get_fs(mounts_type fs[], int *cnt)
|
|||||||
#error "Can't find your mounted filesystem table file."
|
#error "Can't find your mounted filesystem table file."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Get rid of old, unmounted filesystems...
|
/* Get rid of old, unmounted filesystems... */
|
||||||
memset(fs, 0, sizeof(mounts_type) * 256);
|
memset(fs, 0, sizeof(mounts_type) * 256);
|
||||||
|
|
||||||
while (x < 256) {
|
while (x < 256) {
|
||||||
@@ -281,8 +284,7 @@ int machine_get_fs(mounts_type fs[], int *cnt)
|
|||||||
#ifndef STAT_SMBFS
|
#ifndef STAT_SMBFS
|
||||||
&& strcmp(fs[x].type, "smbfs")
|
&& strcmp(fs[x].type, "smbfs")
|
||||||
#endif
|
#endif
|
||||||
)
|
) {
|
||||||
{
|
|
||||||
#ifdef STAT_STATVFS
|
#ifdef STAT_STATVFS
|
||||||
y = statvfs(fs[x].mpoint, &fsinfo);
|
y = statvfs(fs[x].mpoint, &fsinfo);
|
||||||
#elif STAT_STATFS2_BSIZE
|
#elif STAT_STATFS2_BSIZE
|
||||||
@@ -309,7 +311,8 @@ int machine_get_fs(mounts_type fs[], int *cnt)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_load(load_type *curr_load)
|
int
|
||||||
|
machine_get_load(load_type * curr_load)
|
||||||
{
|
{
|
||||||
static load_type last_load = {0, 0, 0, 0, 0};
|
static load_type last_load = {0, 0, 0, 0, 0};
|
||||||
load_type load;
|
load_type load;
|
||||||
@@ -337,13 +340,14 @@ int machine_get_load(load_type *curr_load)
|
|||||||
curr_load->idle = load.idle - last_load.idle;
|
curr_load->idle = load.idle - last_load.idle;
|
||||||
curr_load->total = load.total - last_load.total;
|
curr_load->total = load.total - last_load.total;
|
||||||
|
|
||||||
// struct assignment is legal in C89
|
/* struct assignment is legal in C89 */
|
||||||
last_load = load;
|
last_load = load;
|
||||||
|
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_loadavg(double *load)
|
int
|
||||||
|
machine_get_loadavg(double *load)
|
||||||
{
|
{
|
||||||
#ifdef USE_GETLOADAVG
|
#ifdef USE_GETLOADAVG
|
||||||
double loadavg[LOADAVG_NSTATS];
|
double loadavg[LOADAVG_NSTATS];
|
||||||
@@ -360,7 +364,8 @@ int machine_get_loadavg(double *load)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_meminfo(meminfo_type *result)
|
int
|
||||||
|
machine_get_meminfo(meminfo_type * result)
|
||||||
{
|
{
|
||||||
long tmp;
|
long tmp;
|
||||||
|
|
||||||
@@ -376,9 +381,10 @@ int machine_get_meminfo(meminfo_type *result)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_procs(LinkedList *procs)
|
int
|
||||||
|
machine_get_procs(LinkedList * procs)
|
||||||
{
|
{
|
||||||
// Much of this code was ripped from "gmemusage"
|
/* Much of this code was ripped from "gmemusage" */
|
||||||
DIR *proc;
|
DIR *proc;
|
||||||
FILE *StatusFile;
|
FILE *StatusFile;
|
||||||
struct dirent *procdir;
|
struct dirent *procdir;
|
||||||
@@ -402,7 +408,8 @@ int machine_get_procs(LinkedList *procs)
|
|||||||
int threshold = 400, unique;
|
int threshold = 400, unique;
|
||||||
|
|
||||||
if ((proc = opendir("/proc")) == NULL) {
|
if ((proc = opendir("/proc")) == NULL) {
|
||||||
perror("mem_top_screen: unable to open /proc"); /* ToDo: correct error reporting */
|
/* ToDo: correct error reporting */
|
||||||
|
perror("mem_top_screen: unable to open /proc");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,8 +422,10 @@ int machine_get_procs(LinkedList *procs)
|
|||||||
|
|
||||||
sprintf(buf, "/proc/%s/status", procdir->d_name);
|
sprintf(buf, "/proc/%s/status", procdir->d_name);
|
||||||
if ((StatusFile = fopen(buf, "r")) == NULL) {
|
if ((StatusFile = fopen(buf, "r")) == NULL) {
|
||||||
// Not a serious error; process has finished before we could
|
/*
|
||||||
// examine it:
|
* Not a serious error; process has finished before
|
||||||
|
* we could examine it:
|
||||||
|
*/
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -425,19 +434,24 @@ int machine_get_procs(LinkedList *procs)
|
|||||||
if (!strncmp(buf, NameLine, NameLineLen)) {
|
if (!strncmp(buf, NameLine, NameLineLen)) {
|
||||||
/* Name: procName */
|
/* Name: procName */
|
||||||
sscanf(buf, "%*s %s", procName);
|
sscanf(buf, "%*s %s", procName);
|
||||||
} else if (!strncmp(buf, VmSizeLine, VmSizeLineLen)) {
|
}
|
||||||
|
else if (!strncmp(buf, VmSizeLine, VmSizeLineLen)) {
|
||||||
/* VmSize: procSize kB */
|
/* VmSize: procSize kB */
|
||||||
sscanf(buf, "%*s %d", &procSize);
|
sscanf(buf, "%*s %d", &procSize);
|
||||||
} else if (!strncmp (buf, VmRSSLine, VmRSSLineLen)) {
|
}
|
||||||
|
else if (!strncmp(buf, VmRSSLine, VmRSSLineLen)) {
|
||||||
/* VmRSS: procRSS kB */
|
/* VmRSS: procRSS kB */
|
||||||
sscanf(buf, "%*s %d", &procRSS);
|
sscanf(buf, "%*s %d", &procRSS);
|
||||||
} else if (!strncmp(buf, VmDataLine, VmDataLineLen)) {
|
}
|
||||||
|
else if (!strncmp(buf, VmDataLine, VmDataLineLen)) {
|
||||||
/* VmData: procData kB */
|
/* VmData: procData kB */
|
||||||
sscanf(buf, "%*s %d", &procData);
|
sscanf(buf, "%*s %d", &procData);
|
||||||
} else if (!strncmp(buf, VmStkLine, VmStkLineLen)) {
|
}
|
||||||
|
else if (!strncmp(buf, VmStkLine, VmStkLineLen)) {
|
||||||
/* VmStk: procStk kB */
|
/* VmStk: procStk kB */
|
||||||
sscanf(buf, "%*s %d", &procStk);
|
sscanf(buf, "%*s %d", &procStk);
|
||||||
} else if (!strncmp(buf, VmExeLine, VmExeLineLen)) {
|
}
|
||||||
|
else if (!strncmp(buf, VmExeLine, VmExeLineLen)) {
|
||||||
/* VmExe: procExe kB */
|
/* VmExe: procExe kB */
|
||||||
sscanf(buf, "%*s %d", &procExe);
|
sscanf(buf, "%*s %d", &procExe);
|
||||||
}
|
}
|
||||||
@@ -445,7 +459,7 @@ int machine_get_procs(LinkedList *procs)
|
|||||||
fclose(StatusFile);
|
fclose(StatusFile);
|
||||||
|
|
||||||
if (procSize > threshold) {
|
if (procSize > threshold) {
|
||||||
// Figure out if it's sharing any memory...
|
/* Figure out if it's sharing any memory... */
|
||||||
unique = 1;
|
unique = 1;
|
||||||
LL_Rewind(procs);
|
LL_Rewind(procs);
|
||||||
do {
|
do {
|
||||||
@@ -458,7 +472,7 @@ int machine_get_procs(LinkedList *procs)
|
|||||||
}
|
}
|
||||||
} while (LL_Next(procs) == 0);
|
} while (LL_Next(procs) == 0);
|
||||||
|
|
||||||
// If this is the first one by this name...
|
/* If this is the first one by this name... */
|
||||||
if (unique) {
|
if (unique) {
|
||||||
procinfo_type *p = malloc(sizeof(procinfo_type));
|
procinfo_type *p = malloc(sizeof(procinfo_type));
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
@@ -468,7 +482,7 @@ int machine_get_procs(LinkedList *procs)
|
|||||||
strcpy(p->name, procName);
|
strcpy(p->name, procName);
|
||||||
p->totl = procData + procStk + procExe;
|
p->totl = procData + procStk + procExe;
|
||||||
p->number = 1;
|
p->number = 1;
|
||||||
// TODO: Check for errors here?
|
/* TODO: Check for errors here? */
|
||||||
LL_Push(procs, (void *)p);
|
LL_Push(procs, (void *)p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -478,7 +492,8 @@ int machine_get_procs(LinkedList *procs)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_smpload(load_type *result, int *numcpus)
|
int
|
||||||
|
machine_get_smpload(load_type * result, int *numcpus)
|
||||||
{
|
{
|
||||||
char *token;
|
char *token;
|
||||||
static load_type last_load[MAX_CPUS];
|
static load_type last_load[MAX_CPUS];
|
||||||
@@ -489,7 +504,7 @@ int machine_get_smpload(load_type *result, int *numcpus)
|
|||||||
|
|
||||||
reread(load_fd, "get_load");
|
reread(load_fd, "get_load");
|
||||||
|
|
||||||
// Look for lines starting with "cpu0", "cpu1", etc.
|
/* Look for lines starting with "cpu0", "cpu1", etc. */
|
||||||
token = strtok(procbuf, "\n");
|
token = strtok(procbuf, "\n");
|
||||||
while (token != NULL) {
|
while (token != NULL) {
|
||||||
if ((strlen(token) > 3) && (!strncmp(token, "cpu", 3)) && isdigit(token[3])) {
|
if ((strlen(token) > 3) && (!strncmp(token, "cpu", 3)) && isdigit(token[3])) {
|
||||||
@@ -513,10 +528,10 @@ int machine_get_smpload(load_type *result, int *numcpus)
|
|||||||
result[ncpu].system = curr_load[ncpu].system - last_load[ncpu].system;
|
result[ncpu].system = curr_load[ncpu].system - last_load[ncpu].system;
|
||||||
result[ncpu].idle = curr_load[ncpu].idle - last_load[ncpu].idle;
|
result[ncpu].idle = curr_load[ncpu].idle - last_load[ncpu].idle;
|
||||||
|
|
||||||
// struct assignment is legal in C89
|
/* struct assignment is legal in C89 */
|
||||||
last_load[ncpu] = curr_load[ncpu];
|
last_load[ncpu] = curr_load[ncpu];
|
||||||
|
|
||||||
// restrict # CPUs to min(*numcpus, MAX_CPUS)
|
/* restrict # CPUs to min(*numcpus, MAX_CPUS) */
|
||||||
ncpu++;
|
ncpu++;
|
||||||
if ((ncpu >= *numcpus) || (ncpu >= MAX_CPUS))
|
if ((ncpu >= *numcpus) || (ncpu >= MAX_CPUS))
|
||||||
break;
|
break;
|
||||||
@@ -528,7 +543,8 @@ int machine_get_smpload(load_type *result, int *numcpus)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_uptime(double *up, double *idle)
|
int
|
||||||
|
machine_get_uptime(double *up, double *idle)
|
||||||
{
|
{
|
||||||
double local_up, local_idle;
|
double local_up, local_idle;
|
||||||
|
|
||||||
@@ -545,21 +561,17 @@ int machine_get_uptime(double *up, double *idle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
int
|
||||||
* Read interface statistics from system and store in the struct
|
machine_get_iface_stats(IfaceInfo * interface)
|
||||||
* passed as a pointer. If there are no errors, it returns 1. If errors,
|
|
||||||
* returns 0.
|
|
||||||
*************************************************************************
|
|
||||||
*/
|
|
||||||
int machine_get_iface_stats (IfaceInfo *interface)
|
|
||||||
{
|
{
|
||||||
FILE *file; /* file handler */
|
FILE *file; /* file handler */
|
||||||
char buffer[1024]; /* buffer to work with the file */
|
char buffer[1024]; /* buffer to work with the file */
|
||||||
static int first_time = 1; /* is it first time we call this function? */
|
static int first_time = 1; /* is it first time we call this
|
||||||
char *ch_pointer = NULL; /* pointer to where interface values are in file */
|
* function? */
|
||||||
|
char *ch_pointer = NULL;/* pointer to where interface values are in
|
||||||
|
* file */
|
||||||
|
|
||||||
/* Open the file in read-only mode and parse */
|
/* Open the file in read-only mode and parse */
|
||||||
|
|
||||||
if ((file = fopen("/proc/net/dev", "r")) != NULL) {
|
if ((file = fopen("/proc/net/dev", "r")) != NULL) {
|
||||||
/* Skip first 2 header lines of file */
|
/* Skip first 2 header lines of file */
|
||||||
fgets(buffer, sizeof(buffer), file);
|
fgets(buffer, sizeof(buffer), file);
|
||||||
@@ -579,7 +591,10 @@ int machine_get_iface_stats (IfaceInfo *interface)
|
|||||||
ch_pointer = strchr(buffer, ':');
|
ch_pointer = strchr(buffer, ':');
|
||||||
ch_pointer++;
|
ch_pointer++;
|
||||||
|
|
||||||
/* Now ch_pointer points to values of iface_name */
|
/*
|
||||||
|
* Now ch_pointer points to values of
|
||||||
|
* iface_name
|
||||||
|
*/
|
||||||
/* Scan values from here */
|
/* Scan values from here */
|
||||||
sscanf(ch_pointer, "%lf %lf %*s %*s %*s %*s %*s %*s %lf %lf",
|
sscanf(ch_pointer, "%lf %lf %*s %*s %*s %*s %*s %*s %lf %lf",
|
||||||
&interface->rc_byte,
|
&interface->rc_byte,
|
||||||
@@ -587,28 +602,30 @@ int machine_get_iface_stats (IfaceInfo *interface)
|
|||||||
&interface->tr_byte,
|
&interface->tr_byte,
|
||||||
&interface->tr_pkt);
|
&interface->tr_pkt);
|
||||||
|
|
||||||
/* if is the first time we call this function,
|
/*
|
||||||
* old values are the same as new so we don't
|
* if is the first time we call this
|
||||||
* get big speeds when calculating
|
* function, old values are the same as new
|
||||||
|
* so we don't get big speeds when
|
||||||
|
* calculating
|
||||||
*/
|
*/
|
||||||
if (first_time) {
|
if (first_time) {
|
||||||
interface->rc_byte_old = interface->rc_byte;
|
interface->rc_byte_old = interface->rc_byte;
|
||||||
interface->tr_byte_old = interface->tr_byte;
|
interface->tr_byte_old = interface->tr_byte;
|
||||||
interface->rc_pkt_old = interface->rc_pkt;
|
interface->rc_pkt_old = interface->rc_pkt;
|
||||||
interface->tr_pkt_old = interface->tr_pkt;
|
interface->tr_pkt_old = interface->tr_pkt;
|
||||||
first_time = 0; /* now it isn't first time */
|
first_time = 0; /* now it isn't first
|
||||||
|
* time */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} /* while */
|
|
||||||
|
|
||||||
fclose(file); /* close file */
|
|
||||||
return 1; /* everything went OK */
|
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
return (TRUE);
|
||||||
}
|
}
|
||||||
else { /* error when opening the file */
|
else { /* error when opening the file */
|
||||||
perror("Error: Could not open DEVFILE");
|
perror("Error: Could not open DEVFILE");
|
||||||
return 0; /* something went wrong */
|
return (FALSE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} /* get_iface_stats() */
|
|
||||||
|
|
||||||
#endif /* linux */
|
#endif /* linux */
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
* Collects system information on NetBSD.
|
* Collects system information on NetBSD.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Copyright (c) 2003 Thomas Runge (coto@core.de)
|
/*-
|
||||||
|
* Copyright (c) 2003 Thomas Runge (coto@core.de)
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -73,13 +74,16 @@ static int pageshift;
|
|||||||
#define PROCSIZE(pp) ((pp)->p_vm_tsize + (pp)->p_vm_dsize + (pp)->p_vm_ssize)
|
#define PROCSIZE(pp) ((pp)->p_vm_tsize + (pp)->p_vm_dsize + (pp)->p_vm_ssize)
|
||||||
|
|
||||||
|
|
||||||
int machine_init(void)
|
int
|
||||||
|
machine_init(void)
|
||||||
{
|
{
|
||||||
/* get the page size with "getpagesize" and calculate pageshift from it */
|
/*
|
||||||
|
* get the page size with "getpagesize" and calculate pageshift from
|
||||||
|
* it
|
||||||
|
*/
|
||||||
int pagesize = getpagesize();
|
int pagesize = getpagesize();
|
||||||
pageshift = 0;
|
pageshift = 0;
|
||||||
while (pagesize > 1)
|
while (pagesize > 1) {
|
||||||
{
|
|
||||||
pageshift++;
|
pageshift++;
|
||||||
pagesize >>= 1;
|
pagesize >>= 1;
|
||||||
}
|
}
|
||||||
@@ -90,18 +94,19 @@ int machine_init(void)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_close(void)
|
int
|
||||||
|
machine_close(void)
|
||||||
{
|
{
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_battstat(int *acstat, int *battflag, int *percent)
|
int
|
||||||
|
machine_get_battstat(int *acstat, int *battflag, int *percent)
|
||||||
{
|
{
|
||||||
int apmd;
|
int apmd;
|
||||||
struct apm_power_info apmi;
|
struct apm_power_info apmi;
|
||||||
|
|
||||||
if ((apmd = open("/dev/apm", O_RDONLY)) == -1)
|
if ((apmd = open("/dev/apm", O_RDONLY)) == -1) {
|
||||||
{
|
|
||||||
*acstat = LCDP_AC_ON;
|
*acstat = LCDP_AC_ON;
|
||||||
*battflag = LCDP_BATT_ABSENT;
|
*battflag = LCDP_BATT_ABSENT;
|
||||||
*percent = 100;
|
*percent = 100;
|
||||||
@@ -109,14 +114,12 @@ int machine_get_battstat(int *acstat, int *battflag, int *percent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
memset(&apmi, 0, sizeof(apmi));
|
memset(&apmi, 0, sizeof(apmi));
|
||||||
if (ioctl(apmd, APM_IOC_GETPOWER, &apmi) == -1)
|
if (ioctl(apmd, APM_IOC_GETPOWER, &apmi) == -1) {
|
||||||
{
|
|
||||||
perror("APM_IOC_GETPOWER failed in get_batt_stat()");
|
perror("APM_IOC_GETPOWER failed in get_batt_stat()");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(apmi.ac_state)
|
switch (apmi.ac_state) {
|
||||||
{
|
|
||||||
case APM_AC_OFF:
|
case APM_AC_OFF:
|
||||||
*acstat = LCDP_AC_OFF;
|
*acstat = LCDP_AC_OFF;
|
||||||
break;
|
break;
|
||||||
@@ -139,7 +142,8 @@ int machine_get_battstat(int *acstat, int *battflag, int *percent)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_fs(mounts_type fs[], int *cnt)
|
int
|
||||||
|
machine_get_fs(mounts_type fs[], int *cnt)
|
||||||
{
|
{
|
||||||
#if (__NetBSD_Version__ >= 300000000)
|
#if (__NetBSD_Version__ >= 300000000)
|
||||||
struct statvfs *mntbuf;
|
struct statvfs *mntbuf;
|
||||||
@@ -151,13 +155,11 @@ int machine_get_fs(mounts_type fs[], int *cnt)
|
|||||||
int statcnt, fscnt, i;
|
int statcnt, fscnt, i;
|
||||||
|
|
||||||
fscnt = getmntinfo(&mntbuf, MNT_WAIT);
|
fscnt = getmntinfo(&mntbuf, MNT_WAIT);
|
||||||
if (fscnt == 0)
|
if (fscnt == 0) {
|
||||||
{
|
|
||||||
perror("getmntinfo");
|
perror("getmntinfo");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
for (statcnt = 0, pp = mntbuf, i = 0; i < fscnt; pp++, i++)
|
for (statcnt = 0, pp = mntbuf, i = 0; i < fscnt; pp++, i++) {
|
||||||
{
|
|
||||||
if (strcmp(pp->f_fstypename, "procfs")
|
if (strcmp(pp->f_fstypename, "procfs")
|
||||||
&& strcmp(pp->f_fstypename, "kernfs")
|
&& strcmp(pp->f_fstypename, "kernfs")
|
||||||
&& strcmp(pp->f_fstypename, "linprocfs")
|
&& strcmp(pp->f_fstypename, "linprocfs")
|
||||||
@@ -167,15 +169,13 @@ int machine_get_fs(mounts_type fs[], int *cnt)
|
|||||||
#ifndef STAT_SMBFS
|
#ifndef STAT_SMBFS
|
||||||
&& strcmp(pp->f_fstypename, "smbfs")
|
&& strcmp(pp->f_fstypename, "smbfs")
|
||||||
#endif
|
#endif
|
||||||
)
|
) {
|
||||||
{
|
|
||||||
snprintf(fs[statcnt].dev, 255, "%s", pp->f_mntfromname);
|
snprintf(fs[statcnt].dev, 255, "%s", pp->f_mntfromname);
|
||||||
snprintf(fs[statcnt].mpoint, 255, "%s", pp->f_mntonname);
|
snprintf(fs[statcnt].mpoint, 255, "%s", pp->f_mntonname);
|
||||||
snprintf(fs[statcnt].type, 63, "%s", pp->f_fstypename);
|
snprintf(fs[statcnt].type, 63, "%s", pp->f_fstypename);
|
||||||
|
|
||||||
fs[statcnt].blocks = pp->f_blocks;
|
fs[statcnt].blocks = pp->f_blocks;
|
||||||
if (fs[statcnt].blocks > 0)
|
if (fs[statcnt].blocks > 0) {
|
||||||
{
|
|
||||||
fs[statcnt].bsize = pp->f_bsize;
|
fs[statcnt].bsize = pp->f_bsize;
|
||||||
fs[statcnt].bfree = pp->f_bfree;
|
fs[statcnt].bfree = pp->f_bfree;
|
||||||
fs[statcnt].files = pp->f_files;
|
fs[statcnt].files = pp->f_files;
|
||||||
@@ -189,7 +189,8 @@ int machine_get_fs(mounts_type fs[], int *cnt)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_load(load_type *curr_load)
|
int
|
||||||
|
machine_get_load(load_type * curr_load)
|
||||||
{
|
{
|
||||||
static load_type last_load = {0, 0, 0, 0, 0};
|
static load_type last_load = {0, 0, 0, 0, 0};
|
||||||
static load_type last_ret_load;
|
static load_type last_ret_load;
|
||||||
@@ -201,8 +202,7 @@ int machine_get_load(load_type *curr_load)
|
|||||||
mib[0] = CTL_KERN;
|
mib[0] = CTL_KERN;
|
||||||
mib[1] = KERN_CP_TIME;
|
mib[1] = KERN_CP_TIME;
|
||||||
size = sizeof(cp_time);
|
size = sizeof(cp_time);
|
||||||
if (sysctl(mib, 2, cp_time, &size, NULL, 0) < 0)
|
if (sysctl(mib, 2, cp_time, &size, NULL, 0) < 0) {
|
||||||
{
|
|
||||||
perror("sysctl kern.cp_time failed");
|
perror("sysctl kern.cp_time failed");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
@@ -213,8 +213,7 @@ int machine_get_load(load_type *curr_load)
|
|||||||
load.idle = (unsigned long)(cp_time[CP_IDLE]);
|
load.idle = (unsigned long)(cp_time[CP_IDLE]);
|
||||||
load.total = load.user + load.nice + load.system + load.idle;
|
load.total = load.user + load.nice + load.system + load.idle;
|
||||||
|
|
||||||
if (load.total != last_load.total)
|
if (load.total != last_load.total) {
|
||||||
{
|
|
||||||
curr_load->user = load.user - last_load.user;
|
curr_load->user = load.user - last_load.user;
|
||||||
curr_load->nice = load.nice - last_load.nice;
|
curr_load->nice = load.nice - last_load.nice;
|
||||||
curr_load->system = load.system - last_load.system;
|
curr_load->system = load.system - last_load.system;
|
||||||
@@ -223,15 +222,15 @@ int machine_get_load(load_type *curr_load)
|
|||||||
last_ret_load = *curr_load;
|
last_ret_load = *curr_load;
|
||||||
last_load = load;
|
last_load = load;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
*curr_load = last_ret_load;
|
*curr_load = last_ret_load;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_loadavg(double *load)
|
int
|
||||||
|
machine_get_loadavg(double *load)
|
||||||
{
|
{
|
||||||
double loadavg[LOADAVG_NSTATS];
|
double loadavg[LOADAVG_NSTATS];
|
||||||
|
|
||||||
@@ -243,7 +242,8 @@ int machine_get_loadavg(double *load)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_meminfo(meminfo_type *result)
|
int
|
||||||
|
machine_get_meminfo(meminfo_type * result)
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
int mib[2];
|
int mib[2];
|
||||||
@@ -252,8 +252,7 @@ int machine_get_meminfo(meminfo_type *result)
|
|||||||
mib[0] = CTL_VM;
|
mib[0] = CTL_VM;
|
||||||
mib[1] = VM_UVMEXP2;
|
mib[1] = VM_UVMEXP2;
|
||||||
size = sizeof(uvmexp);
|
size = sizeof(uvmexp);
|
||||||
if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0)
|
if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0) {
|
||||||
{
|
|
||||||
perror("sysctl vm.uvmexp2 failed");
|
perror("sysctl vm.uvmexp2 failed");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
@@ -275,7 +274,8 @@ int machine_get_meminfo(meminfo_type *result)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_procs(LinkedList *procs)
|
int
|
||||||
|
machine_get_procs(LinkedList * procs)
|
||||||
{
|
{
|
||||||
int nproc, i;
|
int nproc, i;
|
||||||
kvm_t *kvmd;
|
kvm_t *kvmd;
|
||||||
@@ -283,24 +283,20 @@ int machine_get_procs(LinkedList *procs)
|
|||||||
procinfo_type *p;
|
procinfo_type *p;
|
||||||
|
|
||||||
kprocs = NULL;
|
kprocs = NULL;
|
||||||
if ((kvmd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, "kvm_open")) == NULL)
|
if ((kvmd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, "kvm_open")) == NULL) {
|
||||||
{
|
|
||||||
perror("kvm_openfiles");
|
perror("kvm_openfiles");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
kprocs = kvm_getproc2(kvmd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc2), &nproc);
|
kprocs = kvm_getproc2(kvmd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc2), &nproc);
|
||||||
if (kprocs == NULL)
|
if (kprocs == NULL) {
|
||||||
{
|
|
||||||
perror("kvm_getproc2");
|
perror("kvm_getproc2");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < nproc; i++)
|
for (i = 0; i < nproc; i++) {
|
||||||
{
|
|
||||||
p = malloc(sizeof(procinfo_type));
|
p = malloc(sizeof(procinfo_type));
|
||||||
if (!p)
|
if (!p) {
|
||||||
{
|
|
||||||
perror("mem_top_malloc");
|
perror("mem_top_malloc");
|
||||||
kvm_close(kvmd);
|
kvm_close(kvmd);
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
@@ -319,7 +315,8 @@ int machine_get_procs(LinkedList *procs)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_smpload(load_type *result, int *numcpus)
|
int
|
||||||
|
machine_get_smpload(load_type * result, int *numcpus)
|
||||||
{
|
{
|
||||||
int mib[2], i, num;
|
int mib[2], i, num;
|
||||||
size_t size;
|
size_t size;
|
||||||
@@ -352,7 +349,8 @@ int machine_get_smpload(load_type *result, int *numcpus)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_uptime(double *up, double *idle)
|
int
|
||||||
|
machine_get_uptime(double *up, double *idle)
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
time_t now;
|
time_t now;
|
||||||
@@ -364,8 +362,7 @@ int machine_get_uptime(double *up, double *idle)
|
|||||||
mib[1] = KERN_BOOTTIME;
|
mib[1] = KERN_BOOTTIME;
|
||||||
size = sizeof(boottime);
|
size = sizeof(boottime);
|
||||||
time(&now);
|
time(&now);
|
||||||
if (sysctl(mib, 2, &boottime, &size, NULL, 0) < 0)
|
if (sysctl(mib, 2, &boottime, &size, NULL, 0) < 0) {
|
||||||
{
|
|
||||||
perror("sysctl kern.boottime failed");
|
perror("sysctl kern.boottime failed");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
@@ -381,7 +378,8 @@ int machine_get_uptime(double *up, double *idle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get network statistics */
|
/* Get network statistics */
|
||||||
int machine_get_iface_stats (IfaceInfo *interface)
|
int
|
||||||
|
machine_get_iface_stats(IfaceInfo * interface)
|
||||||
{
|
{
|
||||||
struct ifaddrs *ifa, *ifa_ptr;
|
struct ifaddrs *ifa, *ifa_ptr;
|
||||||
struct if_data *ifd;
|
struct if_data *ifd;
|
||||||
@@ -427,4 +425,3 @@ int machine_get_iface_stats (IfaceInfo *interface)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif /* __NetBSD__ */
|
#endif /* __NetBSD__ */
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
* Collects system information on OpenBSD.
|
* Collects system information on OpenBSD.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Copyright (c) 2003 Thomas Runge (coto@core.de)
|
/*-
|
||||||
|
* Copyright (c) 2003 Thomas Runge (coto@core.de)
|
||||||
*
|
*
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -63,13 +64,16 @@ static int pageshift;
|
|||||||
#define PROCSIZE(pp) ((pp).vm_tsize + (pp).vm_dsize + (pp).vm_ssize)
|
#define PROCSIZE(pp) ((pp).vm_tsize + (pp).vm_dsize + (pp).vm_ssize)
|
||||||
|
|
||||||
|
|
||||||
int machine_init(void)
|
int
|
||||||
|
machine_init(void)
|
||||||
{
|
{
|
||||||
/* get the page size with "getpagesize" and calculate pageshift from it */
|
/*
|
||||||
|
* get the page size with "getpagesize" and calculate pageshift from
|
||||||
|
* it
|
||||||
|
*/
|
||||||
int pagesize = getpagesize();
|
int pagesize = getpagesize();
|
||||||
pageshift = 0;
|
pageshift = 0;
|
||||||
while (pagesize > 1)
|
while (pagesize > 1) {
|
||||||
{
|
|
||||||
pageshift++;
|
pageshift++;
|
||||||
pagesize >>= 1;
|
pagesize >>= 1;
|
||||||
}
|
}
|
||||||
@@ -80,12 +84,14 @@ int machine_init(void)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_close(void)
|
int
|
||||||
|
machine_close(void)
|
||||||
{
|
{
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_battstat(int *acstat, int *battflag, int *percent)
|
int
|
||||||
|
machine_get_battstat(int *acstat, int *battflag, int *percent)
|
||||||
{
|
{
|
||||||
int apmd;
|
int apmd;
|
||||||
struct apm_power_info api;
|
struct apm_power_info api;
|
||||||
@@ -94,20 +100,17 @@ int machine_get_battstat(int *acstat, int *battflag, int *percent)
|
|||||||
*battflag = LCDP_BATT_ABSENT;
|
*battflag = LCDP_BATT_ABSENT;
|
||||||
*percent = 100;
|
*percent = 100;
|
||||||
|
|
||||||
if ((apmd = open("/dev/apm", O_RDONLY)) == -1)
|
if ((apmd = open("/dev/apm", O_RDONLY)) == -1) {
|
||||||
{
|
|
||||||
perror("get_battstat_open");
|
perror("get_battstat_open");
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ioctl(apmd, APM_IOC_GETPOWER, &api) == -1)
|
if (ioctl(apmd, APM_IOC_GETPOWER, &api) == -1) {
|
||||||
{
|
|
||||||
perror("get_battstat_ioctl");
|
perror("get_battstat_ioctl");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(api.ac_state)
|
switch (api.ac_state) {
|
||||||
{
|
|
||||||
case APM_AC_OFF:
|
case APM_AC_OFF:
|
||||||
*acstat = LCDP_AC_OFF;
|
*acstat = LCDP_AC_OFF;
|
||||||
break;
|
break;
|
||||||
@@ -119,8 +122,7 @@ int machine_get_battstat(int *acstat, int *battflag, int *percent)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(api.battery_state)
|
switch (api.battery_state) {
|
||||||
{
|
|
||||||
case APM_BATT_HIGH:
|
case APM_BATT_HIGH:
|
||||||
*battflag = LCDP_BATT_HIGH;
|
*battflag = LCDP_BATT_HIGH;
|
||||||
break;
|
break;
|
||||||
@@ -148,20 +150,19 @@ int machine_get_battstat(int *acstat, int *battflag, int *percent)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_fs(mounts_type fs[], int *cnt)
|
int
|
||||||
|
machine_get_fs(mounts_type fs[], int *cnt)
|
||||||
{
|
{
|
||||||
struct statfs *mntbuf;
|
struct statfs *mntbuf;
|
||||||
struct statfs *pp;
|
struct statfs *pp;
|
||||||
int statcnt, fscnt, i;
|
int statcnt, fscnt, i;
|
||||||
|
|
||||||
fscnt = getmntinfo(&mntbuf, MNT_WAIT);
|
fscnt = getmntinfo(&mntbuf, MNT_WAIT);
|
||||||
if (fscnt == 0)
|
if (fscnt == 0) {
|
||||||
{
|
|
||||||
perror("getmntinfo");
|
perror("getmntinfo");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
for (statcnt = 0, pp = mntbuf, i = 0; i < fscnt; pp++, i++)
|
for (statcnt = 0, pp = mntbuf, i = 0; i < fscnt; pp++, i++) {
|
||||||
{
|
|
||||||
if (strcmp(pp->f_fstypename, "procfs")
|
if (strcmp(pp->f_fstypename, "procfs")
|
||||||
&& strcmp(pp->f_fstypename, "kernfs")
|
&& strcmp(pp->f_fstypename, "kernfs")
|
||||||
&& strcmp(pp->f_fstypename, "linprocfs")
|
&& strcmp(pp->f_fstypename, "linprocfs")
|
||||||
@@ -171,15 +172,13 @@ int machine_get_fs(mounts_type fs[], int *cnt)
|
|||||||
#ifndef STAT_SMBFS
|
#ifndef STAT_SMBFS
|
||||||
&& strcmp(pp->f_fstypename, "smbfs")
|
&& strcmp(pp->f_fstypename, "smbfs")
|
||||||
#endif
|
#endif
|
||||||
)
|
) {
|
||||||
{
|
|
||||||
snprintf(fs[statcnt].dev, 255, "%s", pp->f_mntfromname);
|
snprintf(fs[statcnt].dev, 255, "%s", pp->f_mntfromname);
|
||||||
snprintf(fs[statcnt].mpoint, 255, "%s", pp->f_mntonname);
|
snprintf(fs[statcnt].mpoint, 255, "%s", pp->f_mntonname);
|
||||||
snprintf(fs[statcnt].type, 63, "%s", pp->f_fstypename);
|
snprintf(fs[statcnt].type, 63, "%s", pp->f_fstypename);
|
||||||
|
|
||||||
fs[statcnt].blocks = pp->f_blocks;
|
fs[statcnt].blocks = pp->f_blocks;
|
||||||
if (fs[statcnt].blocks > 0)
|
if (fs[statcnt].blocks > 0) {
|
||||||
{
|
|
||||||
fs[statcnt].bsize = pp->f_bsize;
|
fs[statcnt].bsize = pp->f_bsize;
|
||||||
fs[statcnt].bfree = pp->f_bfree;
|
fs[statcnt].bfree = pp->f_bfree;
|
||||||
fs[statcnt].files = pp->f_files;
|
fs[statcnt].files = pp->f_files;
|
||||||
@@ -193,7 +192,8 @@ int machine_get_fs(mounts_type fs[], int *cnt)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_load(load_type *curr_load)
|
int
|
||||||
|
machine_get_load(load_type * curr_load)
|
||||||
{
|
{
|
||||||
static load_type last_load = {0, 0, 0, 0, 0};
|
static load_type last_load = {0, 0, 0, 0, 0};
|
||||||
static load_type last_ret_load;
|
static load_type last_ret_load;
|
||||||
@@ -205,8 +205,7 @@ int machine_get_load(load_type *curr_load)
|
|||||||
mib[0] = CTL_KERN;
|
mib[0] = CTL_KERN;
|
||||||
mib[1] = KERN_CPTIME;
|
mib[1] = KERN_CPTIME;
|
||||||
size = sizeof(cp_time);
|
size = sizeof(cp_time);
|
||||||
if (sysctl(mib, 2, cp_time, &size, NULL, 0) < 0)
|
if (sysctl(mib, 2, cp_time, &size, NULL, 0) < 0) {
|
||||||
{
|
|
||||||
perror("sysctl kern.cp_time failed");
|
perror("sysctl kern.cp_time failed");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
@@ -217,8 +216,7 @@ int machine_get_load(load_type *curr_load)
|
|||||||
load.idle = (unsigned long)(cp_time[CP_IDLE]);
|
load.idle = (unsigned long)(cp_time[CP_IDLE]);
|
||||||
load.total = load.user + load.nice + load.system + load.idle;
|
load.total = load.user + load.nice + load.system + load.idle;
|
||||||
|
|
||||||
if (load.total != last_load.total)
|
if (load.total != last_load.total) {
|
||||||
{
|
|
||||||
curr_load->user = load.user - last_load.user;
|
curr_load->user = load.user - last_load.user;
|
||||||
curr_load->nice = load.nice - last_load.nice;
|
curr_load->nice = load.nice - last_load.nice;
|
||||||
curr_load->system = load.system - last_load.system;
|
curr_load->system = load.system - last_load.system;
|
||||||
@@ -227,15 +225,15 @@ int machine_get_load(load_type *curr_load)
|
|||||||
last_ret_load = *curr_load;
|
last_ret_load = *curr_load;
|
||||||
last_load = load;
|
last_load = load;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
*curr_load = last_ret_load;
|
*curr_load = last_ret_load;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_loadavg(double *load)
|
int
|
||||||
|
machine_get_loadavg(double *load)
|
||||||
{
|
{
|
||||||
double loadavg[LOADAVG_NSTATS];
|
double loadavg[LOADAVG_NSTATS];
|
||||||
|
|
||||||
@@ -247,7 +245,8 @@ int machine_get_loadavg(double *load)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_meminfo(meminfo_type *result)
|
int
|
||||||
|
machine_get_meminfo(meminfo_type * result)
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
int mib[2];
|
int mib[2];
|
||||||
@@ -257,8 +256,7 @@ int machine_get_meminfo(meminfo_type *result)
|
|||||||
mib[1] = VM_UVMEXP;
|
mib[1] = VM_UVMEXP;
|
||||||
size = sizeof(suvm);
|
size = sizeof(suvm);
|
||||||
|
|
||||||
if (sysctl(mib, 2, &suvm, &size, NULL, 0) < 0)
|
if (sysctl(mib, 2, &suvm, &size, NULL, 0) < 0) {
|
||||||
{
|
|
||||||
perror("sysctl vm.uvmexp failed");
|
perror("sysctl vm.uvmexp failed");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
@@ -280,32 +278,29 @@ int machine_get_meminfo(meminfo_type *result)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_procs(LinkedList *procs)
|
int
|
||||||
|
machine_get_procs(LinkedList * procs)
|
||||||
{
|
{
|
||||||
struct kinfo_proc *kprocs;
|
struct kinfo_proc *kprocs;
|
||||||
int nproc, i;
|
int nproc, i;
|
||||||
procinfo_type *p;
|
procinfo_type *p;
|
||||||
kvm_t *kvmd;
|
kvm_t *kvmd;
|
||||||
|
|
||||||
if ((kvmd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) == NULL)
|
if ((kvmd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) == NULL) {
|
||||||
{
|
|
||||||
perror("kvm_open");
|
perror("kvm_open");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
kprocs = kvm_getprocs(kvmd, KERN_PROC_ALL, 0, &nproc);
|
kprocs = kvm_getprocs(kvmd, KERN_PROC_ALL, 0, &nproc);
|
||||||
if (kprocs == NULL)
|
if (kprocs == NULL) {
|
||||||
{
|
|
||||||
perror("kvm_getprocs");
|
perror("kvm_getprocs");
|
||||||
kvm_close(kvmd);
|
kvm_close(kvmd);
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < nproc; i++)
|
for (i = 0; i < nproc; i++) {
|
||||||
{
|
|
||||||
p = malloc(sizeof(procinfo_type));
|
p = malloc(sizeof(procinfo_type));
|
||||||
if (!p)
|
if (!p) {
|
||||||
{
|
|
||||||
perror("mem_top_malloc");
|
perror("mem_top_malloc");
|
||||||
kvm_close(kvmd);
|
kvm_close(kvmd);
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
@@ -323,7 +318,8 @@ int machine_get_procs(LinkedList *procs)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_smpload(load_type *result, int *numcpus)
|
int
|
||||||
|
machine_get_smpload(load_type * result, int *numcpus)
|
||||||
{
|
{
|
||||||
int mib[2], i, num;
|
int mib[2], i, num;
|
||||||
size_t size;
|
size_t size;
|
||||||
@@ -356,7 +352,8 @@ int machine_get_smpload(load_type *result, int *numcpus)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_uptime(double *up, double *idle)
|
int
|
||||||
|
machine_get_uptime(double *up, double *idle)
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
time_t now;
|
time_t now;
|
||||||
@@ -368,8 +365,7 @@ int machine_get_uptime(double *up, double *idle)
|
|||||||
mib[1] = KERN_BOOTTIME;
|
mib[1] = KERN_BOOTTIME;
|
||||||
size = sizeof(boottime);
|
size = sizeof(boottime);
|
||||||
time(&now);
|
time(&now);
|
||||||
if (sysctl(mib, 2, &boottime, &size, NULL, 0) < 0)
|
if (sysctl(mib, 2, &boottime, &size, NULL, 0) < 0) {
|
||||||
{
|
|
||||||
perror("sysctl kern.boottime failed");
|
perror("sysctl kern.boottime failed");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
@@ -385,7 +381,8 @@ int machine_get_uptime(double *up, double *idle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get network statistics */
|
/* Get network statistics */
|
||||||
int machine_get_iface_stats (IfaceInfo *interface)
|
int
|
||||||
|
machine_get_iface_stats(IfaceInfo * interface)
|
||||||
{
|
{
|
||||||
/* Implementation missing */
|
/* Implementation missing */
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -41,13 +41,13 @@
|
|||||||
|
|
||||||
static kstat_ctl_t *kc;
|
static kstat_ctl_t *kc;
|
||||||
|
|
||||||
int machine_init(void)
|
int
|
||||||
|
machine_init(void)
|
||||||
{
|
{
|
||||||
kc = NULL;
|
kc = NULL;
|
||||||
|
|
||||||
kc = kstat_open();
|
kc = kstat_open();
|
||||||
if (kc == NULL)
|
if (kc == NULL) {
|
||||||
{
|
|
||||||
perror("kstat_open");
|
perror("kstat_open");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
@@ -55,10 +55,10 @@ int machine_init(void)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_close(void)
|
int
|
||||||
{
|
machine_close(void)
|
||||||
if (kc != NULL)
|
|
||||||
{
|
{
|
||||||
|
if (kc != NULL) {
|
||||||
kstat_close(kc);
|
kstat_close(kc);
|
||||||
kc = NULL;
|
kc = NULL;
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,8 @@ int machine_close(void)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_battstat(int *acstat, int *battflag, int *percent)
|
int
|
||||||
|
machine_get_battstat(int *acstat, int *battflag, int *percent)
|
||||||
{
|
{
|
||||||
*acstat = LCDP_AC_ON;
|
*acstat = LCDP_AC_ON;
|
||||||
*battflag = LCDP_BATT_ABSENT;
|
*battflag = LCDP_BATT_ABSENT;
|
||||||
@@ -75,7 +76,8 @@ int machine_get_battstat(int *acstat, int *battflag, int *percent)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_fs(mounts_type fs[], int *cnt)
|
int
|
||||||
|
machine_get_fs(mounts_type fs[], int *cnt)
|
||||||
{
|
{
|
||||||
FILE *mtab_fd;
|
FILE *mtab_fd;
|
||||||
char line[256];
|
char line[256];
|
||||||
@@ -93,13 +95,11 @@ int machine_get_fs(mounts_type fs[], int *cnt)
|
|||||||
#error "Can't find your mounted filesystem table file."
|
#error "Can't find your mounted filesystem table file."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Get rid of old, unmounted filesystems...
|
/* Get rid of old, unmounted filesystems... */
|
||||||
memset(fs, 0, sizeof(mounts_type) * 256);
|
memset(fs, 0, sizeof(mounts_type) * 256);
|
||||||
|
|
||||||
while (x < 256)
|
while (x < 256) {
|
||||||
{
|
if (fgets(line, 256, mtab_fd) == NULL) {
|
||||||
if (fgets(line, 256, mtab_fd) == NULL)
|
|
||||||
{
|
|
||||||
fclose(mtab_fd);
|
fclose(mtab_fd);
|
||||||
*cnt = x;
|
*cnt = x;
|
||||||
break;
|
break;
|
||||||
@@ -114,8 +114,7 @@ int machine_get_fs(mounts_type fs[], int *cnt)
|
|||||||
#ifndef STAT_SMBFS
|
#ifndef STAT_SMBFS
|
||||||
&& strcmp(fs[x].type, "smbfs")
|
&& strcmp(fs[x].type, "smbfs")
|
||||||
#endif
|
#endif
|
||||||
)
|
) {
|
||||||
{
|
|
||||||
#ifdef STAT_STATVFS
|
#ifdef STAT_STATVFS
|
||||||
y = statvfs(fs[x].mpoint, &fsinfo);
|
y = statvfs(fs[x].mpoint, &fsinfo);
|
||||||
#elif STAT_STATFS2_BSIZE
|
#elif STAT_STATFS2_BSIZE
|
||||||
@@ -127,8 +126,7 @@ int machine_get_fs(mounts_type fs[], int *cnt)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
fs[x].blocks = fsinfo.f_blocks;
|
fs[x].blocks = fsinfo.f_blocks;
|
||||||
if (fs[x].blocks > 0)
|
if (fs[x].blocks > 0) {
|
||||||
{
|
|
||||||
fs[x].bsize = fsinfo.f_bsize;
|
fs[x].bsize = fsinfo.f_bsize;
|
||||||
fs[x].bfree = fsinfo.f_bfree;
|
fs[x].bfree = fsinfo.f_bfree;
|
||||||
fs[x].files = fsinfo.f_files;
|
fs[x].files = fsinfo.f_files;
|
||||||
@@ -144,7 +142,8 @@ int machine_get_fs(mounts_type fs[], int *cnt)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_load(load_type *curr_load)
|
int
|
||||||
|
machine_get_load(load_type * curr_load)
|
||||||
{
|
{
|
||||||
static load_type last_load = {0, 0, 0, 0, 0};
|
static load_type last_load = {0, 0, 0, 0, 0};
|
||||||
load_type load;
|
load_type load;
|
||||||
@@ -152,26 +151,22 @@ int machine_get_load(load_type *curr_load)
|
|||||||
struct cpu_stat cinfo;
|
struct cpu_stat cinfo;
|
||||||
|
|
||||||
k_space = kstat_lookup(kc, "cpu_stat", 0, "cpu_stat0");
|
k_space = kstat_lookup(kc, "cpu_stat", 0, "cpu_stat0");
|
||||||
if (k_space == NULL)
|
if (k_space == NULL) {
|
||||||
{
|
|
||||||
fprintf(stderr, "kstat lookup error\n");
|
fprintf(stderr, "kstat lookup error\n");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kstat_read(kc, k_space, NULL) == -1)
|
if (kstat_read(kc, k_space, NULL) == -1) {
|
||||||
{
|
|
||||||
fprintf(stderr, "kstat read error\n");
|
fprintf(stderr, "kstat read error\n");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
k_space = kstat_lookup(kc, "cpu_stat", -1, "cpu_stat0");
|
k_space = kstat_lookup(kc, "cpu_stat", -1, "cpu_stat0");
|
||||||
if (k_space == NULL)
|
if (k_space == NULL) {
|
||||||
{
|
|
||||||
fprintf(stderr, "kstat lookup error\n");
|
fprintf(stderr, "kstat lookup error\n");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
if (kstat_read(kc, k_space, &cinfo) == -1)
|
if (kstat_read(kc, k_space, &cinfo) == -1) {
|
||||||
{
|
|
||||||
fprintf(stderr, "kstat read error\n");
|
fprintf(stderr, "kstat read error\n");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
@@ -187,13 +182,14 @@ int machine_get_load(load_type *curr_load)
|
|||||||
curr_load->idle = load.idle - last_load.idle;
|
curr_load->idle = load.idle - last_load.idle;
|
||||||
curr_load->total = load.total - last_load.total;
|
curr_load->total = load.total - last_load.total;
|
||||||
|
|
||||||
// struct assingment is legal in C89
|
/* struct assingment is legal in C89 */
|
||||||
last_load = load;
|
last_load = load;
|
||||||
|
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_loadavg(double *load)
|
int
|
||||||
|
machine_get_loadavg(double *load)
|
||||||
{
|
{
|
||||||
double loadavg[LOADAVG_NSTATS];
|
double loadavg[LOADAVG_NSTATS];
|
||||||
|
|
||||||
@@ -205,7 +201,8 @@ int machine_get_loadavg(double *load)
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_meminfo(meminfo_type *result)
|
int
|
||||||
|
machine_get_meminfo(meminfo_type * result)
|
||||||
{
|
{
|
||||||
#define MAXSTRSIZE 80
|
#define MAXSTRSIZE 80
|
||||||
swaptbl_t *s;
|
swaptbl_t *s;
|
||||||
@@ -221,48 +218,41 @@ int machine_get_meminfo(meminfo_type *result)
|
|||||||
result[0].cache = 0;
|
result[0].cache = 0;
|
||||||
|
|
||||||
again:
|
again:
|
||||||
if ((num = swapctl(SC_GETNSWP, 0)) == -1)
|
if ((num = swapctl(SC_GETNSWP, 0)) == -1) {
|
||||||
{
|
|
||||||
perror("swapctl: GETNSWP");
|
perror("swapctl: GETNSWP");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num == 0)
|
if (num == 0) {
|
||||||
{
|
|
||||||
fprintf(stderr, "No Swap Devices Configured\n");
|
fprintf(stderr, "No Swap Devices Configured\n");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocate swaptable for num+1 entries */
|
/* allocate swaptable for num+1 entries */
|
||||||
if ((s = (swaptbl_t*)malloc(num * sizeof(swapent_t) + sizeof(struct swaptable))) == NULL)
|
if ((s = (swaptbl_t *) malloc(num * sizeof(swapent_t) + sizeof(struct swaptable))) == NULL) {
|
||||||
{
|
|
||||||
perror("malloc swap");
|
perror("malloc swap");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocate num+1 string holders */
|
/* allocate num+1 string holders */
|
||||||
if ((strtab = (char*)malloc((num + 1) * MAXSTRSIZE)) == NULL)
|
if ((strtab = (char *)malloc((num + 1) * MAXSTRSIZE)) == NULL) {
|
||||||
{
|
|
||||||
perror("malloc string holder");
|
perror("malloc string holder");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialize string pointers */
|
/* initialize string pointers */
|
||||||
for (i = 0; i < (num + 1); i++)
|
for (i = 0; i < (num + 1); i++) {
|
||||||
{
|
|
||||||
s->swt_ent[i].ste_path = strtab + (i * MAXSTRSIZE);
|
s->swt_ent[i].ste_path = strtab + (i * MAXSTRSIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
s->swt_n = num + 1;
|
s->swt_n = num + 1;
|
||||||
if ((n = swapctl(SC_LIST, s)) < 0)
|
if ((n = swapctl(SC_LIST, s)) < 0) {
|
||||||
{
|
|
||||||
perror("swapctl");
|
perror("swapctl");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* more were added */
|
/* more were added */
|
||||||
if (n > num)
|
if (n > num) {
|
||||||
{
|
|
||||||
free(s);
|
free(s);
|
||||||
free(strtab);
|
free(strtab);
|
||||||
goto again;
|
goto again;
|
||||||
@@ -271,8 +261,7 @@ again:
|
|||||||
result[1].total = 0;
|
result[1].total = 0;
|
||||||
result[1].free = 0;
|
result[1].free = 0;
|
||||||
|
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++) {
|
||||||
{
|
|
||||||
result[1].total = result[1].total + s->swt_ent[i].ste_pages * sysconf(_SC_PAGESIZE) / 1024;
|
result[1].total = result[1].total + s->swt_ent[i].ste_pages * sysconf(_SC_PAGESIZE) / 1024;
|
||||||
result[1].free = result[1].free + s->swt_ent[i].ste_free * sysconf(_SC_PAGESIZE) / 1024;
|
result[1].free = result[1].free + s->swt_ent[i].ste_free * sysconf(_SC_PAGESIZE) / 1024;
|
||||||
}
|
}
|
||||||
@@ -280,7 +269,8 @@ again:
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_procs(LinkedList *procs)
|
int
|
||||||
|
machine_get_procs(LinkedList * procs)
|
||||||
{
|
{
|
||||||
char buf[128];
|
char buf[128];
|
||||||
DIR *proc;
|
DIR *proc;
|
||||||
@@ -292,24 +282,23 @@ int machine_get_procs(LinkedList *procs)
|
|||||||
int procSize, procRSS, procData, procStk, procExe;
|
int procSize, procRSS, procData, procStk, procExe;
|
||||||
int threshold = 400, unique;
|
int threshold = 400, unique;
|
||||||
|
|
||||||
if ((proc = opendir("/proc")) == NULL)
|
if ((proc = opendir("/proc")) == NULL) {
|
||||||
{
|
|
||||||
perror("open /proc");
|
perror("open /proc");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((procdir = readdir(proc)))
|
while ((procdir = readdir(proc))) {
|
||||||
{
|
|
||||||
psinfo_t psinfo;
|
psinfo_t psinfo;
|
||||||
|
|
||||||
if (!strchr("1234567890", procdir->d_name[0]))
|
if (!strchr("1234567890", procdir->d_name[0]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
sprintf(buf, "/proc/%s/psinfo", procdir->d_name);
|
sprintf(buf, "/proc/%s/psinfo", procdir->d_name);
|
||||||
if ((StatusFile = fopen(buf, "r")) == NULL)
|
if ((StatusFile = fopen(buf, "r")) == NULL) {
|
||||||
{
|
/*
|
||||||
// Not a serious error; process has finished before we could
|
* Not a serious error; process has finished before
|
||||||
// examine it:
|
* we could examine it:
|
||||||
|
*/
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,25 +308,24 @@ int machine_get_procs(LinkedList *procs)
|
|||||||
procSize = psinfo.pr_size;
|
procSize = psinfo.pr_size;
|
||||||
procRSS = psinfo.pr_rssize;
|
procRSS = psinfo.pr_rssize;
|
||||||
|
|
||||||
// Following values not accurate, not sure what needs to be set to
|
/*
|
||||||
|
* Following values not accurate, not sure what needs to be
|
||||||
|
* set to
|
||||||
|
*/
|
||||||
procData = psinfo.pr_size;
|
procData = psinfo.pr_size;
|
||||||
procStk = 0;
|
procStk = 0;
|
||||||
procExe = 0;
|
procExe = 0;
|
||||||
|
|
||||||
fclose(StatusFile);
|
fclose(StatusFile);
|
||||||
|
|
||||||
if (procSize > threshold)
|
if (procSize > threshold) {
|
||||||
{
|
/* Figure out if it's sharing any memory... */
|
||||||
// Figure out if it's sharing any memory...
|
|
||||||
unique = 1;
|
unique = 1;
|
||||||
LL_Rewind(procs);
|
LL_Rewind(procs);
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
p = LL_Get(procs);
|
p = LL_Get(procs);
|
||||||
if (p)
|
if (p) {
|
||||||
{
|
if (0 == strcmp(p->name, procName)) {
|
||||||
if (0 == strcmp(p->name, procName))
|
|
||||||
{
|
|
||||||
unique = 0;
|
unique = 0;
|
||||||
p->number++;
|
p->number++;
|
||||||
p->totl += procData + procStk + procExe;
|
p->totl += procData + procStk + procExe;
|
||||||
@@ -345,19 +333,17 @@ int machine_get_procs(LinkedList *procs)
|
|||||||
}
|
}
|
||||||
} while (LL_Next(procs) == 0);
|
} while (LL_Next(procs) == 0);
|
||||||
|
|
||||||
// If this is the first one by this name...
|
/* If this is the first one by this name... */
|
||||||
if (unique)
|
if (unique) {
|
||||||
{
|
|
||||||
p = malloc(sizeof(procinfo_type));
|
p = malloc(sizeof(procinfo_type));
|
||||||
if (p == NULL)
|
if (p == NULL) {
|
||||||
{
|
|
||||||
perror("allocating process entry");
|
perror("allocating process entry");
|
||||||
goto end; // Ack! I hate goto's!
|
goto end;
|
||||||
}
|
}
|
||||||
strcpy(p->name, procName);
|
strcpy(p->name, procName);
|
||||||
p->totl = procData + procStk + procExe;
|
p->totl = procData + procStk + procExe;
|
||||||
p->number = 1;
|
p->number = 1;
|
||||||
// TODO: Check for errors here?
|
/* TODO: Check for errors here? */
|
||||||
LL_Push(procs, (void *)p);
|
LL_Push(procs, (void *)p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -368,7 +354,8 @@ end:
|
|||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_get_smpload(load_type *result, int *numcpus)
|
int
|
||||||
|
machine_get_smpload(load_type * result, int *numcpus)
|
||||||
{
|
{
|
||||||
static load_type last_load[MAX_CPUS];
|
static load_type last_load[MAX_CPUS];
|
||||||
load_type curr_load[MAX_CPUS];
|
load_type curr_load[MAX_CPUS];
|
||||||
@@ -384,8 +371,7 @@ int machine_get_smpload(load_type *result, int *numcpus)
|
|||||||
|
|
||||||
k_space = kstat_lookup(kc, "cpu_stat", count, buffer);
|
k_space = kstat_lookup(kc, "cpu_stat", count, buffer);
|
||||||
|
|
||||||
if ((k_space != NULL) && (kstat_read(kc, k_space, NULL) != -1))
|
if ((k_space != NULL) && (kstat_read(kc, k_space, NULL) != -1)) {
|
||||||
{
|
|
||||||
struct cpu_stat cinfo;
|
struct cpu_stat cinfo;
|
||||||
|
|
||||||
k_space = kstat_lookup(kc, "cpu_stat", -1, buffer);
|
k_space = kstat_lookup(kc, "cpu_stat", -1, buffer);
|
||||||
@@ -404,10 +390,10 @@ int machine_get_smpload(load_type *result, int *numcpus)
|
|||||||
result[ncpu].system = curr_load[ncpu].system - last_load[ncpu].system;
|
result[ncpu].system = curr_load[ncpu].system - last_load[ncpu].system;
|
||||||
result[ncpu].idle = curr_load[ncpu].idle - last_load[ncpu].idle;
|
result[ncpu].idle = curr_load[ncpu].idle - last_load[ncpu].idle;
|
||||||
|
|
||||||
// struct assignment is legal in C89
|
/* struct assignment is legal in C89 */
|
||||||
last_load[ncpu] = curr_load[ncpu];
|
last_load[ncpu] = curr_load[ncpu];
|
||||||
|
|
||||||
// restrict # CPUs to min(*numcpus, MAX_CPUS)
|
/* restrict # CPUs to min(*numcpus, MAX_CPUS) */
|
||||||
ncpu++;
|
ncpu++;
|
||||||
if ((ncpu >= *numcpus) || (ncpu >= MAX_CPUS))
|
if ((ncpu >= *numcpus) || (ncpu >= MAX_CPUS))
|
||||||
break;
|
break;
|
||||||
@@ -419,7 +405,8 @@ int machine_get_smpload(load_type *result, int *numcpus)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* TODO get idle time! */
|
/* TODO get idle time! */
|
||||||
int machine_get_uptime(double *up, double *idle)
|
int
|
||||||
|
machine_get_uptime(double *up, double *idle)
|
||||||
{
|
{
|
||||||
struct utmpx *u, id;
|
struct utmpx *u, id;
|
||||||
load_type curr_load;
|
load_type curr_load;
|
||||||
@@ -444,11 +431,11 @@ int machine_get_uptime(double *up, double *idle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get network statistics */
|
/* Get network statistics */
|
||||||
int machine_get_iface_stats (IfaceInfo *interface)
|
int
|
||||||
|
machine_get_iface_stats(IfaceInfo * interface)
|
||||||
{
|
{
|
||||||
/* Implementation missing */
|
/* Implementation missing */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* sun */
|
#endif /* sun */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user