1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
//! Partial port of `solaris/Platform.c` — htop's Solaris/illumos platform
//! hooks.
//!
//! Ported here (self-contained: only `libc` / Rust std and the already-ported
//! `NetworkIOData` / `DiskIOData` / `ACPresence`):
//! - `Platform_init` (`Platform.c:148`)
//! - `Platform_done` (`Platform.c:153`)
//! - `Platform_setBindings` (`Platform.c:157`)
//! - `Platform_getUptime` (`Platform.c:162`)
//! - `Platform_getLoadAverage` (`Platform.c:178`)
//! - `Platform_getFileDescriptors` (`Platform.c:328`)
//! - `Platform_getDiskIO` (`Platform.c:333`)
//! - `Platform_getNetworkIO` (`Platform.c:339`)
//! - `Platform_getBattery` (`Platform.c:345`)
//!
//! Still `todo!()` and blocked on unported substrate:
//! - `Platform_getMaxPid` — needs `libkstat` (`kstat_open`/`kstat_lookup`/
//! `kstat_read`) FFI and the `kvar_t` struct.
//! - the `Platform_set*Values` meter setters — `Meter::host` (`meter.rs`) is
//! typed as the concrete `LinuxMachine`, so a `SolarisMachine`-backed meter
//! is unmodeled.
//! - `Platform_buildenv` / `Platform_getProcessEnv` — need `libproc`
//! (`Pgrab`/`Penv_iter`/`Prelease`) FFI.
//! - `Platform_getProcessLocks` — `FileLocks_ProcessData` is unmodeled
//! (Solaris's body returns `NULL` unconditionally).
use CStr;
use c_int;
use ptr;
use crateACPresence;
use crateDiskIOData;
use crateNetworkIOData;
// `LOADAVG_1MIN` / `LOADAVG_5MIN` / `LOADAVG_15MIN` (`sys/loadavg.h`).
const LOADAVG_1MIN: usize = 0;
const LOADAVG_5MIN: usize = 1;
const LOADAVG_15MIN: usize = 2;
/// Port of `bool Platform_init(void)` (`Platform.c:148`).
/// Port of `void Platform_done(void)` (`Platform.c:153`).
/// Port of `void Platform_setBindings(Htop_Action* keys)` (`Platform.c:157`).
/// Port of `int Platform_getUptime(void)` (`Platform.c:162`). Scans the
/// `utmpx` database for the "system boot" record and returns the seconds
/// since it.
/// Port of `void Platform_getLoadAverage(double* one, double* five, double*
/// fifteen)` (`Platform.c:178`).
/// TODO: port of `pid_t Platform_getMaxPid(void)` from `Platform.c:191`.
/// Blocked: needs `libkstat` (`kstat_open`/`kstat_lookup`/`kstat_read`) FFI
/// and the `kvar_t` struct (`v_proc`).
/// TODO: port of `double Platform_setCPUValues(Meter* this, unsigned int cpu)`
/// from `Platform.c:211`. Blocked: `Meter::host` typed as `LinuxMachine`; a
/// `SolarisMachine`-backed meter is unmodeled.
/// TODO: port of `void Platform_setMemoryValues(Meter* this)` from
/// `Platform.c:252`. Blocked: `Meter::host` typed as `LinuxMachine`.
/// TODO: port of `void Platform_setSwapValues(Meter* this)` from
/// `Platform.c:260`. Blocked: `Meter::host` typed as `LinuxMachine`.
/// TODO: port of `void Platform_setZfsArcValues(Meter* this)` from
/// `Platform.c:266`. Blocked: `Meter::host` typed as `LinuxMachine`.
/// TODO: port of `void Platform_setZfsCompressedArcValues(Meter* this)` from
/// `Platform.c:272`. Blocked: `Meter::host` typed as `LinuxMachine`.
/// TODO: port of `static int Platform_buildenv(void* accum, const prmap_t*
/// map, const char* name)` from `Platform.c:278`. Blocked: `libproc`
/// `Penv_iter` callback with the `prmap_t` / `ps_prochandle` types.
/// TODO: port of `char* Platform_getProcessEnv(pid_t pid)` from
/// `Platform.c:300`. Blocked: needs `libproc` (`Pgrab`/`Penv_iter`/`Prelease`)
/// FFI.
/// TODO: port of `FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid)`
/// from `Platform.c:323`. Blocked: `FileLocks_ProcessData` is unmodeled
/// (Solaris's body returns `NULL` unconditionally).
/// Port of `void Platform_getFileDescriptors(double* used, double* max)`
/// (`Platform.c:328`). Solaris does not yet expose these, so both are `NaN`.
/// Port of `bool Platform_getDiskIO(DiskIOData* data)` (`Platform.c:333`).
/// Not yet implemented on Solaris; returns `false` without touching `data`.
/// Port of `bool Platform_getNetworkIO(NetworkIOData* data)`
/// (`Platform.c:339`). Not yet implemented on Solaris; returns `false`.
/// Port of `void Platform_getBattery(double* percent, ACPresence* isOnAC)`
/// (`Platform.c:345`). Solaris has no battery probe, so `percent` is `NaN` and
/// the AC state is `AC_ERROR`.