C++ FLTK displaying a sysctl value

Figured out a screenshot solution that doesn't drag in too many dependencies. Here's the CPU gauge from this post, and the demo from the ancient sources. I'm having fun so I'll probably try a 4-CPU version sometime today.
 

Attachments

  • 2025-12-12-100025_290x290_scrot.png
    2025-12-12-100025_290x290_scrot.png
    11 KB · Views: 11
  • 2025-12-12-095625_540x440_scrot.png
    2025-12-12-095625_540x440_scrot.png
    29.9 KB · Views: 12
Here's a 4-gauge version. It didn't turn out as nicely as I had hoped. Again unzip the sources somewhere and compile them like this:
Code:
c++ -o fltk_temp $(fltk-config --cxxflags) Fl_Gauge.cxx fltk_temp.cpp $(fltk-config --ldflags)
And run it like this:
Code:
./fltk_temp
 

Attachments

  • 2025-12-12-114938_570x160_scrot.png
    2025-12-12-114938_570x160_scrot.png
    8 KB · Views: 11
  • fltk_temp.zip
    fltk_temp.zip
    6.5 KB · Views: 7
I am studying this example from GIST.
Please help me understand it.
C:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/sysctl.h>

int main(void) {
  u_int val[3] = {0};
  char buf[256] = {""};
  size_t len = sizeof(val);
  size_t len2 = sizeof(buf);
  if (0 != (sysctlbyname("dev.cpu.0.temperature", &val, &len, NULL, 0))) {
    if (0 != (sysctlbyname("dev.aibs.0.%desc", buf, &len2, NULL, 0))) {
      puts("failed!");
      return EXIT_FAILURE;
    }
  }
  if (0 != (strcmp(buf, "")))
    printf("%s\n", buf);
  else
    printf("%lu\n", (unsigned long)val[0]);

  return EXIT_SUCCESS;
}

I can grasp most of this but I don't understand len2 or its use.
dev.aibs.0.%desc"

What is that sysctl? Some failure trigger for an unfound sysctl?

sysctl: unknown oid 'dev.aibs
 
The term aibs in the context of FreeBSD refers to the ASUSTeK AI Booster hardware monitoring driver (aibs(4) manual page). This driver is used to read sensor values (like voltages and temperatures) from compatible ASUS motherboards that use the ACPI ATK0110 chip.

int sysctlbyname(const char *name, void *oldp, size_t *oldlenp, const void *newp, size_t newlen);
oldlenp -> len2
 
To expand on what Covacat and Alain have said, the "dev.aibs.0.%desc" sysctl returns the description of the aibs(4) sensor at index 0. From the man page:
The driver supports an arbitrary set of sensors, provides descriptions regarding what each sensor is used for...

This is going to be a string of characters of some arbitrary length and sysctlbyname(3) needs a place to put them. In the code above buf is the place, and len2 is the maximum number of characters that can be put there.
 
Example 8 from above PDF at very bottom was an indicator for me:
static int foo_widgets = 5;
Sometimes I have seen examples in brackets.
static int foo_widgets = [5];


Think I see from the format why the number 5. The function has 5 parameters???? Is that what the 5 means?

NVEVERMIND I GOT IT. THIS IS VARIABLE VALUE
 
Back
Top