server->machine is now a pointer, so propagate the change from . to ->.
This commit is contained in:
@@ -56,7 +56,7 @@ _glibtop_init_cpu_p (glibtop *server)
|
||||
{
|
||||
return;
|
||||
}
|
||||
server->machine.sysinfo_offset = result;
|
||||
server->machine->sysinfo_offset = result;
|
||||
|
||||
result = _glibtop_get_kmem_offset(server, "cpuinfo");
|
||||
if (result == -1)
|
||||
@@ -65,9 +65,9 @@ _glibtop_init_cpu_p (glibtop *server)
|
||||
|
||||
return;
|
||||
}
|
||||
server->machine.cpuinfo_offset = result;
|
||||
server->machine->cpuinfo_offset = result;
|
||||
|
||||
server->machine.cpuinfo = (struct cpuinfo*)calloc(_system_configuration.ncpus, sizeof(struct cpuinfo));
|
||||
server->machine->cpuinfo = (struct cpuinfo*)calloc(_system_configuration.ncpus, sizeof(struct cpuinfo));
|
||||
|
||||
server->sysdeps.cpu = _glibtop_sysdeps_cpu;
|
||||
}
|
||||
@@ -85,7 +85,7 @@ glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf)
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_cpu));
|
||||
|
||||
result = _glibtop_get_kmem_info(server, server->machine.sysinfo_offset,
|
||||
result = _glibtop_get_kmem_info(server, server->machine->sysinfo_offset,
|
||||
&sysinfo, sizeof(struct sysinfo));
|
||||
if (result <= 0)
|
||||
{
|
||||
@@ -100,8 +100,8 @@ glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf)
|
||||
|
||||
buf->total = buf->idle + buf->user + buf->sys + buf->nice ;
|
||||
|
||||
result = _glibtop_get_kmem_info(server, server->machine.cpuinfo_offset,
|
||||
server->machine.cpuinfo,
|
||||
result = _glibtop_get_kmem_info(server, server->machine->cpuinfo_offset,
|
||||
server->machine->cpuinfo,
|
||||
_system_configuration.ncpus
|
||||
* sizeof(struct cpuinfo));
|
||||
|
||||
@@ -115,13 +115,13 @@ glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf)
|
||||
for (cpu = 0; cpu < MIN(GLIBTOP_NCPU, _system_configuration.ncpus); cpu++)
|
||||
{
|
||||
buf->xcpu_idle[cpu] =
|
||||
server->machine.cpuinfo[cpu].cpu[CPU_IDLE];
|
||||
server->machine->cpuinfo[cpu].cpu[CPU_IDLE];
|
||||
buf->xcpu_user[cpu] =
|
||||
server->machine.cpuinfo[cpu].cpu[CPU_USER];
|
||||
server->machine->cpuinfo[cpu].cpu[CPU_USER];
|
||||
buf->xcpu_sys[cpu] =
|
||||
server->machine.cpuinfo[cpu].cpu[CPU_KERNEL];
|
||||
server->machine->cpuinfo[cpu].cpu[CPU_KERNEL];
|
||||
buf->xcpu_nice[cpu] =
|
||||
server->machine.cpuinfo[cpu].cpu[CPU_WAIT];
|
||||
server->machine->cpuinfo[cpu].cpu[CPU_WAIT];
|
||||
|
||||
buf->xcpu_total[cpu] = buf->xcpu_idle[cpu] +
|
||||
buf->xcpu_user[cpu] +
|
||||
|
@@ -29,11 +29,11 @@ G_BEGIN_DECLS
|
||||
#endif
|
||||
|
||||
static inline void glibtop_suid_enter (glibtop *server) {
|
||||
setegid (server->machine.egid);
|
||||
setegid (server->machine->egid);
|
||||
}
|
||||
|
||||
static inline void glibtop_suid_leave (glibtop *server) {
|
||||
if (setegid (server->machine.gid))
|
||||
if (setegid (server->machine->gid))
|
||||
_exit (1);
|
||||
}
|
||||
|
||||
|
@@ -44,7 +44,7 @@ _glibtop_init_loadavg_p (glibtop *server)
|
||||
return;
|
||||
}
|
||||
|
||||
server->machine.loadavg_offset = result;
|
||||
server->machine->loadavg_offset = result;
|
||||
|
||||
server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
|
||||
}
|
||||
@@ -61,7 +61,7 @@ glibtop_get_loadavg_p (glibtop *server, glibtop_loadavg *buf)
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_loadavg));
|
||||
|
||||
result = _glibtop_get_kmem_info(server, server->machine.loadavg_offset,
|
||||
result = _glibtop_get_kmem_info(server, server->machine->loadavg_offset,
|
||||
loadavg, sizeof(loadavg));
|
||||
if (result <= 0)
|
||||
{
|
||||
|
@@ -44,7 +44,7 @@ _glibtop_init_msg_limits_p (glibtop *server)
|
||||
return;
|
||||
}
|
||||
|
||||
server->machine.msginfo_offset = result;
|
||||
server->machine->msginfo_offset = result;
|
||||
|
||||
server->sysdeps.msg_limits = _glibtop_sysdeps_msg_limits;
|
||||
}
|
||||
@@ -61,7 +61,7 @@ glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_msg_limits));
|
||||
|
||||
result = _glibtop_get_kmem_info(server, server->machine.msginfo_offset,
|
||||
result = _glibtop_get_kmem_info(server, server->machine->msginfo_offset,
|
||||
&msginfo, sizeof(msginfo));
|
||||
|
||||
if (result <= 0)
|
||||
|
@@ -100,7 +100,7 @@ _glibtop_init_netload_p (glibtop *server)
|
||||
return;
|
||||
}
|
||||
|
||||
server->machine.ifnet_offset = addr;
|
||||
server->machine->ifnet_offset = addr;
|
||||
|
||||
server->sysdeps.netload = _glibtop_sysdeps_netload;
|
||||
}
|
||||
@@ -122,7 +122,7 @@ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_netload));
|
||||
|
||||
for ( offset = server->machine.ifnet_offset;
|
||||
for ( offset = server->machine->ifnet_offset;
|
||||
offset != 0;
|
||||
offset = (off_t)ifnet.if_next
|
||||
)
|
||||
|
@@ -56,23 +56,23 @@ glibtop_open_p (glibtop *server, const char *program_name,
|
||||
{
|
||||
/* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
|
||||
|
||||
server->machine.uid = getuid ();
|
||||
server->machine.euid = geteuid ();
|
||||
server->machine.gid = getgid ();
|
||||
server->machine.egid = getegid ();
|
||||
server->machine->uid = getuid ();
|
||||
server->machine->euid = geteuid ();
|
||||
server->machine->gid = getgid ();
|
||||
server->machine->egid = getegid ();
|
||||
|
||||
/* open kmem */
|
||||
|
||||
server->machine.kmem_fd = open("/dev/kmem", O_RDONLY);
|
||||
if (server->machine.kmem_fd == -1)
|
||||
server->machine->kmem_fd = open("/dev/kmem", O_RDONLY);
|
||||
if (server->machine->kmem_fd == -1)
|
||||
glibtop_error_io_r (server, "Cannot open /dev/kmem");
|
||||
|
||||
/* Drop priviledges. */
|
||||
|
||||
if (seteuid (server->machine.uid))
|
||||
if (seteuid (server->machine->uid))
|
||||
_exit (1);
|
||||
|
||||
if (setegid (server->machine.gid))
|
||||
if (setegid (server->machine->gid))
|
||||
_exit (1);
|
||||
|
||||
/* !!! END OF SUID ROOT PART !!! */
|
||||
|
@@ -46,7 +46,7 @@ _glibtop_init_sem_limits_p (glibtop *server)
|
||||
return;
|
||||
}
|
||||
|
||||
server->machine.seminfo_offset = result;
|
||||
server->machine->seminfo_offset = result;
|
||||
|
||||
server->sysdeps.sem_limits = _glibtop_sysdeps_sem_limits;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_sem_limits));
|
||||
|
||||
result = _glibtop_get_kmem_info(server, server->machine.seminfo_offset,
|
||||
result = _glibtop_get_kmem_info(server, server->machine->seminfo_offset,
|
||||
&seminfo, sizeof(seminfo));
|
||||
|
||||
if (result <= 0)
|
||||
|
@@ -44,7 +44,7 @@ _glibtop_init_shm_limits_p (glibtop *server)
|
||||
return;
|
||||
}
|
||||
|
||||
server->machine.shminfo_offset = result;
|
||||
server->machine->shminfo_offset = result;
|
||||
|
||||
server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits;
|
||||
}
|
||||
@@ -62,7 +62,7 @@ glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_shm_limits));
|
||||
|
||||
result = _glibtop_get_kmem_info(server, server->machine.shminfo_offset,
|
||||
result = _glibtop_get_kmem_info(server, server->machine->shminfo_offset,
|
||||
&shminfo, sizeof(struct shminfo));
|
||||
if (result <= 0)
|
||||
{
|
||||
|
@@ -68,9 +68,9 @@ _glibtop_get_kmem_info(glibtop* server, off_t offset, void* buf, size_t len)
|
||||
|
||||
glibtop_suid_enter(server);
|
||||
|
||||
lseek(server->machine.kmem_fd, offset, SEEK_SET);
|
||||
lseek(server->machine->kmem_fd, offset, SEEK_SET);
|
||||
|
||||
result = read(server->machine.kmem_fd, buf, len);
|
||||
result = read(server->machine->kmem_fd, buf, len);
|
||||
|
||||
glibtop_suid_leave(server);
|
||||
|
||||
@@ -86,23 +86,23 @@ _glibtop_get_procinfo (glibtop *server, pid_t pid)
|
||||
|
||||
/* test if procsinfo already found */
|
||||
|
||||
if ((server->machine.last_pinfo.pi_pid == pid) && (!first_time))
|
||||
if ((server->machine->last_pinfo.pi_pid == pid) && (!first_time))
|
||||
{
|
||||
return &server->machine.last_pinfo;
|
||||
return &server->machine->last_pinfo;
|
||||
}
|
||||
|
||||
/* seek procsinfo if given pid */
|
||||
|
||||
first_time = 0;
|
||||
current = 0;
|
||||
while ((result = getprocs( &server->machine.last_pinfo
|
||||
while ((result = getprocs( &server->machine->last_pinfo
|
||||
, sizeof(struct procsinfo)
|
||||
, NULL, 0, ¤t, 1)) == 1)
|
||||
{
|
||||
|
||||
if (pid == server->machine.last_pinfo.pi_pid)
|
||||
if (pid == server->machine->last_pinfo.pi_pid)
|
||||
{
|
||||
return &server->machine.last_pinfo;
|
||||
return &server->machine->last_pinfo;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
@@ -61,7 +61,7 @@ void
|
||||
_glibtop_init_cpu_p (glibtop *server)
|
||||
{
|
||||
#ifndef KERN_CP_TIME
|
||||
if (kvm_nlist (server->machine.kd, nlst) < 0) {
|
||||
if (kvm_nlist (server->machine->kd, nlst) < 0) {
|
||||
glibtop_warn_io_r (server, "kvm_nlist (cpu)");
|
||||
return;
|
||||
}
|
||||
@@ -100,7 +100,7 @@ glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf)
|
||||
return;
|
||||
}
|
||||
#else
|
||||
if (kvm_read (server->machine.kd, nlst [0].n_value,
|
||||
if (kvm_read (server->machine->kd, nlst [0].n_value,
|
||||
&cpts, sizeof (cpts)) != sizeof (cpts)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (cp_time)");
|
||||
return;
|
||||
|
@@ -35,11 +35,11 @@ G_BEGIN_DECLS
|
||||
#define UREADOK(ki) (FORCEUREAD || (KI_PROC(ki)->p_flag & P_INMEM))
|
||||
|
||||
static inline void glibtop_suid_enter (glibtop *server) {
|
||||
setregid (server->machine.gid, server->machine.egid);
|
||||
setregid (server->machine->gid, server->machine->egid);
|
||||
};
|
||||
|
||||
static inline void glibtop_suid_leave (glibtop *server) {
|
||||
if (setregid (server->machine.egid, server->machine.gid))
|
||||
if (setregid (server->machine->egid, server->machine->gid))
|
||||
_exit (1);
|
||||
};
|
||||
|
||||
|
@@ -92,7 +92,7 @@ _glibtop_init_mem_p (glibtop *server)
|
||||
{
|
||||
register int pagesize;
|
||||
|
||||
if (kvm_nlist (server->machine.kd, nlst) < 0) {
|
||||
if (kvm_nlist (server->machine->kd, nlst) < 0) {
|
||||
glibtop_warn_io_r (server, "kvm_nlist (mem)");
|
||||
return;
|
||||
}
|
||||
@@ -154,14 +154,14 @@ glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
|
||||
}
|
||||
#else
|
||||
/* Get the data from kvm_* */
|
||||
if (kvm_read (server->machine.kd, nlst[1].n_value,
|
||||
if (kvm_read (server->machine->kd, nlst[1].n_value,
|
||||
&vmm, sizeof (vmm)) != sizeof (vmm)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (cnt)");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (kvm_read (server->machine.kd, nlst[0].n_value,
|
||||
if (kvm_read (server->machine->kd, nlst[0].n_value,
|
||||
&bufspace, sizeof (bufspace)) != sizeof (bufspace)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (bufspace)");
|
||||
return;
|
||||
|
@@ -75,12 +75,12 @@ static struct nlist nlst [] = {
|
||||
void
|
||||
_glibtop_init_msg_limits_p (glibtop *server)
|
||||
{
|
||||
if (kvm_nlist (server->machine.kd, nlst) < 0) {
|
||||
if (kvm_nlist (server->machine->kd, nlst) < 0) {
|
||||
glibtop_warn_io_r (server, "kvm_nlist (msg_limits)");
|
||||
return;
|
||||
}
|
||||
|
||||
if (kvm_read (server->machine.kd, nlst [0].n_value,
|
||||
if (kvm_read (server->machine->kd, nlst [0].n_value,
|
||||
&_msginfo, sizeof (_msginfo)) != sizeof (_msginfo)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (msginfo)");
|
||||
return;
|
||||
|
@@ -72,7 +72,7 @@ _glibtop_init_netload_p (glibtop *server)
|
||||
{
|
||||
server->sysdeps.netload = _glibtop_sysdeps_netload;
|
||||
|
||||
if (kvm_nlist (server->machine.kd, nlst) < 0)
|
||||
if (kvm_nlist (server->machine->kd, nlst) < 0)
|
||||
glibtop_error_io_r (server, "kvm_nlist");
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_netload));
|
||||
|
||||
if (kvm_read (server->machine.kd, nlst [0].n_value,
|
||||
if (kvm_read (server->machine->kd, nlst [0].n_value,
|
||||
&ifnetaddr, sizeof (ifnetaddr)) != sizeof (ifnetaddr))
|
||||
glibtop_error_io_r (server, "kvm_read (ifnet)");
|
||||
|
||||
@@ -111,12 +111,12 @@ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
|
||||
{
|
||||
ifnetfound = ifnetaddr;
|
||||
|
||||
if (kvm_read (server->machine.kd, ifnetaddr, &ifnet,
|
||||
if (kvm_read (server->machine->kd, ifnetaddr, &ifnet,
|
||||
sizeof (ifnet)) != sizeof (ifnet))
|
||||
glibtop_error_io_r (server, "kvm_read (ifnetaddr)");
|
||||
|
||||
#if (defined(__FreeBSD__) && (__FreeBSD_version < 501113)) || defined(__bsdi__)
|
||||
if (kvm_read (server->machine.kd, (u_long) ifnet.if_name,
|
||||
if (kvm_read (server->machine->kd, (u_long) ifnet.if_name,
|
||||
tname, 16) != 16)
|
||||
glibtop_error_io_r (server, "kvm_read (if_name)");
|
||||
tname[15] = '\0';
|
||||
@@ -202,7 +202,7 @@ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
|
||||
buf->flags = _glibtop_sysdeps_netload;
|
||||
|
||||
while (ifaddraddr) {
|
||||
if ((kvm_read (server->machine.kd, ifaddraddr, &ifaddr,
|
||||
if ((kvm_read (server->machine->kd, ifaddraddr, &ifaddr,
|
||||
sizeof (ifaddr)) != sizeof (ifaddr)))
|
||||
glibtop_error_io_r (server, "kvm_read (ifaddraddr)");
|
||||
|
||||
|
@@ -58,27 +58,27 @@ glibtop_open_p (glibtop *server, const char *program_name,
|
||||
|
||||
/* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
|
||||
|
||||
server->machine.uid = getuid ();
|
||||
server->machine.euid = geteuid ();
|
||||
server->machine.gid = getgid ();
|
||||
server->machine.egid = getegid ();
|
||||
server->machine->uid = getuid ();
|
||||
server->machine->euid = geteuid ();
|
||||
server->machine->gid = getgid ();
|
||||
server->machine->egid = getegid ();
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
server->os_version_code = __FreeBSD_version;
|
||||
#endif
|
||||
|
||||
/* Setup machine-specific data */
|
||||
server->machine.kd = kvm_open (NULL, NULL, NULL, O_RDONLY, "kvm_open");
|
||||
server->machine->kd = kvm_open (NULL, NULL, NULL, O_RDONLY, "kvm_open");
|
||||
|
||||
if (server->machine.kd == NULL)
|
||||
if (server->machine->kd == NULL)
|
||||
glibtop_error_io_r (server, "kvm_open");
|
||||
|
||||
/* Drop priviledges. */
|
||||
|
||||
if (setreuid (server->machine.euid, server->machine.uid))
|
||||
if (setreuid (server->machine->euid, server->machine->uid))
|
||||
_exit (1);
|
||||
|
||||
if (setregid (server->machine.egid, server->machine.gid))
|
||||
if (setregid (server->machine->egid, server->machine->gid))
|
||||
_exit (1);
|
||||
|
||||
/* !!! END OF SUID ROOT PART !!! */
|
||||
|
@@ -81,7 +81,7 @@ _glibtop_init_ppp_p (glibtop *server)
|
||||
#endif
|
||||
#endif /* HAVE_I4B */
|
||||
|
||||
if (kvm_nlist (server->machine.kd, nlst) < 0)
|
||||
if (kvm_nlist (server->machine->kd, nlst) < 0)
|
||||
glibtop_error_io_r (server, "kvm_nlist");
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ glibtop_get_ppp_p (glibtop *server, glibtop_ppp *buf, unsigned short device)
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_ppp));
|
||||
|
||||
if (kvm_read (server->machine.kd, nlst [0].n_value,
|
||||
if (kvm_read (server->machine->kd, nlst [0].n_value,
|
||||
&data, sizeof (data)) != sizeof (data))
|
||||
glibtop_error_io_r (server, "kvm_read (i4bisppp_softc)");
|
||||
|
||||
|
@@ -72,14 +72,14 @@ glibtop_get_proc_args_p (glibtop *server, glibtop_proc_args *buf,
|
||||
glibtop_suid_enter (server);
|
||||
|
||||
/* Get the process data */
|
||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
|
||||
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid, &count);
|
||||
if ((pinfo == NULL) || (count < 1)) {
|
||||
glibtop_suid_leave (server);
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
args = kvm_getargv (server->machine.kd, pinfo, max_len);
|
||||
args = kvm_getargv (server->machine->kd, pinfo, max_len);
|
||||
if (args == NULL) {
|
||||
glibtop_suid_leave (server);
|
||||
glibtop_warn_io_r (server, "kvm_getargv (%d)", pid);
|
||||
|
@@ -113,7 +113,7 @@ glibtop_get_proc_kernel_p (glibtop *server,
|
||||
if (pid == 0) return;
|
||||
|
||||
/* Get the process information */
|
||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
|
||||
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid, &count);
|
||||
if ((pinfo == NULL) || (count != 1)) {
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
return;
|
||||
@@ -170,11 +170,11 @@ glibtop_get_proc_kernel_p (glibtop *server,
|
||||
/* On NetBSD, there is no kvm_uread(), and kvm_read() always reads
|
||||
* from kernel memory. */
|
||||
|
||||
if (kvm_read (server->machine.kd,
|
||||
if (kvm_read (server->machine->kd,
|
||||
#else
|
||||
|
||||
if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
|
||||
kvm_uread (server->machine.kd, &(pinfo [0]).kp_proc,
|
||||
kvm_uread (server->machine->kd, &(pinfo [0]).kp_proc,
|
||||
#endif
|
||||
(unsigned long) &u_addr->u_stats,
|
||||
(char *) &pstats, sizeof (pstats)) == sizeof (pstats))
|
||||
@@ -195,10 +195,10 @@ glibtop_get_proc_kernel_p (glibtop *server,
|
||||
}
|
||||
|
||||
#ifdef __NetBSD__
|
||||
if (kvm_read (server->machine.kd,
|
||||
if (kvm_read (server->machine->kd,
|
||||
#else
|
||||
if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
|
||||
kvm_uread (server->machine.kd, &(pinfo [0]).kp_proc,
|
||||
kvm_uread (server->machine->kd, &(pinfo [0]).kp_proc,
|
||||
#endif
|
||||
(unsigned long) &u_addr->u_pcb,
|
||||
(char *) &pcb, sizeof (pcb)) == sizeof (pcb))
|
||||
|
@@ -72,7 +72,7 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
|
||||
which = (int)(real_which & GLIBTOP_KERN_PROC_MASK);
|
||||
|
||||
/* Get the process data */
|
||||
pinfo = kvm_getprocs (server->machine.kd, which, arg, &count);
|
||||
pinfo = kvm_getprocs (server->machine->kd, which, arg, &count);
|
||||
if ((pinfo == NULL) || (count < 1)) {
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (proclist)");
|
||||
return NULL;
|
||||
|
@@ -128,7 +128,7 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
|
||||
glibtop_suid_enter (server);
|
||||
|
||||
/* Get the process data */
|
||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
|
||||
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid, &count);
|
||||
if ((pinfo == NULL) || (count < 1)) {
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
return (glibtop_map_entry*) g_array_free(maps, TRUE);
|
||||
@@ -136,7 +136,7 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
|
||||
|
||||
/* Now we get the memory maps. */
|
||||
|
||||
if (kvm_read (server->machine.kd,
|
||||
if (kvm_read (server->machine->kd,
|
||||
#if (defined(__FreeBSD__) && (__FreeBSD_version >= 500013)) || defined(__FreeBSD_kernel__)
|
||||
(unsigned long) pinfo [0].ki_vmspace,
|
||||
#else
|
||||
@@ -147,7 +147,7 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
|
||||
|
||||
first = vmspace.vm_map.header.next;
|
||||
|
||||
if (kvm_read (server->machine.kd,
|
||||
if (kvm_read (server->machine->kd,
|
||||
(unsigned long) vmspace.vm_map.header.next,
|
||||
(char *) &entry, sizeof (entry)) != sizeof (entry))
|
||||
glibtop_error_io_r (server, "kvm_read (entry)");
|
||||
@@ -173,7 +173,7 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
|
||||
guint len;
|
||||
|
||||
if (update) {
|
||||
if (kvm_read (server->machine.kd,
|
||||
if (kvm_read (server->machine->kd,
|
||||
(unsigned long) entry.next,
|
||||
&entry, sizeof (entry)) != sizeof (entry))
|
||||
glibtop_error_io_r (server, "kvm_read (entry)");
|
||||
@@ -206,7 +206,7 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
|
||||
|
||||
/* We're only interested in vnodes */
|
||||
|
||||
if (kvm_read (server->machine.kd,
|
||||
if (kvm_read (server->machine->kd,
|
||||
(unsigned long) entry.object.uvm_obj,
|
||||
&vnode, sizeof (vnode)) != sizeof (vnode)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (vnode)");
|
||||
@@ -218,7 +218,7 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
|
||||
|
||||
/* We're only interested in `vm_object's */
|
||||
|
||||
if (kvm_read (server->machine.kd,
|
||||
if (kvm_read (server->machine->kd,
|
||||
(unsigned long) entry.object.vm_object,
|
||||
&object, sizeof (object)) != sizeof (object))
|
||||
glibtop_error_io_r (server, "kvm_read (object)");
|
||||
@@ -232,7 +232,7 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
|
||||
if ((vnode.v_type != VREG) || (vnode.v_tag != VT_UFS) ||
|
||||
!vnode.v_data) continue;
|
||||
|
||||
if (kvm_read (server->machine.kd,
|
||||
if (kvm_read (server->machine->kd,
|
||||
(unsigned long) vnode.v_data,
|
||||
&inode, sizeof (inode)) != sizeof (inode))
|
||||
glibtop_error_io_r (server, "kvm_read (inode)");
|
||||
@@ -251,7 +251,7 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
|
||||
if (!object.handle)
|
||||
continue;
|
||||
|
||||
if (kvm_read (server->machine.kd,
|
||||
if (kvm_read (server->machine->kd,
|
||||
(unsigned long) object.handle,
|
||||
&vnode, sizeof (vnode)) != sizeof (vnode))
|
||||
glibtop_error_io_r (server, "kvm_read (vnode)");
|
||||
@@ -270,7 +270,7 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
|
||||
if ((vnode.v_type != VREG) || (vnode.v_tag != VT_UFS) ||
|
||||
!vnode.v_data) continue;
|
||||
|
||||
if (kvm_read (server->machine.kd,
|
||||
if (kvm_read (server->machine->kd,
|
||||
(unsigned long) vnode.v_data,
|
||||
&inode, sizeof (inode)) != sizeof (inode))
|
||||
glibtop_error_io_r (server, "kvm_read (inode)");
|
||||
|
@@ -140,7 +140,7 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
|
||||
if (pid == 0) return;
|
||||
|
||||
/* Get the process data */
|
||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
|
||||
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid, &count);
|
||||
if ((pinfo == NULL) || (count < 1)) {
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
return;
|
||||
@@ -161,7 +161,7 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
|
||||
|
||||
#define PROC_VMSPACE kp_proc.p_vmspace
|
||||
|
||||
if (kvm_read (server->machine.kd,
|
||||
if (kvm_read (server->machine->kd,
|
||||
(unsigned long) pinfo [0].PROC_VMSPACE,
|
||||
(char *) &plimit, sizeof (plimit)) != sizeof (plimit)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (plimit)");
|
||||
@@ -182,7 +182,7 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
|
||||
|
||||
/* Now we get the shared memory. */
|
||||
|
||||
if (kvm_read (server->machine.kd,
|
||||
if (kvm_read (server->machine->kd,
|
||||
(unsigned long) pinfo [0].PROC_VMSPACE,
|
||||
(char *) &vmspace, sizeof (vmspace)) != sizeof (vmspace)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (vmspace)");
|
||||
@@ -191,7 +191,7 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
|
||||
|
||||
first = vmspace.vm_map.header.next;
|
||||
|
||||
if (kvm_read (server->machine.kd,
|
||||
if (kvm_read (server->machine->kd,
|
||||
(unsigned long) vmspace.vm_map.header.next,
|
||||
(char *) &entry, sizeof (entry)) != sizeof (entry)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (entry)");
|
||||
@@ -205,7 +205,7 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
|
||||
* to OBJT_DEFAULT so if seems this really works. */
|
||||
|
||||
while (entry.next != first) {
|
||||
if (kvm_read (server->machine.kd,
|
||||
if (kvm_read (server->machine->kd,
|
||||
(unsigned long) entry.next,
|
||||
&entry, sizeof (entry)) != sizeof (entry)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (entry)");
|
||||
@@ -236,7 +236,7 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
|
||||
|
||||
/* We're only interested in vnodes */
|
||||
|
||||
if (kvm_read (server->machine.kd,
|
||||
if (kvm_read (server->machine->kd,
|
||||
(unsigned long) entry.object.uvm_obj,
|
||||
&vnode, sizeof (vnode)) != sizeof (vnode)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (vnode)");
|
||||
@@ -248,7 +248,7 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
|
||||
|
||||
/* We're only interested in `vm_object's */
|
||||
|
||||
if (kvm_read (server->machine.kd,
|
||||
if (kvm_read (server->machine->kd,
|
||||
(unsigned long) entry.object.vm_object,
|
||||
&object, sizeof (object)) != sizeof (object)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (object)");
|
||||
|
@@ -53,7 +53,7 @@ glibtop_get_proc_segment_p (glibtop *server,
|
||||
|
||||
#if 0
|
||||
/* Get the process info from the kernel */
|
||||
kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, count);
|
||||
kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid, count);
|
||||
if (*count != 1) {
|
||||
return; /* the zeroed-out buffer indicating no data */
|
||||
}
|
||||
|
@@ -62,7 +62,7 @@ glibtop_get_proc_signal_p (glibtop *server,
|
||||
if (pid == 0) return;
|
||||
|
||||
/* Get the process information */
|
||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
|
||||
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid, &count);
|
||||
if ((pinfo == NULL) || (count != 1)) {
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
return;
|
||||
|
@@ -65,7 +65,7 @@ glibtop_get_proc_state_p (glibtop *server,
|
||||
if (pid == 0) return;
|
||||
|
||||
/* Get the process information */
|
||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
|
||||
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid, &count);
|
||||
if ((pinfo == NULL) || (count != 1)) {
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
return;
|
||||
|
@@ -136,7 +136,7 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
|
||||
#endif
|
||||
|
||||
/* Get the process information */
|
||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
|
||||
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid, &count);
|
||||
if ((pinfo == NULL) || (count != 1)) {
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
return;
|
||||
@@ -156,7 +156,7 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
|
||||
#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)) || (defined(OpenBSD) && (OpenBSD >= 199912))
|
||||
glibtop_suid_enter (server);
|
||||
|
||||
if (kvm_read (server->machine.kd,
|
||||
if (kvm_read (server->machine->kd,
|
||||
(unsigned long) pinfo [0].kp_proc.p_stats,
|
||||
&pstats, sizeof (pstats)) != sizeof (pstats)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (pstats)");
|
||||
@@ -202,7 +202,7 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
|
||||
#elif (__FreeBSD_version <= 500013)
|
||||
|
||||
if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
|
||||
kvm_uread (server->machine.kd, &(pinfo [0]).kp_proc,
|
||||
kvm_uread (server->machine->kd, &(pinfo [0]).kp_proc,
|
||||
(unsigned long) &u_addr->u_stats,
|
||||
(char *) &pstats, sizeof (pstats)) == sizeof (pstats))
|
||||
{
|
||||
@@ -218,7 +218,7 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
|
||||
#else
|
||||
|
||||
if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
|
||||
kvm_uread (server->machine.kd, &(pinfo [0]).kp_proc,
|
||||
kvm_uread (server->machine->kd, &(pinfo [0]).kp_proc,
|
||||
(unsigned long) &u_addr->u_stats,
|
||||
(char *) &pstats, sizeof (pstats)) == sizeof (pstats))
|
||||
{
|
||||
|
@@ -69,7 +69,7 @@ glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
|
||||
if (pid == 0) return;
|
||||
|
||||
/* Get the process information */
|
||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
|
||||
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid, &count);
|
||||
if ((pinfo == NULL) || (count != 1)) {
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
return;
|
||||
@@ -128,7 +128,7 @@ glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
|
||||
ucred_ptr = (void *) pinfo [0].kp_eproc.e_pcred.pc_ucred;
|
||||
|
||||
if (ucred_ptr) {
|
||||
if (kvm_read (server->machine.kd, (unsigned long) ucred_ptr,
|
||||
if (kvm_read (server->machine->kd, (unsigned long) ucred_ptr,
|
||||
&ucred, sizeof (ucred)) != sizeof (ucred)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (ucred)");
|
||||
} else {
|
||||
|
@@ -77,12 +77,12 @@ static struct nlist nlst [] = {
|
||||
void
|
||||
_glibtop_init_sem_limits_p (glibtop *server)
|
||||
{
|
||||
if (kvm_nlist (server->machine.kd, nlst) < 0) {
|
||||
if (kvm_nlist (server->machine->kd, nlst) < 0) {
|
||||
glibtop_warn_io_r (server, "kvm_nlist (sem_limits)");
|
||||
return;
|
||||
}
|
||||
|
||||
if (kvm_read (server->machine.kd, nlst [0].n_value,
|
||||
if (kvm_read (server->machine->kd, nlst [0].n_value,
|
||||
&_seminfo, sizeof (_seminfo)) != sizeof (_seminfo)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (seminfo)");
|
||||
return;
|
||||
|
@@ -75,12 +75,12 @@ static struct nlist nlst [] = {
|
||||
void
|
||||
_glibtop_init_shm_limits_p (glibtop *server)
|
||||
{
|
||||
if (kvm_nlist (server->machine.kd, nlst) < 0) {
|
||||
if (kvm_nlist (server->machine->kd, nlst) < 0) {
|
||||
glibtop_warn_io_r (server, "kvm_nlist (shm_limits)");
|
||||
return;
|
||||
}
|
||||
|
||||
if (kvm_read (server->machine.kd, nlst [0].n_value,
|
||||
if (kvm_read (server->machine->kd, nlst [0].n_value,
|
||||
&_shminfo, sizeof (_shminfo)) != sizeof (_shminfo)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (shminfo)");
|
||||
return;
|
||||
|
@@ -94,14 +94,14 @@ _glibtop_init_swap_p (glibtop *server)
|
||||
{
|
||||
#if defined(__FreeBSD__) || defined(__bsdi__) || defined(__FreeBSD_kernel__)
|
||||
#if __FreeBSD__ < 4 || defined(__bsdi__)
|
||||
if (kvm_nlist (server->machine.kd, nlst) < 0) {
|
||||
if (kvm_nlist (server->machine->kd, nlst) < 0) {
|
||||
glibtop_warn_io_r (server, "kvm_nlist (swap)");
|
||||
return;
|
||||
}
|
||||
#else
|
||||
struct kvm_swap dummy;
|
||||
|
||||
if (kvm_getswapinfo (server->machine.kd, &dummy, 1, 0) != 0) {
|
||||
if (kvm_getswapinfo (server->machine->kd, &dummy, 1, 0) != 0) {
|
||||
glibtop_warn_io_r (server, "kvm_swap (swap)");
|
||||
return;
|
||||
}
|
||||
@@ -109,7 +109,7 @@ _glibtop_init_swap_p (glibtop *server)
|
||||
#endif
|
||||
|
||||
#if !(defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)) && !defined(__OpenBSD__)
|
||||
if (kvm_nlist (server->machine.kd, nlst2) < 0) {
|
||||
if (kvm_nlist (server->machine->kd, nlst2) < 0) {
|
||||
glibtop_warn_io_r (server, "kvm_nlist (cnt)");
|
||||
return;
|
||||
}
|
||||
@@ -181,7 +181,7 @@ glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
|
||||
#else
|
||||
/* This is used to get the `pagein' and `pageout' members. */
|
||||
|
||||
if (kvm_read (server->machine.kd, nlst2[0].n_value,
|
||||
if (kvm_read (server->machine->kd, nlst2[0].n_value,
|
||||
&vmm, sizeof (vmm)) != sizeof (vmm)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (cnt)");
|
||||
return;
|
||||
@@ -228,7 +228,7 @@ glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
|
||||
|
||||
/* Size of largest swap device. */
|
||||
|
||||
if (kvm_read (server->machine.kd, nlst[VM_NSWAP].n_value,
|
||||
if (kvm_read (server->machine->kd, nlst[VM_NSWAP].n_value,
|
||||
&nswap, sizeof (nswap)) != sizeof (nswap)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (nswap)");
|
||||
return;
|
||||
@@ -236,7 +236,7 @@ glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
|
||||
|
||||
/* Number of swap devices. */
|
||||
|
||||
if (kvm_read (server->machine.kd, nlst[VM_NSWDEV].n_value,
|
||||
if (kvm_read (server->machine->kd, nlst[VM_NSWDEV].n_value,
|
||||
&nswdev, sizeof (nswdev)) != sizeof (nswdev)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (nswdev)");
|
||||
return;
|
||||
@@ -244,7 +244,7 @@ glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
|
||||
|
||||
/* Maximum size of a swap block. */
|
||||
|
||||
if (kvm_read (server->machine.kd, nlst[VM_DMMAX].n_value,
|
||||
if (kvm_read (server->machine->kd, nlst[VM_DMMAX].n_value,
|
||||
&dmmax, sizeof (dmmax)) != sizeof (dmmax)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (dmmax)");
|
||||
return;
|
||||
@@ -252,7 +252,7 @@ glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
|
||||
|
||||
/* List of free swap areas. */
|
||||
|
||||
if (kvm_read (server->machine.kd, nlst[VM_SWAPLIST].n_value,
|
||||
if (kvm_read (server->machine->kd, nlst[VM_SWAPLIST].n_value,
|
||||
&swaplist, sizeof (swaplist)) != sizeof (swaplist)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (swaplist)");
|
||||
return;
|
||||
@@ -260,7 +260,7 @@ glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
|
||||
|
||||
/* Kernel offset of list of swap devices and sizes. */
|
||||
|
||||
if (kvm_read (server->machine.kd, nlst[VM_SWDEVT].n_value,
|
||||
if (kvm_read (server->machine->kd, nlst[VM_SWDEVT].n_value,
|
||||
&ptr, sizeof (ptr)) != sizeof (ptr)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (swdevt)");
|
||||
return;
|
||||
@@ -271,7 +271,7 @@ glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
|
||||
sw_size = nswdev * sizeof (*sw);
|
||||
sw = g_malloc (sw_size);
|
||||
|
||||
if (kvm_read (server->machine.kd, ptr, sw, sw_size) != (ssize_t)sw_size) {
|
||||
if (kvm_read (server->machine->kd, ptr, sw, sw_size) != (ssize_t)sw_size) {
|
||||
glibtop_warn_io_r (server, "kvm_read (*swdevt)");
|
||||
return;
|
||||
}
|
||||
@@ -288,7 +288,7 @@ glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
|
||||
while (swapptr) {
|
||||
int top, bottom, next_block;
|
||||
|
||||
if (kvm_read (server->machine.kd, (int) swapptr, &head,
|
||||
if (kvm_read (server->machine->kd, (int) swapptr, &head,
|
||||
sizeof (struct rlist)) != sizeof (struct rlist)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (swapptr)");
|
||||
return;
|
||||
@@ -365,7 +365,7 @@ glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
|
||||
|
||||
#else
|
||||
|
||||
nswdev = kvm_getswapinfo(server->machine.kd, kvmsw, 16, 0);
|
||||
nswdev = kvm_getswapinfo(server->machine->kd, kvmsw, 16, 0);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_swap;
|
||||
|
||||
@@ -380,7 +380,7 @@ glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
|
||||
|
||||
/* General info about swap devices. */
|
||||
|
||||
if (kvm_read (server->machine.kd, nlst[0].n_value,
|
||||
if (kvm_read (server->machine->kd, nlst[0].n_value,
|
||||
&swap, sizeof (swap)) != sizeof (swap)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (swap)");
|
||||
return;
|
||||
|
@@ -23,11 +23,11 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
static inline void glibtop_suid_enter (glibtop *server) {
|
||||
setreuid (server->machine.uid, server->machine.euid);
|
||||
setreuid (server->machine->uid, server->machine->euid);
|
||||
};
|
||||
|
||||
static inline void glibtop_suid_leave (glibtop *server) {
|
||||
if (setreuid (server->machine.euid, server->machine.uid))
|
||||
if (setreuid (server->machine->euid, server->machine->uid))
|
||||
_exit (1);
|
||||
};
|
||||
|
||||
|
@@ -67,17 +67,17 @@ glibtop_open_p (glibtop *server, const char *program_name,
|
||||
|
||||
server->name = program_name;
|
||||
|
||||
server->machine.uid = getuid ();
|
||||
server->machine.euid = geteuid ();
|
||||
server->machine.gid = getgid ();
|
||||
server->machine.egid = getegid ();
|
||||
server->machine->uid = getuid ();
|
||||
server->machine->euid = geteuid ();
|
||||
server->machine->gid = getgid ();
|
||||
server->machine->egid = getegid ();
|
||||
|
||||
/* Drop priviledges. */
|
||||
|
||||
if (setreuid (server->machine.euid, server->machine.uid))
|
||||
if (setreuid (server->machine->euid, server->machine->uid))
|
||||
_exit (1);
|
||||
|
||||
if (setregid (server->machine.egid, server->machine.gid))
|
||||
if (setregid (server->machine->egid, server->machine->gid))
|
||||
_exit (1);
|
||||
|
||||
/* !!! END OF SUID ROOT PART !!! */
|
||||
|
@@ -35,11 +35,11 @@ G_BEGIN_DECLS
|
||||
#define UREADOK(ki) (FORCEUREAD || (KI_PROC(ki)->p_flag & P_INMEM))
|
||||
|
||||
static inline void glibtop_suid_enter (glibtop *server) {
|
||||
setregid (server->machine.gid, server->machine.egid);
|
||||
setregid (server->machine->gid, server->machine->egid);
|
||||
};
|
||||
|
||||
static inline void glibtop_suid_leave (glibtop *server) {
|
||||
if (setregid (server->machine.egid, server->machine.gid))
|
||||
if (setregid (server->machine->egid, server->machine->gid))
|
||||
_exit (1);
|
||||
};
|
||||
|
||||
|
@@ -58,12 +58,12 @@ static struct nlist nlst [] = {
|
||||
void
|
||||
_glibtop_init_msg_limits_p (glibtop *server)
|
||||
{
|
||||
if (kvm_nlist (server->machine.kd, nlst) < 0) {
|
||||
if (kvm_nlist (server->machine->kd, nlst) < 0) {
|
||||
glibtop_warn_io_r (server, "kvm_nlist (msg_limits)");
|
||||
return;
|
||||
}
|
||||
|
||||
if (kvm_read (server->machine.kd, nlst [0].n_value,
|
||||
if (kvm_read (server->machine->kd, nlst [0].n_value,
|
||||
&_msginfo, sizeof (_msginfo)) != sizeof (_msginfo)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (msginfo)");
|
||||
return;
|
||||
|
@@ -73,7 +73,7 @@ _glibtop_init_netload_p (glibtop *server)
|
||||
{
|
||||
server->sysdeps.netload = _glibtop_sysdeps_netload;
|
||||
|
||||
if (kvm_nlist (server->machine.kd, nlst) < 0)
|
||||
if (kvm_nlist (server->machine->kd, nlst) < 0)
|
||||
glibtop_error_io_r (server, "kvm_nlist");
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_netload));
|
||||
|
||||
if (kvm_read (server->machine.kd, nlst [0].n_value,
|
||||
if (kvm_read (server->machine->kd, nlst [0].n_value,
|
||||
&ifnetaddr, sizeof (ifnetaddr)) != sizeof (ifnetaddr))
|
||||
glibtop_error_io_r (server, "kvm_read (ifnet)");
|
||||
|
||||
@@ -109,7 +109,7 @@ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
|
||||
{
|
||||
ifnetfound = ifnetaddr;
|
||||
|
||||
if (kvm_read (server->machine.kd, ifnetaddr, &ifnet,
|
||||
if (kvm_read (server->machine->kd, ifnetaddr, &ifnet,
|
||||
sizeof (ifnet)) != sizeof (ifnet))
|
||||
glibtop_error_io_r (server, "kvm_read (ifnetaddr)");
|
||||
|
||||
@@ -176,7 +176,7 @@ glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
|
||||
buf->flags = _glibtop_sysdeps_netload;
|
||||
|
||||
while (ifaddraddr) {
|
||||
if ((kvm_read (server->machine.kd, ifaddraddr, &ifaddr,
|
||||
if ((kvm_read (server->machine->kd, ifaddraddr, &ifaddr,
|
||||
sizeof (ifaddr)) != sizeof (ifaddr)))
|
||||
glibtop_error_io_r (server, "kvm_read (ifaddraddr)");
|
||||
|
||||
|
@@ -77,7 +77,7 @@ _glibtop_init_ppp_p (glibtop *server)
|
||||
#endif
|
||||
#endif /* HAVE_I4B */
|
||||
|
||||
if (kvm_nlist (server->machine.kd, nlst) < 0)
|
||||
if (kvm_nlist (server->machine->kd, nlst) < 0)
|
||||
glibtop_error_io_r (server, "kvm_nlist");
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ glibtop_get_ppp_p (glibtop *server, glibtop_ppp *buf, unsigned short device)
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_ppp));
|
||||
|
||||
if (kvm_read (server->machine.kd, nlst [0].n_value,
|
||||
if (kvm_read (server->machine->kd, nlst [0].n_value,
|
||||
&data, sizeof (data)) != sizeof (data))
|
||||
glibtop_error_io_r (server, "kvm_read (i4bisppp_softc)");
|
||||
|
||||
|
@@ -65,7 +65,7 @@ glibtop_get_proc_args_p (glibtop *server, glibtop_proc_args *buf,
|
||||
glibtop_suid_enter (server);
|
||||
|
||||
/* Get the process data */
|
||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid,
|
||||
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid,
|
||||
sizeof (*pinfo), &count);
|
||||
if (pinfo == NULL) {
|
||||
glibtop_suid_leave (server);
|
||||
@@ -73,7 +73,7 @@ glibtop_get_proc_args_p (glibtop *server, glibtop_proc_args *buf,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
args = kvm_getargv (server->machine.kd, pinfo, max_len);
|
||||
args = kvm_getargv (server->machine->kd, pinfo, max_len);
|
||||
if (args == NULL) {
|
||||
glibtop_suid_leave (server);
|
||||
glibtop_warn_io_r (server, "kvm_getargv (%d)", pid);
|
||||
|
@@ -72,7 +72,7 @@ glibtop_get_proc_kernel_p (glibtop *server,
|
||||
glibtop_suid_enter (server);
|
||||
|
||||
/* Get the process information */
|
||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid,
|
||||
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid,
|
||||
sizeof(*pinfo), &count);
|
||||
if (pinfo == NULL) {
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
|
@@ -72,7 +72,7 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
|
||||
which = (int)(real_which & GLIBTOP_KERN_PROC_MASK);
|
||||
|
||||
/* Get the process data */
|
||||
pinfo = kvm_getprocs (server->machine.kd, which, arg,
|
||||
pinfo = kvm_getprocs (server->machine->kd, which, arg,
|
||||
sizeof (*pinfo), &count);
|
||||
if ((pinfo == NULL) || (count < 1)) {
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (proclist)");
|
||||
|
@@ -99,7 +99,7 @@ load_vmmap_entries(glibtop *server, unsigned long kptr,
|
||||
return -1;
|
||||
|
||||
/* Download entry at kptr. */
|
||||
if (kvm_read (server->machine.kd, kptr,
|
||||
if (kvm_read (server->machine->kd, kptr,
|
||||
(char *)entry, sizeof(*entry)) != sizeof(*entry)) {
|
||||
free(entry);
|
||||
return -1;
|
||||
@@ -185,7 +185,7 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
|
||||
glibtop_suid_enter (server);
|
||||
|
||||
/* Get the process data */
|
||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &count);
|
||||
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &count);
|
||||
if (pinfo == NULL) {
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
return (glibtop_map_entry*) g_array_free(maps, TRUE);
|
||||
@@ -193,7 +193,7 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
|
||||
|
||||
/* Now we get the memory maps. */
|
||||
|
||||
if (kvm_read (server->machine.kd,
|
||||
if (kvm_read (server->machine->kd,
|
||||
(unsigned long) pinfo [0].p_vmspace,
|
||||
(char *) &vmspace, sizeof (vmspace)) != sizeof (vmspace)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (vmspace)");
|
||||
@@ -238,7 +238,7 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
|
||||
|
||||
/* We're only interested in vnodes */
|
||||
|
||||
if (kvm_read (server->machine.kd,
|
||||
if (kvm_read (server->machine->kd,
|
||||
(unsigned long) entry->object.uvm_obj,
|
||||
&vnode, sizeof (vnode)) != sizeof (vnode)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (vnode)");
|
||||
@@ -254,7 +254,7 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
|
||||
if ((vnode.v_type != VREG) || (vnode.v_tag != VT_UFS) ||
|
||||
!vnode.v_data) continue;
|
||||
|
||||
if (kvm_read (server->machine.kd,
|
||||
if (kvm_read (server->machine->kd,
|
||||
(unsigned long) vnode.v_data,
|
||||
&inode, sizeof (inode)) != sizeof (inode)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (inode)");
|
||||
|
@@ -113,7 +113,7 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
|
||||
if (pid == 0) return;
|
||||
|
||||
/* Get the process data */
|
||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid,
|
||||
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid,
|
||||
sizeof (*pinfo), &count);
|
||||
if ((pinfo == NULL) || (count < 1)) {
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
|
@@ -63,7 +63,7 @@ glibtop_get_proc_segment_p (glibtop *server,
|
||||
if (pid == 0) return;
|
||||
|
||||
/* Get the process info from the kernel */
|
||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid,
|
||||
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid,
|
||||
sizeof (*pinfo), &count);
|
||||
if (pinfo == NULL) {
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
|
@@ -58,7 +58,7 @@ glibtop_get_proc_signal_p (glibtop *server,
|
||||
if (pid == 0) return;
|
||||
|
||||
/* Get the process information */
|
||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid,
|
||||
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid,
|
||||
sizeof (*pinfo), &count);
|
||||
if (pinfo == NULL) {
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
|
@@ -60,7 +60,7 @@ glibtop_get_proc_state_p (glibtop *server,
|
||||
if (pid == 0) return;
|
||||
|
||||
/* Get the process information */
|
||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid,
|
||||
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid,
|
||||
sizeof (*pinfo), &count);
|
||||
if (pinfo == NULL) {
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
|
@@ -74,7 +74,7 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
|
||||
|
||||
|
||||
/* Get the process information */
|
||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid,
|
||||
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid,
|
||||
sizeof (*pinfo), &count);
|
||||
if (pinfo == NULL) {
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
|
@@ -63,7 +63,7 @@ glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
|
||||
if (pid == 0) return;
|
||||
|
||||
/* Get the process information */
|
||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid,
|
||||
pinfo = kvm_getprocs (server->machine->kd, KERN_PROC_PID, pid,
|
||||
sizeof (*pinfo), &count);
|
||||
if (pinfo == NULL) {
|
||||
glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
|
@@ -56,12 +56,12 @@ static struct nlist nlst [] = {
|
||||
void
|
||||
_glibtop_init_sem_limits_p (glibtop *server)
|
||||
{
|
||||
if (kvm_nlist (server->machine.kd, nlst) < 0) {
|
||||
if (kvm_nlist (server->machine->kd, nlst) < 0) {
|
||||
glibtop_warn_io_r (server, "kvm_nlist (sem_limits)");
|
||||
return;
|
||||
}
|
||||
|
||||
if (kvm_read (server->machine.kd, nlst [0].n_value,
|
||||
if (kvm_read (server->machine->kd, nlst [0].n_value,
|
||||
&_seminfo, sizeof (_seminfo)) != sizeof (_seminfo)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (seminfo)");
|
||||
return;
|
||||
|
@@ -50,12 +50,12 @@ static struct nlist nlst [] = {
|
||||
void
|
||||
_glibtop_init_shm_limits_p (glibtop *server)
|
||||
{
|
||||
if (kvm_nlist (server->machine.kd, nlst) < 0) {
|
||||
if (kvm_nlist (server->machine->kd, nlst) < 0) {
|
||||
glibtop_warn_io_r (server, "kvm_nlist (shm_limits)");
|
||||
return;
|
||||
}
|
||||
|
||||
if (kvm_read (server->machine.kd, nlst [0].n_value,
|
||||
if (kvm_read (server->machine->kd, nlst [0].n_value,
|
||||
&_shminfo, sizeof (_shminfo)) != sizeof (_shminfo)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (shminfo)");
|
||||
return;
|
||||
|
@@ -61,22 +61,22 @@ glibtop_open_p (glibtop *server, const char *program_name,
|
||||
#endif
|
||||
|
||||
/* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
|
||||
server->machine.uid = getuid ();
|
||||
server->machine.euid = geteuid ();
|
||||
server->machine.gid = getgid ();
|
||||
server->machine.egid = getegid ();
|
||||
server->machine->uid = getuid ();
|
||||
server->machine->euid = geteuid ();
|
||||
server->machine->gid = getgid ();
|
||||
server->machine->egid = getegid ();
|
||||
/* Setup machine-specific data */
|
||||
server->machine.kd = kvm_openfiles (NULL, NULL, NULL, O_RDONLY, errbuf);
|
||||
server->machine->kd = kvm_openfiles (NULL, NULL, NULL, O_RDONLY, errbuf);
|
||||
|
||||
if (server->machine.kd == NULL)
|
||||
if (server->machine->kd == NULL)
|
||||
glibtop_error_io_r (server, "kvm_open");
|
||||
|
||||
/* Drop priviledges. */
|
||||
|
||||
if (setreuid (server->machine.euid, server->machine.uid))
|
||||
if (setreuid (server->machine->euid, server->machine->uid))
|
||||
_exit (1);
|
||||
|
||||
if (setregid (server->machine.egid, server->machine.gid))
|
||||
if (setregid (server->machine->egid, server->machine->gid))
|
||||
_exit (1);
|
||||
|
||||
/* !!! END OF SUID ROOT PART !!! */
|
||||
|
@@ -27,11 +27,11 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
static inline void glibtop_suid_enter (glibtop *server) {
|
||||
setreuid (server->machine.uid, server->machine.euid);
|
||||
setreuid (server->machine->uid, server->machine->euid);
|
||||
};
|
||||
|
||||
static inline void glibtop_suid_leave (glibtop *server) {
|
||||
if (setreuid (server->machine.euid, server->machine.uid))
|
||||
if (setreuid (server->machine->euid, server->machine->uid))
|
||||
_exit (1);
|
||||
};
|
||||
|
||||
|
@@ -61,12 +61,12 @@ glibtop_open_p (glibtop *server, const char *program_name,
|
||||
|
||||
server->name = program_name;
|
||||
|
||||
server->machine.uid = getuid ();
|
||||
server->machine.euid = geteuid ();
|
||||
server->machine.gid = getgid ();
|
||||
server->machine.egid = getegid ();
|
||||
server->machine->uid = getuid ();
|
||||
server->machine->euid = geteuid ();
|
||||
server->machine->gid = getgid ();
|
||||
server->machine->egid = getegid ();
|
||||
|
||||
server->machine.proctable_entries = table
|
||||
server->machine->proctable_entries = table
|
||||
(TBL_PROCINFO, 0, NULL, INT_MAX, 0);
|
||||
|
||||
/* Drop priviledges; we only become root when necessary.
|
||||
@@ -76,10 +76,10 @@ glibtop_open_p (glibtop *server, const char *program_name,
|
||||
|
||||
*/
|
||||
|
||||
if (setreuid (server->machine.euid, server->machine.uid))
|
||||
if (setreuid (server->machine->euid, server->machine->uid))
|
||||
_exit (1);
|
||||
|
||||
if (setregid (server->machine.egid, server->machine.gid))
|
||||
if (setregid (server->machine->egid, server->machine->gid))
|
||||
_exit (1);
|
||||
|
||||
/* !!! END OF SUID ROOT PART !!! */
|
||||
|
@@ -77,7 +77,7 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proclist));
|
||||
|
||||
for (entry = 0; entry < server->machine.proctable_entries;
|
||||
for (entry = 0; entry < server->machine->proctable_entries;
|
||||
entry += ELEMENTS_PER_ENTRY)
|
||||
{
|
||||
/* !!! THE FOLLOWING CODE RUNS SUID ROOT -
|
||||
|
@@ -53,14 +53,14 @@ _glibtop_init_cpu_s (glibtop *server)
|
||||
void
|
||||
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
||||
{
|
||||
kstat_ctl_t * const kc = server->machine.kc;
|
||||
kstat_ctl_t * const kc = server->machine->kc;
|
||||
cpu_stat_t cpu_stat;
|
||||
processorid_t cpu;
|
||||
int ncpu, found;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_cpu));
|
||||
|
||||
buf->frequency = server->machine.ticks;
|
||||
buf->frequency = server->machine->ticks;
|
||||
buf->flags = _glibtop_sysdeps_cpu_freq;
|
||||
|
||||
if(!kc)
|
||||
@@ -77,7 +77,7 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
||||
|
||||
for (cpu = 0, found = 0; cpu < GLIBTOP_NCPU && found != ncpu; cpu++)
|
||||
{
|
||||
kstat_t * const ksp = server->machine.cpu_stat_kstat [cpu];
|
||||
kstat_t * const ksp = server->machine->cpu_stat_kstat [cpu];
|
||||
if (!ksp) continue;;
|
||||
|
||||
++found;
|
||||
|
@@ -25,11 +25,11 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
static inline void glibtop_suid_enter (glibtop *server) {
|
||||
setreuid (server->machine.uid, server->machine.euid);
|
||||
setreuid (server->machine->uid, server->machine->euid);
|
||||
};
|
||||
|
||||
static inline void glibtop_suid_leave (glibtop *server) {
|
||||
if (setreuid (server->machine.euid, server->machine.uid))
|
||||
if (setreuid (server->machine->euid, server->machine->uid))
|
||||
_exit (1);
|
||||
};
|
||||
|
||||
|
@@ -62,7 +62,7 @@ glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
|
||||
return;
|
||||
|
||||
#else
|
||||
if(!(kc = server->machine.kc))
|
||||
if(!(kc = server->machine->kc))
|
||||
return;
|
||||
|
||||
switch(kstat_chain_update(kc))
|
||||
@@ -72,7 +72,7 @@ glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
|
||||
default: glibtop_get_kstats(server);
|
||||
}
|
||||
|
||||
if(!(ksp = server->machine.system))
|
||||
if(!(ksp = server->machine->system))
|
||||
return;
|
||||
|
||||
if(kstat_read(kc, ksp, NULL) < 0)
|
||||
|
@@ -47,12 +47,12 @@ _glibtop_init_mem_s (glibtop *server)
|
||||
void
|
||||
glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
|
||||
{
|
||||
kstat_ctl_t * const kc = server->machine.kc;
|
||||
kstat_ctl_t * const kc = server->machine->kc;
|
||||
kstat_t *ksp;
|
||||
kstat_named_t *kn;
|
||||
|
||||
#undef PAGESIZE
|
||||
#define PAGESIZE (server->machine.pagesize)
|
||||
#define PAGESIZE (server->machine->pagesize)
|
||||
#define PAGESHIFT (PAGESIZE + 10)
|
||||
|
||||
#ifdef _LP64
|
||||
@@ -78,7 +78,7 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
|
||||
default: glibtop_get_kstats(server);
|
||||
}
|
||||
|
||||
if((ksp = server->machine.syspages) && kstat_read(kc, ksp, NULL) >= 0)
|
||||
if((ksp = server->machine->syspages) && kstat_read(kc, ksp, NULL) >= 0)
|
||||
{
|
||||
kn = kstat_data_lookup(ksp, "pagesfree");
|
||||
if(kn)
|
||||
@@ -99,7 +99,7 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
|
||||
|
||||
/* Bunyip module provides data in multiples of system page size */
|
||||
|
||||
if((ksp = server->machine.bunyip) && kstat_read(kc, ksp, NULL) >= 0)
|
||||
if((ksp = server->machine->bunyip) && kstat_read(kc, ksp, NULL) >= 0)
|
||||
{
|
||||
kn = kstat_data_lookup(ksp, "pages_exec");
|
||||
if(kn)
|
||||
|
@@ -48,7 +48,7 @@ _glibtop_init_msg_limits_p (glibtop *server)
|
||||
{
|
||||
#if GLIBTOP_SOLARIS_RELEASE < 51000
|
||||
|
||||
kvm_t *kd = server->machine.kd;
|
||||
kvm_t *kd = server->machine->kd;
|
||||
|
||||
if(kd && !kvm_nlist(kd, nlst))
|
||||
server->sysdeps.msg_limits = _glibtop_sysdeps_msg_limits;
|
||||
@@ -64,7 +64,7 @@ glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
|
||||
{
|
||||
#if GLIBTOP_SOLARIS_RELEASE < 51000
|
||||
|
||||
kvm_t *kd = server->machine.kd;
|
||||
kvm_t *kd = server->machine->kd;
|
||||
glibtop_msg_limits minfo;
|
||||
|
||||
|
||||
|
@@ -97,7 +97,7 @@ solaris_stats(glibtop *server,
|
||||
char *name = interface;
|
||||
char *module;
|
||||
char *ptr;
|
||||
kstat_ctl_t * const kctl = server->machine.kc;
|
||||
kstat_ctl_t * const kctl = server->machine->kc;
|
||||
kstat_t *ksp;
|
||||
kstat_named_t *kdata;
|
||||
int have_bytes = 1;
|
||||
|
@@ -40,7 +40,7 @@
|
||||
void
|
||||
glibtop_get_kstats(glibtop *server)
|
||||
{
|
||||
kstat_ctl_t *kc = server->machine.kc;
|
||||
kstat_ctl_t *kc = server->machine->kc;
|
||||
kstat_t *ksp;
|
||||
int nproc_same, new_ncpu;
|
||||
|
||||
@@ -50,23 +50,23 @@ glibtop_get_kstats(glibtop *server)
|
||||
if(!kc)
|
||||
{
|
||||
server->ncpu = new_ncpu;
|
||||
server->machine.vminfo_kstat = NULL;
|
||||
server->machine.system = NULL;
|
||||
server->machine.syspages = NULL;
|
||||
server->machine.bunyip = NULL;
|
||||
server->machine->vminfo_kstat = NULL;
|
||||
server->machine->system = NULL;
|
||||
server->machine->syspages = NULL;
|
||||
server->machine->bunyip = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
|
||||
ksp = kstat_lookup(kc, "unix", -1, "vminfo");
|
||||
server->machine.vminfo_kstat = ksp;
|
||||
server->machine->vminfo_kstat = ksp;
|
||||
if(ksp)
|
||||
{
|
||||
kstat_read(kc, ksp, &server->machine.vminfo);
|
||||
kstat_read(kc, ksp, &server->machine->vminfo);
|
||||
/* Don't change snaptime if we only need to reinitialize kstats */
|
||||
if(!(server->machine.vminfo_snaptime))
|
||||
server->machine.vminfo_snaptime = ksp->ks_snaptime;
|
||||
if(!(server->machine->vminfo_snaptime))
|
||||
server->machine->vminfo_snaptime = ksp->ks_snaptime;
|
||||
}
|
||||
|
||||
/* We don't know why was kstat chain invalidated. It could have
|
||||
@@ -81,11 +81,11 @@ glibtop_get_kstats(glibtop *server)
|
||||
char cpu[20];
|
||||
|
||||
for(i = 0, checked = 0; i < GLIBTOP_NCPU || checked == new_ncpu; ++i)
|
||||
if(!server->machine.cpu_stat_kstat[i])
|
||||
if(!server->machine->cpu_stat_kstat[i])
|
||||
|
||||
{
|
||||
sprintf(cpu, "cpu_stat%d", i);
|
||||
if(!(server->machine.cpu_stat_kstat[i] =
|
||||
if(!(server->machine->cpu_stat_kstat[i] =
|
||||
kstat_lookup(kc, "cpu_stat", -1, cpu)))
|
||||
{
|
||||
nproc_same = 0;
|
||||
@@ -107,19 +107,19 @@ glibtop_get_kstats(glibtop *server)
|
||||
{
|
||||
if(p_online(p, P_STATUS) < 0)
|
||||
{
|
||||
server->machine.cpu_stat_kstat[p] = NULL;
|
||||
server->machine->cpu_stat_kstat[p] = NULL;
|
||||
continue;
|
||||
}
|
||||
sprintf(cpu, "cpu_stat%d", (int)p);
|
||||
server->machine.cpu_stat_kstat[p] =
|
||||
server->machine->cpu_stat_kstat[p] =
|
||||
kstat_lookup(kc, "cpu_stat", -1, cpu);
|
||||
++found;
|
||||
}
|
||||
}
|
||||
|
||||
server->machine.system = kstat_lookup(kc, "unix", -1, "system_misc");
|
||||
server->machine.syspages = kstat_lookup(kc, "unix", -1, "system_pages");
|
||||
server->machine.bunyip = kstat_lookup(kc, "bunyip", -1, "mempages");
|
||||
server->machine->system = kstat_lookup(kc, "unix", -1, "system_misc");
|
||||
server->machine->syspages = kstat_lookup(kc, "unix", -1, "system_pages");
|
||||
server->machine->bunyip = kstat_lookup(kc, "bunyip", -1, "mempages");
|
||||
|
||||
} while(kstat_chain_update(kc) > 0 &&
|
||||
(new_ncpu = sysconf(_SC_NPROCESSORS_CONF)));
|
||||
@@ -142,18 +142,18 @@ glibtop_open_s (glibtop *server, const char *program_name,
|
||||
|
||||
page = sysconf(_SC_PAGESIZE) >> 10;
|
||||
for(i = 0; page; ++i, page >>= 1);
|
||||
server->machine.pagesize = i - 1;
|
||||
server->machine.ticks = sysconf(_SC_CLK_TCK);
|
||||
if(server->machine.kc)
|
||||
kstat_close(server->machine.kc);
|
||||
server->machine.kc = kc = kstat_open ();
|
||||
server->machine->pagesize = i - 1;
|
||||
server->machine->ticks = sysconf(_SC_CLK_TCK);
|
||||
if(server->machine->kc)
|
||||
kstat_close(server->machine->kc);
|
||||
server->machine->kc = kc = kstat_open ();
|
||||
|
||||
#if 0
|
||||
for (ksp = server->machine.kc->kc_chain; ksp != NULL; ksp = ksp->ks_next) {
|
||||
for (ksp = server->machine->kc->kc_chain; ksp != NULL; ksp = ksp->ks_next) {
|
||||
if (!strcmp (ksp->ks_class, "vm") && !strcmp (ksp->ks_name, "vminfo")) {
|
||||
server->machine.vminfo_kstat = ksp;
|
||||
kstat_read (server->machine.kc, ksp, &server->machine.vminfo);
|
||||
server->machine.vminfo_snaptime = ksp->ks_snaptime;
|
||||
server->machine->vminfo_kstat = ksp;
|
||||
kstat_read (server->machine->kc, ksp, &server->machine->vminfo);
|
||||
server->machine->vminfo_snaptime = ksp->ks_snaptime;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -166,7 +166,7 @@ glibtop_open_s (glibtop *server, const char *program_name,
|
||||
if (cpu >= server->ncpu)
|
||||
server->ncpu = cpu+1;
|
||||
|
||||
server->machine.cpu_stat_kstat [cpu] = ksp;
|
||||
server->machine->cpu_stat_kstat [cpu] = ksp;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -177,33 +177,33 @@ glibtop_open_s (glibtop *server, const char *program_name,
|
||||
glibtop_warn_io_r (server, "kstat_open ()");
|
||||
|
||||
server->ncpu = -1; /* Force processor detection */
|
||||
server->machine.vminfo_snaptime = 0; /* Force snaptime read */
|
||||
server->machine->vminfo_snaptime = 0; /* Force snaptime read */
|
||||
glibtop_get_kstats(server);
|
||||
|
||||
server->machine.boot = 0;
|
||||
if((ksp = server->machine.system) && kstat_read(kc, ksp, NULL) >= 0)
|
||||
server->machine->boot = 0;
|
||||
if((ksp = server->machine->system) && kstat_read(kc, ksp, NULL) >= 0)
|
||||
{
|
||||
kn = (kstat_named_t *)kstat_data_lookup(ksp, "boot_time");
|
||||
if(kn)
|
||||
switch(kn->data_type)
|
||||
{
|
||||
#ifdef KSTAT_DATA_INT32
|
||||
case KSTAT_DATA_INT32: server->machine.boot = kn->value.i32;
|
||||
case KSTAT_DATA_INT32: server->machine->boot = kn->value.i32;
|
||||
break;
|
||||
case KSTAT_DATA_UINT32: server->machine.boot = kn->value.ui32;
|
||||
case KSTAT_DATA_UINT32: server->machine->boot = kn->value.ui32;
|
||||
break;
|
||||
case KSTAT_DATA_INT64: server->machine.boot = kn->value.i64;
|
||||
case KSTAT_DATA_INT64: server->machine->boot = kn->value.i64;
|
||||
break;
|
||||
case KSTAT_DATA_UINT64: server->machine.boot = kn->value.ui64;
|
||||
case KSTAT_DATA_UINT64: server->machine->boot = kn->value.ui64;
|
||||
break;
|
||||
#else
|
||||
case KSTAT_DATA_LONG: server->machine.boot = kn->value.l;
|
||||
case KSTAT_DATA_LONG: server->machine->boot = kn->value.l;
|
||||
break;
|
||||
case KSTAT_DATA_ULONG: server->machine.boot = kn->value.ul;
|
||||
case KSTAT_DATA_ULONG: server->machine->boot = kn->value.ul;
|
||||
break;
|
||||
case KSTAT_DATA_LONGLONG: server->machine.boot = kn->value.ll;
|
||||
case KSTAT_DATA_LONGLONG: server->machine->boot = kn->value.ll;
|
||||
break;
|
||||
case KSTAT_DATA_ULONGLONG: server->machine.boot = kn->value.ull;
|
||||
case KSTAT_DATA_ULONGLONG: server->machine->boot = kn->value.ull;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
@@ -214,9 +214,9 @@ glibtop_open_s (glibtop *server, const char *program_name,
|
||||
#if GLIBTOP_SOLARIS_RELEASE >= 50600
|
||||
|
||||
dl = dlopen("/usr/lib/libproc.so", RTLD_LAZY);
|
||||
if(server->machine.libproc)
|
||||
dlclose(server->machine.libproc);
|
||||
server->machine.libproc = dl;
|
||||
if(server->machine->libproc)
|
||||
dlclose(server->machine->libproc);
|
||||
server->machine->libproc = dl;
|
||||
if(dl)
|
||||
{
|
||||
void *func;
|
||||
@@ -224,19 +224,19 @@ glibtop_open_s (glibtop *server, const char *program_name,
|
||||
func = dlsym(dl, "Pobjname"); /* Solaris 8 */
|
||||
if(!func)
|
||||
func = dlsym(dl, "proc_objname"); /* Solaris 7 */
|
||||
server->machine.objname = (void (*)
|
||||
server->machine->objname = (void (*)
|
||||
(void *, uintptr_t, const char *, size_t))func;
|
||||
server->machine.pgrab = (struct ps_prochandle *(*)(pid_t, int, int *))
|
||||
server->machine->pgrab = (struct ps_prochandle *(*)(pid_t, int, int *))
|
||||
dlsym(dl, "Pgrab");
|
||||
server->machine.pfree = (void (*)(void *))dlsym(dl, "Pfree");
|
||||
server->machine->pfree = (void (*)(void *))dlsym(dl, "Pfree");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
server->machine.objname = NULL;
|
||||
server->machine.pgrab = NULL;
|
||||
server->machine.pfree = NULL;
|
||||
server->machine->objname = NULL;
|
||||
server->machine->pgrab = NULL;
|
||||
server->machine->pfree = NULL;
|
||||
}
|
||||
#endif
|
||||
server->machine.me = getpid();
|
||||
server->machine->me = getpid();
|
||||
}
|
||||
|
@@ -62,15 +62,15 @@ glibtop_open_p (glibtop *server, const char *program_name,
|
||||
|
||||
server->name = program_name;
|
||||
|
||||
server->machine.uid = getuid ();
|
||||
server->machine.euid = geteuid ();
|
||||
server->machine.gid = getgid ();
|
||||
server->machine.egid = getegid ();
|
||||
server->machine->uid = getuid ();
|
||||
server->machine->euid = geteuid ();
|
||||
server->machine->gid = getgid ();
|
||||
server->machine->egid = getegid ();
|
||||
|
||||
#if GLIBTOP_SOLARIS_RELEASE < 51000
|
||||
|
||||
server->machine.kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL);
|
||||
if(!server->machine.kd)
|
||||
server->machine->kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL);
|
||||
if(!server->machine->kd)
|
||||
glibtop_warn_io_r(server, "kvm_open()");
|
||||
|
||||
#endif
|
||||
@@ -82,10 +82,10 @@ glibtop_open_p (glibtop *server, const char *program_name,
|
||||
|
||||
*/
|
||||
|
||||
if (setreuid (server->machine.euid, server->machine.uid))
|
||||
if (setreuid (server->machine->euid, server->machine->uid))
|
||||
_exit (1);
|
||||
|
||||
if (setregid (server->machine.egid, server->machine.gid))
|
||||
if (setregid (server->machine->egid, server->machine->gid))
|
||||
_exit (1);
|
||||
|
||||
/* !!! END OF SUID ROOT PART !!! */
|
||||
|
@@ -125,9 +125,9 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
|
||||
|
||||
#if GLIBTOP_SOLARIS_RELEASE >= 50600
|
||||
|
||||
if(server->machine.objname && server->machine.pgrab &&
|
||||
server->machine.pfree)
|
||||
Pr = (server->machine.pgrab)(pid, 1, &pr_err);
|
||||
if(server->machine->objname && server->machine->pgrab &&
|
||||
server->machine->pfree)
|
||||
Pr = (server->machine->pgrab)(pid, 1, &pr_err);
|
||||
#endif
|
||||
for(heap = 0,i = 0; i < nmaps; ++i)
|
||||
{
|
||||
@@ -179,7 +179,7 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
|
||||
else
|
||||
if(Pr)
|
||||
{
|
||||
server->machine.objname(Pr, maps[i].pr_vaddr, buffer,
|
||||
server->machine->objname(Pr, maps[i].pr_vaddr, buffer,
|
||||
BUFSIZ);
|
||||
if((len = resolvepath(buffer, entry[i].filename,
|
||||
GLIBTOP_MAP_FILENAME_LEN)) > 0)
|
||||
@@ -194,7 +194,7 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
|
||||
#if GLIBTOP_SOLARIS_RELEASE >= 50600
|
||||
|
||||
if(Pr)
|
||||
server->machine.pfree(Pr);
|
||||
server->machine->pfree(Pr);
|
||||
#endif
|
||||
buf->flags = _glibtop_sysdeps_proc_map;
|
||||
s_close(fd);
|
||||
|
@@ -46,7 +46,7 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
|
||||
struct psinfo psinfo;
|
||||
#else
|
||||
struct prpsinfo psinfo;
|
||||
int pagesize = server->machine.pagesize;
|
||||
int pagesize = server->machine->pagesize;
|
||||
#endif
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_mem));
|
||||
|
@@ -50,7 +50,7 @@ _glibtop_init_sem_limits_p (glibtop *server)
|
||||
{
|
||||
#if GLIBTOP_SOLARIS_RELEASE < 51000
|
||||
|
||||
kvm_t *kd = server->machine.kd;
|
||||
kvm_t *kd = server->machine->kd;
|
||||
|
||||
if(kd && !kvm_nlist(kd, nlst))
|
||||
server->sysdeps.sem_limits = _glibtop_sysdeps_sem_limits;
|
||||
@@ -65,7 +65,7 @@ void
|
||||
glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
|
||||
{
|
||||
#if GLIBTOP_SOLARIS_RELEASE < 51000
|
||||
kvm_t *kd = server->machine.kd;
|
||||
kvm_t *kd = server->machine->kd;
|
||||
glibtop_sem_limits sinfo;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_sem_limits));
|
||||
|
@@ -50,7 +50,7 @@ _glibtop_init_shm_limits_p (glibtop *server)
|
||||
{
|
||||
#if GLIBTOP_SOLARIS_RELEASE < 51000
|
||||
|
||||
kvm_t * const kd = server->machine.kd;
|
||||
kvm_t * const kd = server->machine->kd;
|
||||
|
||||
if(kd && !kvm_nlist(kd, nlst))
|
||||
server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits;
|
||||
@@ -66,7 +66,7 @@ glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
|
||||
{
|
||||
#if GLIBTOP_SOLARIS_RELEASE < 51000
|
||||
|
||||
kvm_t * const kd = server->machine.kd;
|
||||
kvm_t * const kd = server->machine->kd;
|
||||
glibtop_shm_limits sinfo;
|
||||
|
||||
|
||||
|
@@ -44,11 +44,11 @@ glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
|
||||
{
|
||||
memset (buf, 0, sizeof (glibtop_uptime));
|
||||
|
||||
if(!(server->machine.boot))
|
||||
if(!(server->machine->boot))
|
||||
return;
|
||||
|
||||
buf->boot_time = server->machine.boot;
|
||||
buf->uptime = time(NULL) - server->machine.boot;
|
||||
buf->boot_time = server->machine->boot;
|
||||
buf->uptime = time(NULL) - server->machine->boot;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_uptime;
|
||||
}
|
||||
|
@@ -25,11 +25,11 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
static inline void glibtop_suid_enter (glibtop *server) {
|
||||
setreuid (server->machine.uid, server->machine.euid);
|
||||
setreuid (server->machine->uid, server->machine->euid);
|
||||
};
|
||||
|
||||
static inline void glibtop_suid_leave (glibtop *server) {
|
||||
if (setreuid (server->machine.euid, server->machine.uid))
|
||||
if (setreuid (server->machine->euid, server->machine->uid))
|
||||
_exit (1);
|
||||
};
|
||||
|
||||
|
@@ -55,17 +55,17 @@ glibtop_open_p (glibtop *server, const char *program_name,
|
||||
|
||||
server->name = program_name;
|
||||
|
||||
server->machine.uid = getuid ();
|
||||
server->machine.euid = geteuid ();
|
||||
server->machine.gid = getgid ();
|
||||
server->machine.egid = getegid ();
|
||||
server->machine->uid = getuid ();
|
||||
server->machine->euid = geteuid ();
|
||||
server->machine->gid = getgid ();
|
||||
server->machine->egid = getegid ();
|
||||
|
||||
/* Drop priviledges. */
|
||||
|
||||
if (setreuid (server->machine.euid, server->machine.uid))
|
||||
if (setreuid (server->machine->euid, server->machine->uid))
|
||||
_exit (1);
|
||||
|
||||
if (setregid (server->machine.egid, server->machine.gid))
|
||||
if (setregid (server->machine->egid, server->machine->gid))
|
||||
_exit (1);
|
||||
|
||||
/* !!! END OF SUID ROOT PART !!! */
|
||||
|
@@ -55,7 +55,7 @@ glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf)
|
||||
#ifdef MULTIPROCESSOR
|
||||
/* get the mp_time array as well */
|
||||
|
||||
if (server->machine.ncpu > 1) {
|
||||
if (server->machine->ncpu > 1) {
|
||||
(void) _glibtop_getkval (server, _glibtop_nlist [X_MP_TIME].n_value,
|
||||
(int *) mp_time, sizeof (mp_time),
|
||||
_glibtop_nlist [X_MP_TIME].n_name);
|
||||
@@ -73,8 +73,8 @@ glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf)
|
||||
/* [FIXME]: I had no machine with more than one processor to test
|
||||
* this code !!! */
|
||||
|
||||
if (server->machine.ncpu > 1) {
|
||||
for (i = 0; i < server->machine.ncpu; i++) {
|
||||
if (server->machine->ncpu > 1) {
|
||||
for (i = 0; i < server->machine->ncpu; i++) {
|
||||
buf->user += mp_time [i][CP_USER];
|
||||
buf->nice += mp_time [i][CP_NICE];
|
||||
buf->sys += mp_time [i][CP_SYS];
|
||||
|
@@ -25,11 +25,11 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
static inline void glibtop_suid_enter (glibtop *server) {
|
||||
setregid (server->machine.gid, server->machine.egid);
|
||||
setregid (server->machine->gid, server->machine->egid);
|
||||
};
|
||||
|
||||
static inline void glibtop_suid_leave (glibtop *server) {
|
||||
if (setregid (server->machine.egid, server->machine.gid))
|
||||
if (setregid (server->machine->egid, server->machine->gid))
|
||||
_exit (1);
|
||||
};
|
||||
|
||||
|
@@ -42,7 +42,7 @@ glibtop_get_loadavg_p (glibtop *server, glibtop_loadavg *buf)
|
||||
|
||||
/* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */
|
||||
|
||||
setregid (server->machine.gid, server->machine.egid);
|
||||
setregid (server->machine->gid, server->machine->egid);
|
||||
|
||||
/* get the load average array */
|
||||
|
||||
@@ -50,7 +50,7 @@ glibtop_get_loadavg_p (glibtop *server, glibtop_loadavg *buf)
|
||||
(int *) avenrun, sizeof (avenrun),
|
||||
_glibtop_nlist [X_AVENRUN].n_name);
|
||||
|
||||
if (setregid (server->machine.egid, server->machine.gid))
|
||||
if (setregid (server->machine->egid, server->machine->gid))
|
||||
_exit (1);
|
||||
|
||||
/* !!! END OF SGID KMEM PART !!! */
|
||||
|
@@ -31,7 +31,7 @@ static const unsigned long _glibtop_sysdeps_mem =
|
||||
|
||||
/* define pagetok in terms of pageshift */
|
||||
|
||||
#define pagetok(size) ((size) << server->machine.pageshift)
|
||||
#define pagetok(size) ((size) << server->machine->pageshift)
|
||||
|
||||
/* Provides information about memory usage. */
|
||||
|
||||
@@ -48,9 +48,9 @@ glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
|
||||
|
||||
/* get the array of physpage descriptors */
|
||||
|
||||
(void) _glibtop_getkval (server, server->machine.pages,
|
||||
(int *) server->machine.physpage,
|
||||
server->machine.bytesize,
|
||||
(void) _glibtop_getkval (server, server->machine->pages,
|
||||
(int *) server->machine->physpage,
|
||||
server->machine->bytesize,
|
||||
"array _page");
|
||||
|
||||
glibtop_suid_leave (server);
|
||||
@@ -67,9 +67,9 @@ glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
|
||||
|
||||
/* bop thru the array counting page types */
|
||||
|
||||
pp = server->machine.physpage;
|
||||
pp = server->machine->physpage;
|
||||
inuse = free = locked = 0;
|
||||
for (cnt = server->machine.count; --cnt >= 0; pp++) {
|
||||
for (cnt = server->machine->count; --cnt >= 0; pp++) {
|
||||
if (pp->p_free)
|
||||
free++;
|
||||
else if (pp->p_lock || pp->p_keepcnt > 0)
|
||||
|
@@ -50,7 +50,7 @@ glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
|
||||
|
||||
/* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */
|
||||
|
||||
setregid (server->machine.gid, server->machine.egid);
|
||||
setregid (server->machine->gid, server->machine->egid);
|
||||
|
||||
/* get the load average array */
|
||||
|
||||
@@ -58,7 +58,7 @@ glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
|
||||
(int *) &msginfo, sizeof (msginfo),
|
||||
_glibtop_nlist [X_MSGINFO].n_name);
|
||||
|
||||
if (setregid (server->machine.egid, server->machine.gid))
|
||||
if (setregid (server->machine->egid, server->machine->gid))
|
||||
_exit (1);
|
||||
|
||||
/* !!! END OF SGID KMEM PART !!! */
|
||||
|
@@ -85,37 +85,37 @@ glibtop_open_p (glibtop *server, const char *program_name,
|
||||
|
||||
server->name = program_name;
|
||||
|
||||
server->machine.uid = getuid ();
|
||||
server->machine.euid = geteuid ();
|
||||
server->machine.gid = getgid ();
|
||||
server->machine.egid = getegid ();
|
||||
server->machine->uid = getuid ();
|
||||
server->machine->euid = geteuid ();
|
||||
server->machine->gid = getgid ();
|
||||
server->machine->egid = getegid ();
|
||||
|
||||
/* initialize the kernel interface */
|
||||
|
||||
server->machine.kd = kvm_open (NULL, NULL, NULL, O_RDONLY, "libgtop");
|
||||
server->machine->kd = kvm_open (NULL, NULL, NULL, O_RDONLY, "libgtop");
|
||||
|
||||
if (server->machine.kd == NULL)
|
||||
if (server->machine->kd == NULL)
|
||||
glibtop_error_io_r (server, "kvm_open");
|
||||
|
||||
/* get the list of symbols we want to access in the kernel */
|
||||
|
||||
server->machine.nlist_count = kvm_nlist
|
||||
(server->machine.kd, _glibtop_nlist);
|
||||
server->machine->nlist_count = kvm_nlist
|
||||
(server->machine->kd, _glibtop_nlist);
|
||||
|
||||
if (server->machine.nlist_count < 0)
|
||||
if (server->machine->nlist_count < 0)
|
||||
glibtop_error_io_r (server, "nlist");
|
||||
|
||||
#ifdef MULTIPROCESSOR
|
||||
/* were ncpu and xp_time not found in the nlist? */
|
||||
|
||||
if ((server->machine.nlist_count > 0) &&
|
||||
if ((server->machine->nlist_count > 0) &&
|
||||
(_glibtop_nlist[X_NCPU].n_type == 0) &&
|
||||
(_glibtop_nlist[X_MP_TIME].n_type == 0)) {
|
||||
/* we were compiled on an MP system but we are not running
|
||||
* on one, so we will pretend this didn't happen and set
|
||||
* ncpu = 1 */
|
||||
server->machine.nlist_count -= 2;
|
||||
server->machine.ncpu = 1;
|
||||
server->machine->nlist_count -= 2;
|
||||
server->machine->ncpu = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -125,76 +125,76 @@ glibtop_open_p (glibtop *server, const char *program_name,
|
||||
|
||||
/* Get the number of CPUs on this system. */
|
||||
syscall(SYS_getcpustatus, &status,
|
||||
&server->machine.ncpu, &type);
|
||||
&server->machine->ncpu, &type);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make sure all of the symbols were found. */
|
||||
|
||||
if ((server->machine.nlist_count > 0) &&
|
||||
if ((server->machine->nlist_count > 0) &&
|
||||
(_glibtop_check_nlist (server, _glibtop_nlist) > 0))
|
||||
_exit (1);
|
||||
|
||||
/* Get process array stuff. */
|
||||
|
||||
(void) _glibtop_getkval (server, _glibtop_nlist[X_NPROC].n_value,
|
||||
(int *)(&server->machine.nproc),
|
||||
sizeof (server->machine.nproc),
|
||||
(int *)(&server->machine->nproc),
|
||||
sizeof (server->machine->nproc),
|
||||
_glibtop_nlist[X_NPROC].n_name);
|
||||
|
||||
(void) _glibtop_getkval (server, _glibtop_nlist[X_PROC].n_value,
|
||||
(int *)(&server->machine.ptable_offset),
|
||||
sizeof (server->machine.ptable_offset),
|
||||
(int *)(&server->machine->ptable_offset),
|
||||
sizeof (server->machine->ptable_offset),
|
||||
_glibtop_nlist[X_PROC].n_name);
|
||||
|
||||
server->machine.ptable_size = (unsigned long) server->machine.nproc *
|
||||
server->machine->ptable_size = (unsigned long) server->machine->nproc *
|
||||
(unsigned long) sizeof (struct proc);
|
||||
|
||||
server->machine.proc_table = g_malloc
|
||||
(server, server->machine.ptable_size);
|
||||
server->machine->proc_table = g_malloc
|
||||
(server, server->machine->ptable_size);
|
||||
|
||||
/* This are for the memory statistics. */
|
||||
|
||||
(void) _glibtop_getkval (server, _glibtop_nlist[X_PAGES].n_value,
|
||||
(int *)(&server->machine.pages),
|
||||
sizeof (server->machine.pages),
|
||||
(int *)(&server->machine->pages),
|
||||
sizeof (server->machine->pages),
|
||||
_glibtop_nlist[X_PAGES].n_name);
|
||||
|
||||
(void) _glibtop_getkval (server, _glibtop_nlist[X_EPAGES].n_value,
|
||||
(int *)(&server->machine.epages),
|
||||
sizeof (server->machine.epages),
|
||||
(int *)(&server->machine->epages),
|
||||
sizeof (server->machine->epages),
|
||||
_glibtop_nlist[X_EPAGES].n_name);
|
||||
|
||||
server->machine.bytesize = server->machine.epages -
|
||||
server->machine.pages;
|
||||
server->machine.count = server->machine.bytesize /
|
||||
server->machine->bytesize = server->machine->epages -
|
||||
server->machine->pages;
|
||||
server->machine->count = server->machine->bytesize /
|
||||
sizeof (struct page);
|
||||
|
||||
server->machine.physpage = (struct page *)
|
||||
g_malloc (server->machine.bytesize);
|
||||
server->machine->physpage = (struct page *)
|
||||
g_malloc (server->machine->bytesize);
|
||||
|
||||
/* get the page size with "getpagesize" and
|
||||
* calculate pageshift from it */
|
||||
|
||||
pagesize = getpagesize();
|
||||
|
||||
server->machine.pageshift = 0;
|
||||
server->machine->pageshift = 0;
|
||||
|
||||
while (pagesize > 1) {
|
||||
server->machine.pageshift++;
|
||||
server->machine->pageshift++;
|
||||
pagesize >>= 1;
|
||||
}
|
||||
|
||||
/* we only need the amount of log(2)1024 for our conversion */
|
||||
|
||||
server->machine.pageshift -= LOG1024;
|
||||
server->machine->pageshift -= LOG1024;
|
||||
|
||||
/* Drop priviledges. */
|
||||
|
||||
if (setreuid (server->machine.euid, server->machine.uid))
|
||||
if (setreuid (server->machine->euid, server->machine->uid))
|
||||
_exit (1);
|
||||
|
||||
if (setregid (server->machine.egid, server->machine.gid))
|
||||
if (setregid (server->machine->egid, server->machine->gid))
|
||||
_exit (1);
|
||||
|
||||
/* !!! END OF SUID ROOT PART !!! */
|
||||
@@ -254,7 +254,7 @@ _glibtop_getkval (void *void_server, unsigned long offset, int *ptr,
|
||||
{
|
||||
glibtop *server = (glibtop *) void_server;
|
||||
|
||||
if (kvm_read (server->machine.kd, offset, ptr, size) != size)
|
||||
if (kvm_read (server->machine->kd, offset, ptr, size) != size)
|
||||
{
|
||||
if (*refstr == '!') return 0;
|
||||
|
||||
@@ -274,16 +274,16 @@ _glibtop_read_proc_table (void *void_server)
|
||||
|
||||
/* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */
|
||||
|
||||
setregid (server->machine.gid, server->machine.egid);
|
||||
setregid (server->machine->gid, server->machine->egid);
|
||||
|
||||
/* Read process table from kernel. */
|
||||
|
||||
(void) _glibtop_getkval (server, server->machine.ptable_offset,
|
||||
(int *) server->machine.proc_table,
|
||||
(size_t) server->machine.ptable_size,
|
||||
(void) _glibtop_getkval (server, server->machine->ptable_offset,
|
||||
(int *) server->machine->proc_table,
|
||||
(size_t) server->machine->ptable_size,
|
||||
_glibtop_nlist[X_PROC].n_name);
|
||||
|
||||
if (setregid (server->machine.egid, server->machine.gid))
|
||||
if (setregid (server->machine->egid, server->machine->gid))
|
||||
_exit (1);
|
||||
|
||||
/* !!! END OF SGID KMEM PART !!! */
|
||||
@@ -299,8 +299,8 @@ _glibtop_find_pid (void *void_server, pid_t pid)
|
||||
|
||||
glibtop *server = (glibtop *) void_server;
|
||||
|
||||
for (pp = server->machine.proc_table, i = 0;
|
||||
i < server->machine.nproc; pp++, i++) {
|
||||
for (pp = server->machine->proc_table, i = 0;
|
||||
i < server->machine->nproc; pp++, i++) {
|
||||
if ((pp->p_stat != 0) && (pp->p_pid == pid))
|
||||
return pp;
|
||||
}
|
||||
|
@@ -55,8 +55,8 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
|
||||
|
||||
/* Count number of processes. */
|
||||
|
||||
for (pp = server->machine.proc_table, i = 0;
|
||||
i < server->machine.nproc; pp++, i++) {
|
||||
for (pp = server->machine->proc_table, i = 0;
|
||||
i < server->machine->nproc; pp++, i++) {
|
||||
if (pp->p_stat == 0)
|
||||
continue;
|
||||
else
|
||||
@@ -74,8 +74,8 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
|
||||
|
||||
/* Write process list. */
|
||||
|
||||
for (pp = server->machine.proc_table, i = 0, nproc = 0;
|
||||
i < server->machine.nproc; pp++, i++) {
|
||||
for (pp = server->machine->proc_table, i = 0, nproc = 0;
|
||||
i < server->machine->nproc; pp++, i++) {
|
||||
if (pp->p_stat == 0)
|
||||
continue;
|
||||
proc_list [nproc++] = pp->p_pid;
|
||||
|
@@ -52,7 +52,7 @@ glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
|
||||
|
||||
/* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */
|
||||
|
||||
setregid (server->machine.gid, server->machine.egid);
|
||||
setregid (server->machine->gid, server->machine->egid);
|
||||
|
||||
/* get the load average array */
|
||||
|
||||
@@ -60,7 +60,7 @@ glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
|
||||
(int *) &seminfo, sizeof (seminfo),
|
||||
_glibtop_nlist [X_SEMINFO].n_name);
|
||||
|
||||
if (setregid (server->machine.egid, server->machine.gid))
|
||||
if (setregid (server->machine->egid, server->machine->gid))
|
||||
_exit (1);
|
||||
|
||||
/* !!! END OF SGID KMEM PART !!! */
|
||||
|
@@ -50,7 +50,7 @@ glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
|
||||
|
||||
/* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */
|
||||
|
||||
setregid (server->machine.gid, server->machine.egid);
|
||||
setregid (server->machine->gid, server->machine->egid);
|
||||
|
||||
/* get the load average array */
|
||||
|
||||
@@ -58,7 +58,7 @@ glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
|
||||
(int *) &shminfo, sizeof (shminfo),
|
||||
_glibtop_nlist [X_SHMINFO].n_name);
|
||||
|
||||
if (setregid (server->machine.egid, server->machine.gid))
|
||||
if (setregid (server->machine->egid, server->machine->gid))
|
||||
_exit (1);
|
||||
|
||||
/* !!! END OF SGID KMEM PART !!! */
|
||||
|
Reference in New Issue
Block a user