On Mon, 10 Jul 2006, Weldon Goree wrote:
> sysctl(3) says that sysctl({CTL_HW, HW_SENSORS}, 2, NULL, &some_size_t,
> NULL, 0) should give me the size of the array of struct sensor's that
> sysctl({CTL_HW, HW_SENSORS}, 2, &some_buffer, &length_thereof, NULL, 0)
> will put into &some_buffer.
>
> Or so I thought. In fact, it returns -1 and sets errno to ENOTDIR, which
> it then diagnoses as my specifying a non-terminal MIB. sysctl(1) shows
> me that I have 7 hw.sensors, but obviously that is a variable among
> systems; how am I supposed to find the number of struct sensor's that
> the buffer must hold? And how do I get all of them at once like (I
> think) sysctl(3) says I can? Should I just run sysctl({CTL_HW,
> HW_SENSORS, i}, 3 ...) for increasing values of i until it returns -1?
I'm afraid it's seven worse. sensors are not contiguous. On my amd64,
I see:
hw.sensors.0=it0, Fan1, 3183 RPM
hw.sensors.2=it0, Fan3, 5273 RPM
hw.sensors.3=it0, VCORE_A, 1.36 V DC
...
Take a look how sbin/sysctl does it's think. AFAIK, there's no other
way. This is something that really needs improvement.
-Otto