From 2868191440ce9d139347233cf91bbf3db2a8166c Mon Sep 17 00:00:00 2001 From: Drazen Kacar Date: Thu, 29 Apr 1999 20:42:17 +0000 Subject: [PATCH] add field for kvm descriptor. * glibtop_machine.h: add field for kvm descriptor. * open.c: add code for opening kernel name space. * shm_limits.c: implemented. The real implementation will have this code in the daemon, since process needs to be setgid sys to be able to read kernel symbols. --- sysdeps/solaris/ChangeLog | 8 ++++++++ sysdeps/solaris/glibtop_machine.h | 3 +++ sysdeps/solaris/open.c | 4 ++++ sysdeps/solaris/shm_limits.c | 29 +++++++++++++++++++++++++++-- 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/sysdeps/solaris/ChangeLog b/sysdeps/solaris/ChangeLog index c829779b..372ee29f 100644 --- a/sysdeps/solaris/ChangeLog +++ b/sysdeps/solaris/ChangeLog @@ -1,3 +1,11 @@ +1999-04-29 Drazen Kacar + + * glibtop_machine.h: add field for kvm descriptor. + + * open.c: add code for opening kernel name space. + + * shm_limits.c: implemented. + 1999-03-31 Drazen Kacar * loadavg.c: make it work with Solaris 2.6 and older. A part diff --git a/sysdeps/solaris/glibtop_machine.h b/sysdeps/solaris/glibtop_machine.h index db1e7d60..01aa54eb 100644 --- a/sysdeps/solaris/glibtop_machine.h +++ b/sysdeps/solaris/glibtop_machine.h @@ -29,6 +29,7 @@ #include #include +#include #include BEGIN_LIBGTOP_DECLS @@ -40,6 +41,8 @@ struct _glibtop_machine uid_t uid, euid; gid_t gid, egid; + kvm_t *kd; + kstat_ctl_t *kc; kstat_t *vminfo_kstat; diff --git a/sysdeps/solaris/open.c b/sysdeps/solaris/open.c index c1244769..ac0213b4 100644 --- a/sysdeps/solaris/open.c +++ b/sysdeps/solaris/open.c @@ -60,6 +60,10 @@ glibtop_open_s (glibtop *server, const char *program_name, if (!server->machine.kc) glibtop_error_io_r (server, "kstat_open ()"); + server->machine.kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL); + if(!server->machine.kd) + glibtop_warn_io_r(server, "kvm_open()"); + fprintf (stderr, "Sleeping 2 seconds, please wait ...\n"); sleep (2); } diff --git a/sysdeps/solaris/shm_limits.c b/sysdeps/solaris/shm_limits.c index 8a024b4a..df11d948 100644 --- a/sysdeps/solaris/shm_limits.c +++ b/sysdeps/solaris/shm_limits.c @@ -24,14 +24,25 @@ #include #include -static const unsigned long _glibtop_sysdeps_shm_limits = 0; +#include +#include + +static struct nlist nlst[] = { {"shminfo"}, {NULL} }; +static const unsigned long _glibtop_sysdeps_shm_limits = +(1L << GLIBTOP_IPC_SHMMAX) + (1L << GLIBTOP_IPC_SHMMIN) + +(1L << GLIBTOP_IPC_SHMMNI) + (1L << GLIBTOP_IPC_SHMSEG); /* Init function. */ void glibtop_init_shm_limits_s (glibtop *server) { - server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits; + kvm_t *kd = server->machine.kd; + + if(kd && !kvm_nlist(kd, nlst)) + server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits; + else + server->sysdeps.shm_limits = 0; } /* Provides information about sysv ipc limits. */ @@ -39,5 +50,19 @@ glibtop_init_shm_limits_s (glibtop *server) void glibtop_get_shm_limits_s (glibtop *server, glibtop_shm_limits *buf) { + kvm_t *kd = server->machine.kd; + struct shminfo sinfo; + memset (buf, 0, sizeof (glibtop_shm_limits)); + + if(!(server->sysdeps.shm_limits)) + return; + if(kvm_read(kd, nlst[0].n_value, (void *)&sinfo, + sizeof(struct shminfo)) != sizeof(struct shminfo)) + return; + buf->shmmax = sinfo.shmmax; + buf->shmmin = sinfo.shmmin; + buf->shmmni = sinfo.shmmni; + buf->shmseg = sinfo.shmseg; + buf->flags = _glibtop_sysdeps_shm_limits; }