Reflect latest interface changes.

This commit is contained in:
Martin Baulig
1999-12-25 19:50:36 +00:00
parent e7b42a66b1
commit c76bf0bfab
10 changed files with 355 additions and 303 deletions

View File

@@ -26,8 +26,10 @@
#include <glibtop/xmalloc.h>
#include <glibtop/procargs.h>
#include <glibtop_private.h>
static const unsigned long _glibtop_sysdeps_proc_args =
(1L << GLIBTOP_PROC_ARGS_SIZE);
(1L << GLIBTOP_ARRAY_SIZE) + (1L << GLIBTOP_ARRAY_NUMBER);
/* Init function. */
@@ -35,49 +37,59 @@ int
glibtop_init_proc_args_s (glibtop *server)
{
server->sysdeps.proc_args = _glibtop_sysdeps_proc_args;
return 0;
}
/* Provides detailed information about a process. */
char *
glibtop_get_proc_args_s (glibtop *server, glibtop_proc_args *buf,
pid_t pid, unsigned max_len)
char **
glibtop_get_proc_args_s (glibtop *server, glibtop_array *array, pid_t pid)
{
#ifdef HAVE_PROCFS_H
struct psinfo pinfo;
#else
struct prpsinfo pinfo;
#endif
int len, i;
char *ret, *p;
int retval, len, i, count;
char *ret, *p, **ptrlist;
memset (buf, 0, sizeof (glibtop_proc_args));
memset (array, 0, sizeof (glibtop_array));
if(glibtop_get_proc_data_psinfo_s(server, &pinfo, pid))
retval = glibtop_get_proc_data_psinfo_s(server, &pinfo, pid);
if (retval) {
server->glibtop_errno = retval;
return NULL;
}
for(len = 0; len < PRARGSZ; ++len)
if(!(pinfo.pr_psargs[len]))
break;
if(max_len)
{
ret = glibtop_malloc_r(server, max_len + 1);
if(max_len < len)
len = max_len;
memcpy(ret, pinfo.pr_psargs, len);
ret[len] = 0;
}
else
{
ret = glibtop_malloc_r(server, len + 1);
ret = glibtop_malloc_r (server, len+1);
memcpy(ret, pinfo.pr_psargs, len);
ret[len] = 0;
buf->size = len;
buf->flags = _glibtop_sysdeps_proc_args;
}
count = 0;
for(p = ret; *p; ++p)
if(*p == ' ')
*p = 0;
return ret;
if(*p == ' ') {
*p = 0; count++;
}
ptrlist = glibtop_calloc_r(server, len+1, sizeof (char *));
for (i = 0, p = ret; i < count; i++) {
ptrlist [i] = glibtop_strdup_r (server, p);
p += strlen (p) + 1;
}
ptrlist [count] = NULL;
glibtop_free_r (server, ret);
array->number = count;
array->size = sizeof (char *);
array->flags = _glibtop_sysdeps_proc_args;
return ptrlist;
}

View File

@@ -32,6 +32,8 @@ int
glibtop_init_proc_kernel_s (glibtop *server)
{
server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel;
return 0;
}
/* Provides detailed information about a process. */
@@ -41,4 +43,6 @@ glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf,
pid_t pid)
{
memset (buf, 0, sizeof (glibtop_proc_kernel));
return 0;
}

View File

