Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
htop
Commits
fd5dd660
Commit
fd5dd660
authored
Nov 02, 2015
by
Hisham Muhammad
Browse files
Merge pull request #299 from mmcco/master
OpenBSD port updates and error exit improvements
parents
b669540e
cd3d2337
Changes
3
Show whitespace changes
Inline
Side-by-side
darwin/DarwinProcessList.c
View file @
fd5dd660
...
@@ -41,14 +41,14 @@ void ProcessList_getHostInfo(host_basic_info_data_t *p) {
...
@@ -41,14 +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
))
{
err
(
2
,
"Unable to retrieve host info
\n
"
);
CRT_fatalError
(
"Unable to retrieve host info
\n
"
);
}
}
}
}
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
))
{
err
(
8
,
"Unable to free old CPU load information
\n
"
);
CRT_fatalError
(
"Unable to free old CPU load information
\n
"
);
}
}
}
}
...
@@ -61,7 +61,7 @@ unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) {
...
@@ -61,7 +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
))
{
err
(
4
,
"Unable to retrieve CPU info
\n
"
);
CRT_fatalError
(
"Unable to retrieve CPU info
\n
"
);
}
}
return
cpu_count
;
return
cpu_count
;
...
@@ -71,7 +71,7 @@ void ProcessList_getVMStats(vm_statistics64_t p) {
...
@@ -71,7 +71,7 @@ void ProcessList_getVMStats(vm_statistics64_t p) {
mach_msg_type_number_t
info_size
=
HOST_VM_INFO64_COUNT
;
mach_msg_type_number_t
info_size
=
HOST_VM_INFO64_COUNT
;
if
(
host_statistics64
(
mach_host_self
(),
HOST_VM_INFO64
,
(
host_info_t
)
p
,
&
info_size
)
!=
0
)
if
(
host_statistics64
(
mach_host_self
(),
HOST_VM_INFO64
,
(
host_info_t
)
p
,
&
info_size
)
!=
0
)
err
(
9
,
"Unable to retrieve VM statistics
\n
"
);
CRT_fatalError
(
"Unable to retrieve VM statistics
\n
"
);
}
}
struct
kinfo_proc
*
ProcessList_getKInfoProcs
(
size_t
*
count
)
{
struct
kinfo_proc
*
ProcessList_getKInfoProcs
(
size_t
*
count
)
{
...
@@ -84,14 +84,14 @@ struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) {
...
@@ -84,14 +84,14 @@ struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) {
*/
*/
*
count
=
0
;
*
count
=
0
;
if
(
sysctl
(
mib
,
4
,
NULL
,
count
,
NULL
,
0
)
<
0
)
if
(
sysctl
(
mib
,
4
,
NULL
,
count
,
NULL
,
0
)
<
0
)
err
(
5
,
"Unable to get size of kproc_infos"
);
CRT_fatalError
(
"Unable to get size of kproc_infos"
);
processes
=
malloc
(
*
count
);
processes
=
malloc
(
*
count
);
if
(
processes
==
NULL
)
if
(
processes
==
NULL
)
errx
(
6
,
"Out of memory for kproc_infos"
);
CRT_fatalError
(
"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"
);
CRT_fatalError
(
"Unable to get kinfo_procs"
);
*
count
=
*
count
/
sizeof
(
struct
kinfo_proc
);
*
count
=
*
count
/
sizeof
(
struct
kinfo_proc
);
...
...
openbsd/OpenBSDProcessList.c
View file @
fd5dd660
...
@@ -13,7 +13,6 @@ in the source distribution for its full text.
...
@@ -13,7 +13,6 @@ in the source distribution for its full text.
#include <unistd.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdlib.h>
#include <errno.h>
#include <errno.h>
#include <err.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/proc.h>
...
@@ -60,7 +59,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
...
@@ -60,7 +59,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
size
=
sizeof
(
fscale
);
size
=
sizeof
(
fscale
);
if
(
sysctl
(
fmib
,
2
,
&
fscale
,
&
size
,
NULL
,
0
)
<
0
)
if
(
sysctl
(
fmib
,
2
,
&
fscale
,
&
size
,
NULL
,
0
)
<
0
)
err
(
1
,
"fscale sysctl call failed"
);
CRT_fatalError
(
"fscale sysctl call failed"
);
for
(
i
=
0
;
i
<
pl
->
cpuCount
;
i
++
)
{
for
(
i
=
0
;
i
<
pl
->
cpuCount
;
i
++
)
{
fpl
->
cpus
[
i
].
totalTime
=
1
;
fpl
->
cpus
[
i
].
totalTime
=
1
;
...
@@ -90,7 +89,7 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) {
...
@@ -90,7 +89,7 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) {
size_t
size
=
sizeof
(
uvmexp
);
size_t
size
=
sizeof
(
uvmexp
);
if
(
sysctl
(
uvmexp_mib
,
2
,
&
uvmexp
,
&
size
,
NULL
,
0
)
<
0
)
{
if
(
sysctl
(
uvmexp_mib
,
2
,
&
uvmexp
,
&
size
,
NULL
,
0
)
<
0
)
{
err
(
1
,
"uvmexp sysctl call failed"
);
CRT_fatalError
(
"uvmexp sysctl call failed"
);
}
}
//kb_pagesize = uvmexp.pagesize / 1024;
//kb_pagesize = uvmexp.pagesize / 1024;
...
@@ -133,11 +132,11 @@ char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in
...
@@ -133,11 +132,11 @@ char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in
argv
=
kvm_getargv
(
kd
,
kproc
,
500
);
argv
=
kvm_getargv
(
kd
,
kproc
,
500
);
if
(
argv
==
NULL
)
if
(
argv
==
NULL
)
err
(
1
,
"kvm call failed"
);
CRT_fatalError
(
"kvm call failed"
);
str
=
buf
=
malloc
(
len
+
1
);
str
=
buf
=
malloc
(
len
+
1
);
if
(
str
==
NULL
)
if
(
str
==
NULL
)
err
(
1
,
"out of memory"
);
CRT_fatalError
(
"out of memory"
);
while
(
*
argv
!=
NULL
)
{
while
(
*
argv
!=
NULL
)
{
cpsz
=
MIN
(
len
,
strlen
(
*
argv
));
cpsz
=
MIN
(
len
,
strlen
(
*
argv
));
...
...
openbsd/Platform.c
View file @
fd5dd660
...
@@ -38,6 +38,7 @@ in the source distribution for its full text.
...
@@ -38,6 +38,7 @@ in the source distribution for its full text.
/*{
/*{
#include "Action.h"
#include "Action.h"
#include "BatteryMeter.h"
#include "BatteryMeter.h"
#include "SignalsPanel.h"
extern ProcessFieldData Process_fields[];
extern ProcessFieldData Process_fields[];
...
@@ -210,8 +211,7 @@ double Platform_setCPUValues(Meter* this, int cpu) {
...
@@ -210,8 +211,7 @@ double Platform_setCPUValues(Meter* this, int cpu) {
size_t
size
=
sizeof
(
double
)
*
CPUSTATES
;
size_t
size
=
sizeof
(
double
)
*
CPUSTATES
;
int
mib
[]
=
{
CTL_KERN
,
KERN_CPTIME2
,
cpu
-
1
};
int
mib
[]
=
{
CTL_KERN
,
KERN_CPTIME2
,
cpu
-
1
};
if
(
sysctl
(
mib
,
3
,
new_v
,
&
size
,
NULL
,
0
)
==
-
1
)
{
if
(
sysctl
(
mib
,
3
,
new_v
,
&
size
,
NULL
,
0
)
==
-
1
)
{
puts
(
"err!"
);
return
0
.;
//return 0.;
}
}
// XXX: why?
// XXX: why?
...
@@ -232,7 +232,7 @@ double Platform_setCPUValues(Meter* this, int cpu) {
...
@@ -232,7 +232,7 @@ double Platform_setCPUValues(Meter* this, int cpu) {
if
(
perc
<=
100
.
&&
perc
>=
0
.)
{
if
(
perc
<=
100
.
&&
perc
>=
0
.)
{
return
perc
;
return
perc
;
}
else
{
}
else
{
return
12
.
34
;
return
0
.
;
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment