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

@@ -47,28 +47,34 @@ static const unsigned long _glibtop_sysdeps_msg_limits =
* since `msginfo' is already declared external in <sys/msg.h>. */ * since `msginfo' is already declared external in <sys/msg.h>. */
static struct msginfo _msginfo; static struct msginfo _msginfo;
/* nlist structure for kernel access */
static struct nlist nlst [] = {
{ "_msginfo" },
{ 0 }
};
/* Init function. */ /* Init function. */
void void
_glibtop_init_msg_limits_p (glibtop *server) _glibtop_init_msg_limits_p (glibtop *server)
{ {
if (kvm_nlist (server->machine->kd, nlst) < 0) { int mib[3];
glibtop_warn_io_r (server, "kvm_nlist (msg_limits)"); struct msg_sysctl_info *msgsi;
size_t len = sizeof(struct msginfo);
mib[0] = CTL_KERN;
mib[1] = KERN_SYSVIPC_INFO;
mib[2] = KERN_SYSVIPC_MSG_INFO;
if ((msgsi = malloc(len)) == NULL) {
glibtop_warn_io_r (server, "malloc (shm_limits)");
return; return;
} }
if (kvm_read (server->machine->kd, nlst [0].n_value, if (sysctl(mib, 3, msgsi, &len, NULL, 0) < 0) {
&_msginfo, sizeof (_msginfo)) != sizeof (_msginfo)) { glibtop_warn_io_r (server, "sysctl (shm_limits)");
glibtop_warn_io_r (server, "kvm_read (msginfo)");
return; return;
} }
_msginfo = msgsi->msginfo;
free (msgsi);
server->sysdeps.msg_limits = _glibtop_sysdeps_msg_limits; server->sysdeps.msg_limits = _glibtop_sysdeps_msg_limits;
} }

View File

@@ -45,28 +45,34 @@ static unsigned long _glibtop_sysdeps_sem_limits =
* since `seminfo' is already declared external in <sys/sem.h>. */ * since `seminfo' is already declared external in <sys/sem.h>. */
static struct seminfo _seminfo; static struct seminfo _seminfo;
/* nlist structure for kernel access */
static struct nlist nlst [] = {
{ "_seminfo" },
{ 0 }
};
/* Init function. */ /* Init function. */
void void
_glibtop_init_sem_limits_p (glibtop *server) _glibtop_init_sem_limits_p (glibtop *server)
{ {
if (kvm_nlist (server->machine->kd, nlst) < 0) { int mib[3];
glibtop_warn_io_r (server, "kvm_nlist (sem_limits)"); struct sem_sysctl_info *semsi;
size_t len = sizeof(struct seminfo);
mib[0] = CTL_KERN;
mib[1] = KERN_SYSVIPC_INFO;
mib[2] = KERN_SYSVIPC_SEM_INFO;
if ((semsi = malloc(len)) == NULL) {
glibtop_warn_io_r (server, "malloc (shm_limits)");
return; return;
} }
if (kvm_read (server->machine->kd, nlst [0].n_value, if (sysctl(mib, 3, semsi, &len, NULL, 0) < 0) {
&_seminfo, sizeof (_seminfo)) != sizeof (_seminfo)) { glibtop_warn_io_r (server, "sysctl (shm_limits)");
glibtop_warn_io_r (server, "kvm_read (seminfo)");
return; return;
} }
_seminfo = semsi->seminfo;
free (semsi);
server->sysdeps.sem_limits = _glibtop_sysdeps_sem_limits; server->sysdeps.sem_limits = _glibtop_sysdeps_sem_limits;
} }

View File

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