@@ -30,11 +30,11 @@
#include <dirent.h>
#include <ctype.h>
#define GLIBTOP_PROCLIST_FLAGS 3
#include <glibtop_private.h>
static const unsigned long _glibtop_sysdeps_proclist =
(1L << GLIBTOP_PROCLIST_TOTAL) + (1L << GLIBTOP_PROCLIST_NUMBER) +
(1L << GLIBTOP_PROCLIST_SIZE);
(1L << GLIBTOP_ARRAY_TOTAL) + (1L << GLIBTOP_ARRAY_NUMBER) +
(1L << GLIBTOP_ARRAY_SIZE);
/* Init function. */
@@ -42,6 +42,8 @@ int
glibtop_init_proclist_s (glibtop *server)
{
server->sysdeps.proclist = _glibtop_sysdeps_proclist;
return 0;
}
#define BLOCK_COUNT 256
@@ -55,7 +57,7 @@ glibtop_init_proclist_s (glibtop *server)
* each buf->size big. The total size is stored in buf->total. */
unsigned *
glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf,
glibtop_get_proclist_s (glibtop *server, glibtop_array *array,
int64_t which, int64_t arg)
{
DIR *proc;
@@ -65,15 +67,17 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf,
unsigned pids [BLOCK_COUNT], *pids_chain = NULL;
unsigned pids_size = 0, pids_offset = 0, new_size;
struct stat statb;
int len, i, ok;
int len, ok;
memset (buf, 0, sizeof (glibtop_proclist));
memset (array, 0, sizeof (glibtop_array));
mask = which & ~GLIBTOP_KERN_PROC_MASK;
which &= GLIBTOP_KERN_PROC_MASK;
/* Check if the user wanted only one process */
if(which == GLIBTOP_KERN_PROC_PID) {
pid = arg;
if(mask) {
#ifdef HAVE_PROCFS_H
struct psinfo psinfo;
@@ -89,13 +93,17 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf,
if(mask & GLIBTOP_EXCLUDE_NOTTY && psinfo.pr_ttydev == PRNODEV)
return NULL;
} else {
sprintf(buffer, "/proc/%d", arg);
sprintf(buffer, "/proc/%ld", (long)arg);
if(s_stat(buffer, &statb) < 0)
return NULL;
}
if(!(pids_chain = glibtop_malloc(sizeof(unsigned))))
if(!(pids_chain = glibtop_calloc_r(server, 1, sizeof(unsigned))))
return NULL;
*pids_chain = pid;
array->number = 1;
array->size = sizeof(unsigned);
array->total = array->number * array->size;
array->flags = _glibtop_sysdeps_proclist;
return pids_chain;
}
@@ -235,15 +243,15 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf,
pids_offset += BLOCK_COUNT;
/* Since everything is ok now, we can set buf->flags, fill in the
/* Since everything is ok now, we can set array->flags, fill in the
* remaining fields and return the `pids_chain'. */
buf->flags = _glibtop_sysdeps_proclist;
array->flags = _glibtop_sysdeps_proclist;
buf->size = sizeof (unsigned);
buf->number = total;
array->size = sizeof (unsigned);
array->number = total;
buf->total = total * sizeof (unsigned);
array->total = array->number * array->size;
return pids_chain;
}

View File

