cosmetics: if, for, while, wtf
This commit is contained in:
parent
ff4a80bd87
commit
9178cbc0d3
|
@ -135,8 +135,7 @@ _cpu_state_get(cpu_core_t **cores, int ncpu)
|
||||||
if (!ncpu)
|
if (!ncpu)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < ncpu; i++)
|
for (i = 0; i < ncpu; i++) {
|
||||||
{
|
|
||||||
core = cores[i];
|
core = cores[i];
|
||||||
size = sizeof(struct cpustats);
|
size = sizeof(struct cpustats);
|
||||||
cpu_time_mib[2] = i;
|
cpu_time_mib[2] = i;
|
||||||
|
|
|
@ -117,44 +117,44 @@ system_memory_usage_get(meminfo_t *memory)
|
||||||
len = sizeof(memory->total);
|
len = sizeof(memory->total);
|
||||||
if (sysctl(mib, 2, &memory->total, &len, NULL, 0) == -1)
|
if (sysctl(mib, 2, &memory->total, &len, NULL, 0) == -1)
|
||||||
return;
|
return;
|
||||||
if ((active =
|
|
||||||
_sysctlfromname("vm.stats.vm.v_active_count", mib, 4, &len)) < 0)
|
if ((active = _sysctlfromname("vm.stats.vm.v_active_count", mib, 4, &len)) == -1)
|
||||||
return;
|
return;
|
||||||
if ((inactive =
|
|
||||||
_sysctlfromname("vm.stats.vm.v_inactive_count", mib, 4, &len)) < 0)
|
if ((inactive = _sysctlfromname("vm.stats.vm.v_inactive_count", mib, 4, &len)) == -1)
|
||||||
return;
|
return;
|
||||||
if ((wired =
|
|
||||||
_sysctlfromname("vm.stats.vm.v_wire_count", mib, 4, &len)) < 0)
|
if ((wired = _sysctlfromname("vm.stats.vm.v_wire_count", mib, 4, &len)) == -1)
|
||||||
return;
|
return;
|
||||||
if ((cached =
|
|
||||||
_sysctlfromname("vm.stats.vm.v_cache_count", mib, 4, &len)) < 0)
|
if ((cached = _sysctlfromname("vm.stats.vm.v_cache_count", mib, 4, &len)) == -1)
|
||||||
return;
|
return;
|
||||||
if ((free = _sysctlfromname("vm.stats.vm.v_free_count", mib, 4, &len)) < 0)
|
|
||||||
|
if ((free = _sysctlfromname("vm.stats.vm.v_free_count", mib, 4, &len)) == -1)
|
||||||
return;
|
return;
|
||||||
if ((buffered = _sysctlfromname("vfs.bufspace", mib, 2, &len)) < 0)
|
|
||||||
|
if ((buffered = _sysctlfromname("vfs.bufspace", mib, 2, &len)) == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if ((zfs_arc = _sysctlfromname("kstat.zfs.misc.arcstats.c", mib, 5, &len)) != -1)
|
||||||
|
memory->zfs_arc_used = zfs_arc;
|
||||||
|
|
||||||
memory->used = ((active + wired + cached) * page_size);
|
memory->used = ((active + wired + cached) * page_size);
|
||||||
memory->buffered = buffered;
|
memory->buffered = buffered;
|
||||||
memory->cached = (cached * page_size);
|
memory->cached = (cached * page_size);
|
||||||
|
|
||||||
result = _sysctlfromname("vm.swap_total", mib, 2, &len);
|
result = _sysctlfromname("vm.swap_total", mib, 2, &len);
|
||||||
if (result < 0)
|
if (result == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
memory->swap_total = result;
|
memory->swap_total = result;
|
||||||
|
|
||||||
miblen = 3;
|
miblen = 3;
|
||||||
if (sysctlnametomib("vm.swap_info", mib, &miblen) == -1) return;
|
if (sysctlnametomib("vm.swap_info", mib, &miblen) == -1) return;
|
||||||
|
|
||||||
if ((zfs_arc = _sysctlfromname("kstat.zfs.misc.arcstats.c", mib, 5, &len)) != -1)
|
|
||||||
{
|
|
||||||
memory->zfs_arc_used = zfs_arc;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct xswdev xsw;
|
struct xswdev xsw;
|
||||||
|
|
||||||
for (i = 0; ; i++)
|
for (i = 0; ; i++) {
|
||||||
{
|
|
||||||
mib[miblen] = i;
|
mib[miblen] = i;
|
||||||
len = sizeof(xsw);
|
len = sizeof(xsw);
|
||||||
if (sysctl(mib, miblen + 1, &xsw, &len, NULL, 0) == -1)
|
if (sysctl(mib, miblen + 1, &xsw, &len, NULL, 0) == -1)
|
||||||
|
|
|
@ -24,8 +24,7 @@ _freebsd_generic_network_status(uint64_t *in,
|
||||||
int i, count;
|
int i, count;
|
||||||
len = sizeof(count);
|
len = sizeof(count);
|
||||||
|
|
||||||
if (sysctlbyname
|
if (sysctlbyname("net.link.generic.system.ifcount", &count, &len, NULL, 0) == -1)
|
||||||
("net.link.generic.system.ifcount", &count, &len, NULL, 0) < 0)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ifmd = malloc(sizeof(struct ifmibdata));
|
ifmd = malloc(sizeof(struct ifmibdata));
|
||||||
|
|
|
@ -27,8 +27,7 @@ system_sensors_thermal_get(int *sensor_count)
|
||||||
struct sensordev snsrdev;
|
struct sensordev snsrdev;
|
||||||
size_t sdlen = sizeof(struct sensordev);
|
size_t sdlen = sizeof(struct sensordev);
|
||||||
|
|
||||||
for (devn = 0;; devn++)
|
for (devn = 0;; devn++) {
|
||||||
{
|
|
||||||
mibs[2] = devn;
|
mibs[2] = devn;
|
||||||
|
|
||||||
if (sysctl(mibs, 3, &snsrdev, &sdlen, NULL, 0) == -1)
|
if (sysctl(mibs, 3, &snsrdev, &sdlen, NULL, 0) == -1)
|
||||||
|
@ -37,8 +36,7 @@ system_sensors_thermal_get(int *sensor_count)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (n = 0; n < snsrdev.maxnumt[SENSOR_TEMP]; n++)
|
for (n = 0; n < snsrdev.maxnumt[SENSOR_TEMP]; n++) {
|
||||||
{
|
|
||||||
mibs[4] = n;
|
mibs[4] = n;
|
||||||
|
|
||||||
if (sysctl(mibs, 5, &snsr, &slen, NULL, 0) == -1)
|
if (sysctl(mibs, 5, &snsr, &slen, NULL, 0) == -1)
|
||||||
|
@ -80,8 +78,7 @@ system_sensors_thermal_get(int *sensor_count)
|
||||||
n = scandir("/sys/class/thermal", &names, 0, alphasort);
|
n = scandir("/sys/class/thermal", &names, 0, alphasort);
|
||||||
if (n < 0) return NULL;
|
if (n < 0) return NULL;
|
||||||
|
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++) {
|
||||||
{
|
|
||||||
if (strncmp(names[i]->d_name, "thermal_zone", 12))
|
if (strncmp(names[i]->d_name, "thermal_zone", 12))
|
||||||
{
|
{
|
||||||
free(names[i]);
|
free(names[i]);
|
||||||
|
@ -171,18 +168,13 @@ _power_battery_count_get(power_t *power)
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
if ((sysctlbyname("hw.acpi.battery.units", &power->battery_count, &len, NULL, 0)) < 0)
|
if ((sysctlbyname("hw.acpi.battery.units", &power->battery_count, &len, NULL, 0)) < 0)
|
||||||
{
|
power->battery_count = 0;
|
||||||
power->battery_count = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((sysctlbyname("hw.acpi.acline", NULL, &len, NULL, 0)) != -1)
|
if ((sysctlbyname("hw.acpi.acline", NULL, &len, NULL, 0)) != -1)
|
||||||
{
|
sysctlnametomib("hw.acpi.acline", power->ac_mibs, &len);
|
||||||
sysctlnametomib("hw.acpi.acline", power->ac_mibs, &len);
|
|
||||||
}
|
|
||||||
|
|
||||||
power->batteries = malloc(power->battery_count * sizeof(bat_t **));
|
power->batteries = malloc(power->battery_count * sizeof(bat_t **));
|
||||||
for (int i = 0; i < power->battery_count; i++)
|
for (int i = 0; i < power->battery_count; i++) {
|
||||||
{
|
|
||||||
power->batteries[i] = calloc(1, sizeof(bat_t));
|
power->batteries[i] = calloc(1, sizeof(bat_t));
|
||||||
power->batteries[i]->present = true;
|
power->batteries[i]->present = true;
|
||||||
}
|
}
|
||||||
|
@ -195,8 +187,7 @@ _power_battery_count_get(power_t *power)
|
||||||
n = scandir("/sys/class/power_supply", &names, 0, alphasort);
|
n = scandir("/sys/class/power_supply", &names, 0, alphasort);
|
||||||
if (n < 0) return power->battery_count;
|
if (n < 0) return power->battery_count;
|
||||||
|
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++) {
|
||||||
{
|
|
||||||
snprintf(path, sizeof(path), "/sys/class/power_supply/%s/type",
|
snprintf(path, sizeof(path), "/sys/class/power_supply/%s/type",
|
||||||
names[i]->d_name);
|
names[i]->d_name);
|
||||||
|
|
||||||
|
@ -234,8 +225,7 @@ _battery_state_get(power_t *power)
|
||||||
size_t slen = sizeof(struct sensor);
|
size_t slen = sizeof(struct sensor);
|
||||||
struct sensor snsr;
|
struct sensor snsr;
|
||||||
|
|
||||||
for (int i = 0; i < power->battery_count; i++)
|
for (int i = 0; i < power->battery_count; i++) {
|
||||||
{
|
|
||||||
charge_full = charge_current = 0;
|
charge_full = charge_current = 0;
|
||||||
|
|
||||||
mib = power->batteries[i]->mibs;
|
mib = power->batteries[i]->mibs;
|
||||||
|
@ -276,8 +266,7 @@ _battery_state_get(power_t *power)
|
||||||
|
|
||||||
if ((fd = open("/dev/acpi", O_RDONLY)) == -1) return;
|
if ((fd = open("/dev/acpi", O_RDONLY)) == -1) return;
|
||||||
|
|
||||||
for (i = 0; i < power->battery_count; i++)
|
for (i = 0; i < power->battery_count; i++) {
|
||||||
{
|
|
||||||
battio.unit = i;
|
battio.unit = i;
|
||||||
if (ioctl(fd, ACPIIO_BATT_GET_BIF, &battio) != -1)
|
if (ioctl(fd, ACPIIO_BATT_GET_BIF, &battio) != -1)
|
||||||
{
|
{
|
||||||
|
@ -290,13 +279,10 @@ _battery_state_get(power_t *power)
|
||||||
power->batteries[i]->name = strdup(name);
|
power->batteries[i]->name = strdup(name);
|
||||||
battio.unit = i;
|
battio.unit = i;
|
||||||
if (ioctl(fd, ACPIIO_BATT_GET_BST, &battio) != -1)
|
if (ioctl(fd, ACPIIO_BATT_GET_BST, &battio) != -1)
|
||||||
{
|
power->batteries[i]->charge_current = battio.bst.cap;
|
||||||
power->batteries[i]->charge_current = battio.bst.cap;
|
|
||||||
}
|
|
||||||
if (battio.bst.state == ACPI_BATT_STAT_NOT_PRESENT)
|
if (battio.bst.state == ACPI_BATT_STAT_NOT_PRESENT)
|
||||||
{
|
power->batteries[i]->present = false;
|
||||||
power->batteries[i]->present = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
@ -311,8 +297,7 @@ _battery_state_get(power_t *power)
|
||||||
unsigned long charge_full = 0;
|
unsigned long charge_full = 0;
|
||||||
unsigned long charge_current = 0;
|
unsigned long charge_current = 0;
|
||||||
|
|
||||||
for (i = 0; i < power->battery_count; i++)
|
for (i = 0; i < power->battery_count; i++) {
|
||||||
{
|
|
||||||
naming = NULL;
|
naming = NULL;
|
||||||
snprintf(path, sizeof(path), "/sys/class/power_supply/%s",
|
snprintf(path, sizeof(path), "/sys/class/power_supply/%s",
|
||||||
power->batteries[i]->name);
|
power->batteries[i]->name);
|
||||||
|
@ -369,17 +354,13 @@ _battery_state_get(power_t *power)
|
||||||
char name[256];
|
char name[256];
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
len = strlen(vendor);
|
len = strlen(vendor) - 1;
|
||||||
if (vendor[len - 1] == '\n' || vendor[len - 1] == '\r')
|
if (vendor[len] == '\n' || vendor[len] == '\r')
|
||||||
{
|
vendor[len] = '\0';
|
||||||
vendor[len - 1] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
len = strlen(model);
|
len = strlen(model) - 1;
|
||||||
if (model[len - 1] == '\n' || model[len - 1] == '\r')
|
if (model[len] == '\n' || model[len] == '\r')
|
||||||
{
|
model[len] = '\0';
|
||||||
model[len - 1] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
free(power->batteries[i]->name);;
|
free(power->batteries[i]->name);;
|
||||||
snprintf(name, sizeof(name), "%s %s", vendor, model);
|
snprintf(name, sizeof(name), "%s %s", vendor, model);
|
||||||
|
@ -424,9 +405,8 @@ system_power_state_get(power_t *power)
|
||||||
#elif defined(__FreeBSD__) || defined(__DragonFly__)
|
#elif defined(__FreeBSD__) || defined(__DragonFly__)
|
||||||
len = sizeof(value);
|
len = sizeof(value);
|
||||||
if ((sysctl(power->ac_mibs, 3, &value, &len, NULL, 0)) == -1)
|
if ((sysctl(power->ac_mibs, 3, &value, &len, NULL, 0)) == -1)
|
||||||
{
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
power->have_ac = value;
|
power->have_ac = value;
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
buf = file_contents("/sys/class/power_supply/AC/online");
|
buf = file_contents("/sys/class/power_supply/AC/online");
|
||||||
|
@ -439,8 +419,7 @@ system_power_state_get(power_t *power)
|
||||||
|
|
||||||
_battery_state_get(power);
|
_battery_state_get(power);
|
||||||
|
|
||||||
for (i = 0; i < power->battery_count; i++)
|
for (i = 0; i < power->battery_count; i++) {
|
||||||
{
|
|
||||||
double percent = 100 *
|
double percent = 100 *
|
||||||
(power->batteries[i]->charge_current /
|
(power->batteries[i]->charge_current /
|
||||||
power->batteries[i]->charge_full);
|
power->batteries[i]->charge_full);
|
||||||
|
|
Loading…
Reference in New Issue