Fix shm_limits.c, sem_limits.c, and msg_limits.c

by using sysctl instead of kvm_nlist

Co-authored-by: jasper <jasper@openbsd.org>
This commit is contained in:
robert
2021-04-19 15:34:58 +02:00
committed by ToMe25
parent fd162f9cb8
commit 43e4c52579
3 changed files with 50 additions and 33 deletions

View File

@@ -39,28 +39,33 @@ static unsigned long _glibtop_sysdeps_shm_limits =
* since `shminfo' is already declared external in <sys/shm.h>. */
static struct shminfo _shminfo;
/* nlist structure for kernel access */
static struct nlist nlst [] = {
{ "_shminfo" },
{ 0 }
};
/* Init function. */
void
_glibtop_init_shm_limits_p (glibtop *server)
{
if (kvm_nlist (server->machine->kd, nlst) < 0) {
glibtop_warn_io_r (server, "kvm_nlist (shm_limits)");
int mib[3];
struct shm_sysctl_info *shmsi;
size_t len = sizeof(struct shminfo);
mib[0] = CTL_KERN;
mib[1] = KERN_SYSVIPC_INFO;
mib[2] = KERN_SYSVIPC_SHM_INFO;
if ((shmsi = malloc(len)) == NULL) {
glibtop_warn_io_r (server, "malloc (shm_limits)");
return;
}
if (kvm_read (server->machine->kd, nlst [0].n_value,
&_shminfo, sizeof (_shminfo)) != sizeof (_shminfo)) {
glibtop_warn_io_r (server, "kvm_read (shminfo)");
if (sysctl(mib, 3, shmsi, &len, NULL, 0) < 0) {
glibtop_warn_io_r (server, "sysctl (shm_limits)");
return;
}
_shminfo = shmsi->shminfo;
free (shmsi);
server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits;
}