Hi Tony,
On 7/1/24 9:04 AM, Luck, Tony wrote:
+static bool cpus_offline_empty(void) +{
- char offline_cpus_str[64];
- FILE *fp;
- fp = fopen("/sys/devices/system/cpu/offline", "r");
Check for fp == NULL before using it.
- if (fscanf(fp, "%s", offline_cpus_str) < 0) {
fscanf() seems like a heavy hammer.
Do you perhaps have any recommendations that should be used instead of fscanf()? I checked with stat() but could not see a difference between file with a CPU and a file without. Other alternative is open()/read()/close()? Looks like when there are no offline CPUs then the file will only contain '\n' so it may be possible to read one byte from the file and confirm it is '\n' as a check for "cpus_offline_empty()".
Reinette