@@ -30,36 +30,37 @@
#include <errno.h>
#include <alloca.h>
#include "safeio.h"
#include <glibtop_private.h>
static const unsigned long _glibtop_sysdeps_proc_map =
(1L << GLIBTOP_PROC_MAP_NUMBER) + (1L << GLIBTOP_PROC_MAP_TOTAL) +
(1L << GLIBTOP_PROC_MAP_SIZE);
(1L << GLIBTOP_ARRAY_NUMBER) + (1L << GLIBTOP_ARRAY_TOTAL) +
(1L << GLIBTOP_ARRAY_SIZE);
static const unsigned long _glibtop_sysdeps_map_entry =
(1L << GLIBTOP_MAP_ENTRY_START) + (1L << GLIBTOP_MAP_ENTRY_END) +
(1L << GLIBTOP_MAP_ENTRY_OFFSET) + (1L << GLIBTOP_MAP_ENTRY_PERM);
static const unsigned long _glibtop_sysdeps_map_device =
(1L << GLIBTOP_MAP_ENTRY_DEVICE) + (1L << GLIBTOP_MAP_ENTRY_INODE);
/* Init function. */
int
glibtop_init_proc_map_s (glibtop *server)
{
server->sysdeps.proc_map = _glibtop_sysdeps_proc_map;
return 0;
}
/* Provides detailed information about a process. */
glibtop_map_entry *
glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
glibtop_get_proc_map_s (glibtop *server, glibtop_array *array, pid_t pid)
{
int fd, i, nmaps, pr_err, heap;
#if GLIBTOP_SOLARIS_RELEASE >= 560
prxmap_t *maps;
struct ps_prochandle *Pr;
struct ps_prochandle *Pr = NULL;
#else
prmap_t *maps;
#endif
@@ -76,22 +77,20 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
struct stat inode;
char buffer[BUFSIZ];
memset (buf, 0, sizeof (glibtop_proc_map));
memset (array, 0, sizeof (glibtop_array));
#ifdef HAVE_PROCFS_H
sprintf(buffer, "/proc/%d/xmap", (int)pid);
#else
sprintf(buffer, "/proc/%d", (int)pid);
#endif
if((fd = s_open(buffer, O_RDONLY)) < 0)
{
if((fd = s_open(buffer, O_RDONLY)) < 0) {
if(errno != EPERM && errno != EACCES)
glibtop_warn_io_r(server, "open (%s)", buffer);
return NULL;
}
#ifdef HAVE_PROCFS_H
if(fstat(fd, &inode) < 0)
{
if(fstat(fd, &inode) < 0) {
if(errno != EOVERFLOW)
glibtop_warn_io_r(server, "fstat (%s)", buffer);
/* else call daemon for 64-bit support */
@@ -100,22 +99,19 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
}
maps = alloca(inode.st_size);
nmaps = inode.st_size / sizeof(prxmap_t);
if(s_pread(fd, maps, inode.st_size, 0) != inode.st_size)
{
if(s_pread(fd, maps, inode.st_size, 0) != inode.st_size) {
glibtop_warn_io_r(server, "pread (%s)", buffer);
s_close(fd);
return NULL;
}
#else
if(ioctl(fd, PIOCNMAP, &nmaps) < 0)
{
if(ioctl(fd, PIOCNMAP, &nmaps) < 0) {
glibtop_warn_io_r(server, "ioctl(%s, PIOCNMAP)", buffer);
s_close(fd);
return NULL;
}
maps = alloca((nmaps + 1) * sizeof(prmap_t));
if(ioctl(fd, PIOCMAP, maps) < 0)
{
if(ioctl(fd, PIOCMAP, maps) < 0) {
glibtop_warn_io_r(server, "ioctl(%s, PIOCMAP)", buffer);
s_close(fd);
return NULL;
@@ -124,9 +120,9 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
if(!(entry = glibtop_malloc_r(server,
nmaps * sizeof(glibtop_map_entry))))
return NULL;
buf->number = nmaps;
buf->size = sizeof(glibtop_map_entry);
buf->total = nmaps * sizeof(glibtop_map_entry);
array->number = nmaps;
array->size = sizeof(glibtop_map_entry);
array->total = nmaps * sizeof(glibtop_map_entry);
memset(entry, 0, nmaps * sizeof(glibtop_map_entry));
@@ -136,8 +132,7 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
server->_priv->machine.pfree)
Pr = (server->_priv->machine.pgrab)(pid, 1, &pr_err);
#endif
for(heap = 0,i = 0; i < nmaps; ++i)
{
for(heap = 0,i = 0; i < nmaps; ++i) {
int len;
entry[i].start = maps[i].pr_vaddr;
@@ -145,8 +140,7 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
#if GLIBTOP_SOLARIS_RELEASE >= 560
if(maps[i].pr_dev != PRNODEV)
{
if(maps[i].pr_dev != PRNODEV) {
entry[i].device = maps[i].pr_dev;
entry[i].inode = maps[i].pr_ino;
entry[i].flags |= _glibtop_sysdeps_map_device;
@@ -167,41 +161,37 @@ glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
#if GLIBTOP_SOLARIS_RELEASE >= 560
if(maps[i].pr_mflags & MA_ANON)
{
if(!heap)
{
if(maps[i].pr_mflags & MA_ANON) {
if(!heap) {
++heap;
strcpy(entry[i].filename, "[ heap ]");
}
else
} else {
if(i == nmaps - 1)
strcpy(entry[i].filename, "[ stack ]");
else
strcpy(entry[i].filename, "[ anon ]");
entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME);
}
else
if(Pr)
{
entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME);
} else {
if(Pr) {
server->_priv->machine.objname(Pr, maps[i].pr_vaddr, buffer,
BUFSIZ);
if((len = resolvepath(buffer, entry[i].filename,
GLIBTOP_MAP_FILENAME_LEN)) > 0)
{
GLIBTOP_MAP_FILENAME_LEN)) > 0) {
entry[i].filename[len] = 0;
entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME);
}
}
#endif
}
}
}
#if GLIBTOP_SOLARIS_RELEASE >= 560
if(Pr)
server->_priv->machine.pfree(Pr);
#endif
buf->flags = _glibtop_sysdeps_proc_map;
array->flags = _glibtop_sysdeps_proc_map;
s_close(fd);
return entry;
}

View File

@@ -24,6 +24,8 @@
#include <glibtop.h>
#include <glibtop/procmem.h>
#include <glibtop_private.h>
static const unsigned long _glibtop_sysdeps_proc_mem =
(1L << GLIBTOP_PROC_MEM_SIZE) + (1L << GLIBTOP_PROC_MEM_VSIZE) +
(1L << GLIBTOP_PROC_MEM_RESIDENT) + (1L << GLIBTOP_PROC_MEM_RSS);
@@ -34,6 +36,8 @@ int
glibtop_init_proc_mem_s (glibtop *server)
{
server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem;
return 0;
}
/* Provides detailed information about a process. */
@@ -47,11 +51,12 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
struct prpsinfo psinfo;
int pagesize = server->_priv->machine.pagesize;
#endif
int retval;
memset (buf, 0, sizeof (glibtop_proc_mem));
if(glibtop_get_proc_data_psinfo_s(server, &psinfo, pid))
return;
retval = glibtop_get_proc_data_psinfo_s(server, &psinfo, pid);
if (retval) return retval;
#ifdef HAVE_PROCFS_H
buf->size = buf->vsize = psinfo.pr_size << 10;
@@ -61,4 +66,6 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
buf->resident = buf->rss = psinfo.pr_rssize << pagesize << 10;
#endif
buf->flags = _glibtop_sysdeps_proc_mem;
return 0;
}

View File

@@ -32,6 +32,8 @@ int
glibtop_init_proc_segment_s (glibtop *server)
{
server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment;
return 0;
}
/* Provides detailed information about a process. */
@@ -41,4 +43,6 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
pid_t pid)
{
memset (buf, 0, sizeof (glibtop_proc_segment));
return 0;
}

View File

@@ -35,6 +35,8 @@ int
glibtop_init_proc_signal_s (glibtop *server)
{
server->sysdeps.proc_signal = _glibtop_sysdeps_proc_signal;
return 0;
}
/* Provides detailed information about a process. */
@@ -48,12 +50,12 @@ glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf,
#else
struct prstatus pstatus;
#endif
int size;
int retval, size;
memset (buf, 0, sizeof (glibtop_proc_signal));
if(glibtop_get_proc_status_s(server, &pstatus, pid))
return;
retval = glibtop_get_proc_status_s(server, &pstatus, pid);
if (retval) return retval;
if(sizeof(buf->signal) < sizeof(sigset_t))
size = sizeof(buf->signal);
@@ -71,4 +73,6 @@ glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf,
but this should be a good enough approximation. */
buf->flags = _glibtop_sysdeps_proc_signal;
return 0;
}

View File

@@ -41,6 +41,8 @@ int
glibtop_init_proc_state_s (glibtop *server)
{
server->sysdeps.proc_state = _glibtop_sysdeps_proc_state;
return 0;
}
/* Provides detailed information about a process. */
@@ -53,36 +55,45 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
#else
struct prpsinfo psinfo;
#endif
unsigned state;
int retval;
memset (buf, 0, sizeof (glibtop_proc_state));
if (glibtop_get_proc_data_psinfo_s (server, &psinfo, pid))
return;
retval = glibtop_get_proc_data_psinfo_s (server, &psinfo, pid);
if (retval) return retval;
buf->uid = psinfo.pr_euid;
buf->gid = psinfo.pr_egid;
buf->ruid = psinfo.pr_uid;
buf->rgid = psinfo.pr_gid;
#ifdef HAVE_PROCFS_H
switch(psinfo.pr_lwp.pr_state)
state = psinfo.pr_lwp.pr_state;
#else
switch(psinfo.pr_state)
state = psinfo.pr_state;
#endif
{
switch(state) {
case SONPROC:
#ifdef HAVE_PROCFS_H
buf->has_cpu = 1;
buf->processor = psinfo.pr_lwp.pr_onpro;
#endif
case SRUN: buf->state = GLIBTOP_PROCESS_RUNNING;
break;
case SZOMB: buf->state = GLIBTOP_PROCESS_ZOMBIE;
case SRUN:
buf->state = GLIBTOP_PROCESS_RUNNING;
break;
case SSLEEP: buf->state = GLIBTOP_PROCESS_INTERRUPTIBLE;
case SZOMB:
buf->state = GLIBTOP_PROCESS_ZOMBIE;
break;
case SSTOP: buf->state = GLIBTOP_PROCESS_STOPPED;
case SSLEEP:
buf->state = GLIBTOP_PROCESS_INTERRUPTIBLE;
break;
case SIDL: buf->state = GLIBTOP_PROCESS_UNINTERRUPTIBLE;
case SSTOP:
buf->state = GLIBTOP_PROCESS_STOPPED;
break;
case SIDL:
buf->state = GLIBTOP_PROCESS_UNINTERRUPTIBLE;
}
#ifdef HAVE_PROCFS_H
buf->last_processor = psinfo.pr_lwp.pr_onpro;
@@ -90,4 +101,6 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
strncpy (buf->cmd, psinfo.pr_fname, 39);
buf->flags = _glibtop_sysdeps_proc_state;
return 0;
}

View File

@@ -36,6 +36,8 @@ int
glibtop_init_proc_time_s (glibtop *server)
{
server->sysdeps.proc_time = _glibtop_sysdeps_proc_time;
return 0;
}
/* Provides detailed information about a process. */
@@ -45,15 +47,17 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf,
pid_t pid)
{
struct prusage prusage;
int retval;
memset (buf, 0, sizeof (glibtop_proc_time));
/* Don't do it for scheduler, we don't want to frighten our users */
if(pid)
{
if (glibtop_get_proc_data_usage_s (server, &prusage, pid))
return;
if (!pid)
return -GLIBTOP_ERROR_INVALID_ARGUMENT;
retval = glibtop_get_proc_data_usage_s (server, &prusage, pid);
if (retval) return retval;
buf->start_time = prusage.pr_create.tv_sec;
@@ -63,7 +67,8 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf,
prusage.pr_utime.tv_nsec / 1E+3;
buf->stime = prusage.pr_stime.tv_sec * 1E+6 +
prusage.pr_stime.tv_nsec / 1E+3;
}
buf->flags = _glibtop_sysdeps_proc_time;
return 0;
}

