mirror of https://github.com/xzeldon/htop.git
Change more fprintf(stderr, ...); exit(...); to err[x](...). Tweak a few existing ones and fix some style.
This commit is contained in:
parent
e2bbd5cfa4
commit
571cbc0aa1
|
@ -41,16 +41,14 @@ void ProcessList_getHostInfo(host_basic_info_data_t *p) {
|
||||||
mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT;
|
mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT;
|
||||||
|
|
||||||
if(0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) {
|
if(0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) {
|
||||||
fprintf(stderr, "Unable to retrieve host info\n");
|
err(2, "Unable to retrieve host info\n");
|
||||||
exit(2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) {
|
void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) {
|
||||||
if(NULL != p && NULL != *p) {
|
if(NULL != p && NULL != *p) {
|
||||||
if(0 != munmap(*p, vm_page_size)) {
|
if(0 != munmap(*p, vm_page_size)) {
|
||||||
fprintf(stderr, "Unable to free old CPU load information\n");
|
err(8, "Unable to free old CPU load information\n");
|
||||||
exit(8);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,8 +61,7 @@ unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) {
|
||||||
|
|
||||||
// TODO Improving the accuracy of the load counts woule help a lot.
|
// TODO Improving the accuracy of the load counts woule help a lot.
|
||||||
if(0 != host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, (processor_info_array_t *)p, &info_size)) {
|
if(0 != host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, (processor_info_array_t *)p, &info_size)) {
|
||||||
fprintf(stderr, "Unable to retrieve CPU info\n");
|
err(4, "Unable to retrieve CPU info\n");
|
||||||
exit(4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cpu_count;
|
return cpu_count;
|
||||||
|
@ -91,7 +88,7 @@ struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) {
|
||||||
|
|
||||||
processes = malloc(*count);
|
processes = malloc(*count);
|
||||||
if (processes == NULL)
|
if (processes == NULL)
|
||||||
err(6, "Out of memory for kproc_infos");
|
errx(6, "Out of memory for kproc_infos");
|
||||||
|
|
||||||
if (sysctl(mib, 4, processes, count, NULL, 0) < 0)
|
if (sysctl(mib, 4, processes, count, NULL, 0) < 0)
|
||||||
err(7, "Unable to get kinfo_procs");
|
err(7, "Unable to get kinfo_procs");
|
||||||
|
|
7
htop.c
7
htop.c
|
@ -132,11 +132,11 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
|
||||||
char* saveptr;
|
char* saveptr;
|
||||||
char* pid = strtok_r(argCopy, ",", &saveptr);
|
char* pid = strtok_r(argCopy, ",", &saveptr);
|
||||||
|
|
||||||
if( !flags.pidWhiteList ) {
|
if(!flags.pidWhiteList) {
|
||||||
flags.pidWhiteList = Hashtable_new(8, false);
|
flags.pidWhiteList = Hashtable_new(8, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
while( pid ) {
|
while(pid) {
|
||||||
unsigned int num_pid = atoi(pid);
|
unsigned int num_pid = atoi(pid);
|
||||||
Hashtable_put(flags.pidWhiteList, num_pid, (void *) 1);
|
Hashtable_put(flags.pidWhiteList, num_pid, (void *) 1);
|
||||||
pid = strtok_r(NULL, ",", &saveptr);
|
pid = strtok_r(NULL, ",", &saveptr);
|
||||||
|
@ -176,8 +176,7 @@ int main(int argc, char** argv) {
|
||||||
|
|
||||||
#ifdef HAVE_PROC
|
#ifdef HAVE_PROC
|
||||||
if (access(PROCDIR, R_OK) != 0) {
|
if (access(PROCDIR, R_OK) != 0) {
|
||||||
fprintf(stderr, "Error: could not read procfs (compiled to look in %s).\n", PROCDIR);
|
errx(1, "Error: could not read procfs (compiled to look in %s).\n", PROCDIR);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue