libkvm: Fix kvm_getloadavg() on modern kernel vmcores
Fix kvm_getloadavg() to work correctly on vmcores for modern kernel versions. The kernels no longer include the `_fscale` symbol causing the kvm_nlist() invocation to fail. The code seemed to already assume that `_fscale` could be missing but the early kvm_nlist() result check has caused the function to fail if any symbol were missing. Modify it to only treat `_averunnable` as obligatory, and handle missing `_fscale` gracefully. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D32884
This commit is contained in:
parent
e9aeb50797
commit
8099a35446
@ -62,7 +62,6 @@ int
|
|||||||
kvm_getloadavg(kvm_t *kd, double loadavg[], int nelem)
|
kvm_getloadavg(kvm_t *kd, double loadavg[], int nelem)
|
||||||
{
|
{
|
||||||
struct loadavg loadinfo;
|
struct loadavg loadinfo;
|
||||||
struct nlist *p;
|
|
||||||
int fscale, i;
|
int fscale, i;
|
||||||
|
|
||||||
if (ISALIVE(kd))
|
if (ISALIVE(kd))
|
||||||
@ -74,10 +73,9 @@ kvm_getloadavg(kvm_t *kd, double loadavg[], int nelem)
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kvm_nlist(kd, nl) != 0) {
|
if (kvm_nlist(kd, nl) != 0 && nl[X_AVERUNNABLE].n_type == 0) {
|
||||||
for (p = nl; p->n_type != 0; ++p);
|
|
||||||
_kvm_err(kd, kd->program,
|
_kvm_err(kd, kd->program,
|
||||||
"%s: no such symbol", p->n_name);
|
"%s: no such symbol", nl[X_AVERUNNABLE].n_name);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +90,8 @@ kvm_getloadavg(kvm_t *kd, double loadavg[], int nelem)
|
|||||||
* Old kernels have fscale separately; if not found assume
|
* Old kernels have fscale separately; if not found assume
|
||||||
* running new format.
|
* running new format.
|
||||||
*/
|
*/
|
||||||
if (!KREAD(kd, nl[X_FSCALE].n_value, &fscale))
|
if (nl[X_FSCALE].n_type != 0 &&
|
||||||
|
!KREAD(kd, nl[X_FSCALE].n_value, &fscale))
|
||||||
loadinfo.fscale = fscale;
|
loadinfo.fscale = fscale;
|
||||||
|
|
||||||
nelem = MIN(nelem, (int)(sizeof(loadinfo.ldavg) / sizeof(fixpt_t)));
|
nelem = MIN(nelem, (int)(sizeof(loadinfo.ldavg) / sizeof(fixpt_t)));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user