Solaris: add kstat lookup wrappers

The system interfaces kstat_lookup() and kstat_data_lookup() take a
non-constant string parameter, but passing string literals is valid.

Add wrapper functions to ignore all the const-discard warnings.
This commit is contained in:
Christian Göttsche 2021-05-19 19:00:44 +02:00 committed by cgzones
parent 4676e35f42
commit fdda291a0e
3 changed files with 36 additions and 23 deletions

View File

@ -163,7 +163,7 @@ int Platform_getMaxPid() {
kstat_ctl_t* kc = kstat_open(); kstat_ctl_t* kc = kstat_open();
if (kc != NULL) { if (kc != NULL) {
kstat_t* kshandle = kstat_lookup(kc, "unix", 0, "var"); kstat_t* kshandle = kstat_lookup_wrapper(kc, "unix", 0, "var");
if (kshandle != NULL) { if (kshandle != NULL) {
kstat_read(kc, kshandle, NULL); kstat_read(kc, kshandle, NULL);

View File

@ -11,6 +11,7 @@ in the source distribution for its full text.
#include "config.h" // IWYU pragma: keep #include "config.h" // IWYU pragma: keep
#include <kstat.h>
#include <libproc.h> #include <libproc.h>
#include <signal.h> #include <signal.h>
#include <stdbool.h> #include <stdbool.h>
@ -109,4 +110,16 @@ static inline void Platform_gettime_monotonic(uint64_t* msec) {
Generic_gettime_monotonic(msec); Generic_gettime_monotonic(msec);
} }
static inline void* kstat_data_lookup_wrapper(kstat_t* ksp, const char* name) {
IGNORE_WCASTQUAL_BEGIN
return kstat_data_lookup(ksp, (char*)name);
IGNORE_WCASTQUAL_END
}
static inline kstat_t* kstat_lookup_wrapper(kstat_ctl_t* kc, const char* ks_module, int ks_instance, const char* ks_name) {
IGNORE_WCASTQUAL_BEGIN
return kstat_lookup(kc, (char*)ks_module, ks_instance, (char*)ks_name);
IGNORE_WCASTQUAL_END
}
#endif #endif

View File

@ -39,7 +39,7 @@ char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) {
} else if ( kd == NULL ) { } else if ( kd == NULL ) {
zname = xStrdup(UZONE); zname = xStrdup(UZONE);
} else { } else {
kstat_t* ks = kstat_lookup( kd, "zones", sproc->zoneid, NULL ); kstat_t* ks = kstat_lookup_wrapper( kd, "zones", sproc->zoneid, NULL );
zname = xStrdup(ks == NULL ? UZONE : ks->ks_name); zname = xStrdup(ks == NULL ? UZONE : ks->ks_name);
} }
@ -95,12 +95,12 @@ static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) {
// Calculate per-CPU statistics first // Calculate per-CPU statistics first
for (unsigned int i = 0; i < cpus; i++) { for (unsigned int i = 0; i < cpus; i++) {
if (spl->kd != NULL) { if (spl->kd != NULL) {
if ((cpuinfo = kstat_lookup(spl->kd, "cpu", i, "sys")) != NULL) { if ((cpuinfo = kstat_lookup_wrapper(spl->kd, "cpu", i, "sys")) != NULL) {
if (kstat_read(spl->kd, cpuinfo, NULL) != -1) { if (kstat_read(spl->kd, cpuinfo, NULL) != -1) {
idletime = kstat_data_lookup(cpuinfo, "cpu_nsec_idle"); idletime = kstat_data_lookup_wrapper(cpuinfo, "cpu_nsec_idle");
intrtime = kstat_data_lookup(cpuinfo, "cpu_nsec_intr"); intrtime = kstat_data_lookup_wrapper(cpuinfo, "cpu_nsec_intr");
krnltime = kstat_data_lookup(cpuinfo, "cpu_nsec_kernel"); krnltime = kstat_data_lookup_wrapper(cpuinfo, "cpu_nsec_kernel");
usertime = kstat_data_lookup(cpuinfo, "cpu_nsec_user"); usertime = kstat_data_lookup_wrapper(cpuinfo, "cpu_nsec_user");
} }
} }
} }
@ -110,9 +110,9 @@ static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) {
if (pl->settings->showCPUFrequency) { if (pl->settings->showCPUFrequency) {
if (spl->kd != NULL) { if (spl->kd != NULL) {
if ((cpuinfo = kstat_lookup(spl->kd, "cpu_info", i, NULL)) != NULL) { if ((cpuinfo = kstat_lookup_wrapper(spl->kd, "cpu_info", i, NULL)) != NULL) {
if (kstat_read(spl->kd, cpuinfo, NULL) != -1) { if (kstat_read(spl->kd, cpuinfo, NULL) != -1) {
cpu_freq = kstat_data_lookup(cpuinfo, "current_clock_Hz"); cpu_freq = kstat_data_lookup_wrapper(cpuinfo, "current_clock_Hz");
} }
} }
} }
@ -179,15 +179,15 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) {
// Part 1 - physical memory // Part 1 - physical memory
if (spl->kd != NULL && meminfo == NULL) { if (spl->kd != NULL && meminfo == NULL) {
// Look up the kstat chain just once, it never changes // Look up the kstat chain just once, it never changes
meminfo = kstat_lookup(spl->kd, "unix", 0, "system_pages"); meminfo = kstat_lookup_wrapper(spl->kd, "unix", 0, "system_pages");
} }
if (meminfo != NULL) { if (meminfo != NULL) {
ksrphyserr = kstat_read(spl->kd, meminfo, NULL); ksrphyserr = kstat_read(spl->kd, meminfo, NULL);
} }
if (ksrphyserr != -1) { if (ksrphyserr != -1) {
totalmem_pgs = kstat_data_lookup(meminfo, "physmem"); totalmem_pgs = kstat_data_lookup_wrapper(meminfo, "physmem");
freemem_pgs = kstat_data_lookup(meminfo, "freemem"); freemem_pgs = kstat_data_lookup_wrapper(meminfo, "freemem");
pages = kstat_data_lookup(meminfo, "pagestotal"); pages = kstat_data_lookup_wrapper(meminfo, "pagestotal");
pl->totalMem = totalmem_pgs->value.ui64 * pageSizeKB; pl->totalMem = totalmem_pgs->value.ui64 * pageSizeKB;
if (pl->totalMem > freemem_pgs->value.ui64 * pageSizeKB) { if (pl->totalMem > freemem_pgs->value.ui64 * pageSizeKB) {
@ -246,39 +246,39 @@ static inline void SolarisProcessList_scanZfsArcstats(ProcessList* pl) {
kstat_named_t *cur_kstat = NULL; kstat_named_t *cur_kstat = NULL;
if (spl->kd != NULL) { if (spl->kd != NULL) {
arcstats = kstat_lookup(spl->kd, "zfs", 0, "arcstats"); arcstats = kstat_lookup_wrapper(spl->kd, "zfs", 0, "arcstats");
} }
if (arcstats != NULL) { if (arcstats != NULL) {
ksrphyserr = kstat_read(spl->kd, arcstats, NULL); ksrphyserr = kstat_read(spl->kd, arcstats, NULL);
} }
if (ksrphyserr != -1) { if (ksrphyserr != -1) {
cur_kstat = kstat_data_lookup( arcstats, "size" ); cur_kstat = kstat_data_lookup_wrapper( arcstats, "size" );
spl->zfs.size = cur_kstat->value.ui64 / 1024; spl->zfs.size = cur_kstat->value.ui64 / 1024;
spl->zfs.enabled = spl->zfs.size > 0 ? 1 : 0; spl->zfs.enabled = spl->zfs.size > 0 ? 1 : 0;
cur_kstat = kstat_data_lookup( arcstats, "c_max" ); cur_kstat = kstat_data_lookup_wrapper( arcstats, "c_max" );
spl->zfs.max = cur_kstat->value.ui64 / 1024; spl->zfs.max = cur_kstat->value.ui64 / 1024;
cur_kstat = kstat_data_lookup( arcstats, "mfu_size" ); cur_kstat = kstat_data_lookup_wrapper( arcstats, "mfu_size" );
spl->zfs.MFU = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0; spl->zfs.MFU = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;
cur_kstat = kstat_data_lookup( arcstats, "mru_size" ); cur_kstat = kstat_data_lookup_wrapper( arcstats, "mru_size" );
spl->zfs.MRU = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0; spl->zfs.MRU = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;
cur_kstat = kstat_data_lookup( arcstats, "anon_size" ); cur_kstat = kstat_data_lookup_wrapper( arcstats, "anon_size" );
spl->zfs.anon = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0; spl->zfs.anon = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;
cur_kstat = kstat_data_lookup( arcstats, "hdr_size" ); cur_kstat = kstat_data_lookup_wrapper( arcstats, "hdr_size" );
spl->zfs.header = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0; spl->zfs.header = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;
cur_kstat = kstat_data_lookup( arcstats, "other_size" ); cur_kstat = kstat_data_lookup_wrapper( arcstats, "other_size" );
spl->zfs.other = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0; spl->zfs.other = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;
if ((cur_kstat = kstat_data_lookup( arcstats, "compressed_size" )) != NULL) { if ((cur_kstat = kstat_data_lookup_wrapper( arcstats, "compressed_size" )) != NULL) {
spl->zfs.compressed = cur_kstat->value.ui64 / 1024; spl->zfs.compressed = cur_kstat->value.ui64 / 1024;
spl->zfs.isCompressed = 1; spl->zfs.isCompressed = 1;
cur_kstat = kstat_data_lookup( arcstats, "uncompressed_size" ); cur_kstat = kstat_data_lookup_wrapper( arcstats, "uncompressed_size" );
spl->zfs.uncompressed = cur_kstat->value.ui64 / 1024; spl->zfs.uncompressed = cur_kstat->value.ui64 / 1024;
} else { } else {
spl->zfs.isCompressed = 0; spl->zfs.isCompressed = 0;