View File

@@ -46,6 +46,8 @@ glibtop_init_proc_uid_s (glibtop *server)
{
server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid_psinfo +
_glibtop_sysdeps_proc_uid_prcred;
return 0;
}
/* Provides detailed information about a process. */
@@ -61,11 +63,12 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
struct prpsinfo psinfo;
gid_t groups[1]; /* dummy for consistent function prototype */
#endif
int retval;
memset (buf, 0, sizeof (glibtop_proc_uid));
if (glibtop_get_proc_data_psinfo_s (server, &psinfo, pid))
return;
retval = glibtop_get_proc_data_psinfo_s (server, &psinfo, pid);
if (retval) return retval;
buf->euid = psinfo.pr_euid;
buf->uid = psinfo.pr_uid;
@@ -93,8 +96,8 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
buf->flags = _glibtop_sysdeps_proc_uid_psinfo;
if(glibtop_get_proc_credentials_s(server, &prcred, groups, pid))
return;
retval = glibtop_get_proc_credentials_s(server, &prcred, groups, pid);
if (retval) return retval;
buf->suid = prcred.pr_suid;
buf->sgid = prcred.pr_sgid;
@@ -104,13 +107,15 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
#ifdef HAVE_PROCFS_H
if(sizeof(int) == sizeof(gid_t))
memcpy(buf->groups, &groups, buf->ngroups * sizeof(gid_t));
else
{
else {
int i;
for(i = 0; i < buf->ngroups; ++i)
buf->groups[i] = groups[i];
}
#endif
buf->flags += _glibtop_sysdeps_proc_uid_prcred;
buf->flags |= _glibtop_sysdeps_proc_uid_prcred;
return 0;
}