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