clean-up (Eric Pooch)

This commit is contained in:
marschap
2007-02-04 20:45:00 +00:00
parent 70defdae6d
commit 875574fd32
+8 -9
View File
@@ -60,8 +60,6 @@
#include <CoreFoundation/CoreFoundation.h> #include <CoreFoundation/CoreFoundation.h>
#include <IOKit/ps/IOPowerSources.h> #include <IOKit/ps/IOPowerSources.h>
#include <IOKit/ps/IOPSKeys.h> #include <IOKit/ps/IOPSKeys.h>
//AUTOFRAMEWORK(CoreFoundation)
//AUTOFRAMEWORK(IOKit)
static int pageshift; static int pageshift;
#define pagetok(size) ((size) << pageshift) #define pagetok(size) ((size) << pageshift)
@@ -152,7 +150,8 @@ 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, /* There is a way to check this through the IOKit,
but I am not sure what gets for kIOPSLowWarnLevelKey and kIOPSDeadWarnLevelKey, and this is easier. 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)
@@ -317,24 +316,23 @@ int machine_get_procs(LinkedList *procs)
size_t size = 0; size_t size = 0;
/* Call sysctl with a NULL buffer. */ /* 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 *)malloc(size); kprocs = (struct kinfo_proc *)alloca(size);
if (kprocs == NULL) if (kprocs == NULL)
{ {
perror("mem_malloc"); 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");
free(kprocs);
return FALSE; return FALSE;
} }
@@ -375,7 +373,9 @@ int machine_get_procs(LinkedList *procs)
p->totl = (unsigned long)(/*info.virtual_size*/ info.resident_size / 1024); p->totl = (unsigned long)(/*info.virtual_size*/ info.resident_size / 1024);
} }
} else { } else {
/* This error pops up very often and doesn't seem to be a serious problem. /* 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"); perror("task_for_pid");
printf("process: %s, owner:%d\n", kprocs->kp_proc.p_comm, kprocs->kp_eproc.e_pcred.p_ruid); */ printf("process: %s, owner:%d\n", kprocs->kp_proc.p_comm, kprocs->kp_eproc.e_pcred.p_ruid); */
p->totl = 0; p->totl = 0;
@@ -383,7 +383,6 @@ int machine_get_procs(LinkedList *procs)
} }
kprocs -= i; kprocs -= i;
free(kprocs);
return(TRUE); return(TRUE);
} }