diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2015-10-05 11:22:50 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2015-10-05 11:22:50 -0300 |
commit | bf276a099323788f79148dfa2409e1dd9ebdcc10 (patch) | |
tree | ce752e1fca73ed6418e7877175f8319cd08250be /darwin | |
parent | 5c2b0a6bbcffaa110b3eb90da77b91ef43025c7b (diff) | |
parent | 6a21d2f3a6d1f4735e5a2a2145eb78309f4d9073 (diff) |
Merge pull request #274 from mmcco/master
Cleanup and initial OpenBSD support
Diffstat (limited to 'darwin')
-rw-r--r-- | darwin/DarwinProcessList.c | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index 9afee58b..d45ac09c 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -40,16 +40,14 @@ void ProcessList_getHostInfo(host_basic_info_data_t *p) { 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)) { - fprintf(stderr, "Unable to retrieve host info\n"); - exit(2); + err(2, "Unable to retrieve host info\n"); } } void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) { if(NULL != p && NULL != *p) { if(0 != munmap(*p, vm_page_size)) { - fprintf(stderr, "Unable to free old CPU load information\n"); - exit(8); + err(8, "Unable to free old CPU load information\n"); } } @@ -62,8 +60,7 @@ unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) { // 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)) { - fprintf(stderr, "Unable to retrieve CPU info\n"); - exit(4); + err(4, "Unable to retrieve CPU info\n"); } return cpu_count; @@ -72,10 +69,8 @@ unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) { void ProcessList_getVMStats(vm_statistics64_t p) { mach_msg_type_number_t info_size = HOST_VM_INFO64_COUNT; - if(0 != host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info_t)p, &info_size)) { - fprintf(stderr, "Unable to retrieve VM statistics\n"); - exit(9); - } + if (host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info_t)p, &info_size) != 0) + err(9, "Unable to retrieve VM statistics\n"); } struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) { @@ -87,21 +82,15 @@ struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) { * process entry or two. */ *count = 0; - if(0 > sysctl(mib, 4, NULL, count, NULL, 0)) { - fprintf(stderr, "Unable to get size of kproc_infos"); - exit(5); - } + if (sysctl(mib, 4, NULL, count, NULL, 0) < 0) + err(5, "Unable to get size of kproc_infos"); - processes = (struct kinfo_proc *)malloc(*count); - if(NULL == processes) { - fprintf(stderr, "Out of memory for kproc_infos\n"); - exit(6); - } + processes = malloc(*count); + if (processes == NULL) + errx(6, "Out of memory for kproc_infos"); - if(0 > sysctl(mib, 4, processes, count, NULL, 0)) { - fprintf(stderr, "Unable to get kinfo_procs\n"); - exit(7); - } + if (sysctl(mib, 4, processes, count, NULL, 0) < 0) + err(7, "Unable to get kinfo_procs"); *count = *count / sizeof(struct kinfo_proc); |