The indentation in LibGTop was done with the following command:
find . -name \*.[ch] | xargs -i emacs -batch {} \ -l /gnome/compile/libgtop/misc/format.el -f save-buffer December 26, 1999 Martin
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
@@ -63,44 +65,44 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
||||
if(!kc)
|
||||
return -GLIBTOP_ERROR_INCOMPATIBLE_KERNEL;
|
||||
switch(kstat_chain_update(kc))
|
||||
{
|
||||
{
|
||||
case -1: assert(0); /* Debugging purposes, shouldn't happen */
|
||||
case 0: break;
|
||||
default: glibtop_get_kstats(server);
|
||||
}
|
||||
}
|
||||
ncpu = server->ncpu;
|
||||
if (ncpu > GLIBTOP_NCPU)
|
||||
ncpu = GLIBTOP_NCPU;
|
||||
|
||||
for (cpu = 0, found = 0; cpu < GLIBTOP_NCPU && found != ncpu; cpu++)
|
||||
{
|
||||
kstat_t *ksp = server->_priv->machine.cpu_stat_kstat [cpu];
|
||||
if (!ksp) continue;
|
||||
{
|
||||
kstat_t *ksp = server->_priv->machine.cpu_stat_kstat [cpu];
|
||||
if (!ksp) continue;
|
||||
|
||||
++found;
|
||||
if(p_online(cpu, P_STATUS) == P_ONLINE)
|
||||
buf->xcpu_flags |= (1L << cpu);
|
||||
else
|
||||
continue;
|
||||
ret = kstat_read (kc, ksp, &cpu_stat);
|
||||
++found;
|
||||
if(p_online(cpu, P_STATUS) == P_ONLINE)
|
||||
buf->xcpu_flags |= (1L << cpu);
|
||||
else
|
||||
continue;
|
||||
ret = kstat_read (kc, ksp, &cpu_stat);
|
||||
|
||||
if (ret == -1) {
|
||||
glibtop_warn_io_r (server, "kstat_read (cpu_stat%d)", cpu);
|
||||
continue;
|
||||
if (ret == -1) {
|
||||
glibtop_warn_io_r (server, "kstat_read (cpu_stat%d)", cpu);
|
||||
continue;
|
||||
}
|
||||
|
||||
buf->xcpu_idle [cpu] = cpu_stat.cpu_sysinfo.cpu [CPU_IDLE];
|
||||
buf->xcpu_user [cpu] = cpu_stat.cpu_sysinfo.cpu [CPU_USER];
|
||||
buf->xcpu_sys [cpu] = cpu_stat.cpu_sysinfo.cpu [CPU_KERNEL];
|
||||
|
||||
buf->xcpu_total [cpu] = buf->xcpu_idle [cpu] + buf->xcpu_user [cpu] +
|
||||
buf->xcpu_sys [cpu];
|
||||
|
||||
buf->idle += cpu_stat.cpu_sysinfo.cpu [CPU_IDLE];
|
||||
buf->user += cpu_stat.cpu_sysinfo.cpu [CPU_USER];
|
||||
buf->sys += cpu_stat.cpu_sysinfo.cpu [CPU_KERNEL];
|
||||
}
|
||||
|
||||
buf->xcpu_idle [cpu] = cpu_stat.cpu_sysinfo.cpu [CPU_IDLE];
|
||||
buf->xcpu_user [cpu] = cpu_stat.cpu_sysinfo.cpu [CPU_USER];
|
||||
buf->xcpu_sys [cpu] = cpu_stat.cpu_sysinfo.cpu [CPU_KERNEL];
|
||||
|
||||
buf->xcpu_total [cpu] = buf->xcpu_idle [cpu] + buf->xcpu_user [cpu] +
|
||||
buf->xcpu_sys [cpu];
|
||||
|
||||
buf->idle += cpu_stat.cpu_sysinfo.cpu [CPU_IDLE];
|
||||
buf->user += cpu_stat.cpu_sysinfo.cpu [CPU_USER];
|
||||
buf->sys += cpu_stat.cpu_sysinfo.cpu [CPU_KERNEL];
|
||||
}
|
||||
|
||||
buf->total = buf->idle + buf->user + buf->sys;
|
||||
buf->frequency = server->_priv->machine.ticks;
|
||||
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
@@ -27,12 +29,12 @@
|
||||
BEGIN_LIBGTOP_DECLS
|
||||
|
||||
static inline void glibtop_suid_enter (glibtop *server) {
|
||||
setreuid (server->_priv->machine.uid, server->_priv->machine.euid);
|
||||
setreuid (server->_priv->machine.uid, server->_priv->machine.euid);
|
||||
};
|
||||
|
||||
static inline void glibtop_suid_leave (glibtop *server) {
|
||||
if (setreuid (server->_priv->machine.euid, server->_priv->machine.uid))
|
||||
_exit (1);
|
||||
if (setreuid (server->_priv->machine.euid, server->_priv->machine.uid))
|
||||
_exit (1);
|
||||
};
|
||||
|
||||
void
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
@@ -71,61 +73,61 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
|
||||
if(!kc)
|
||||
return -GLIBTOP_ERROR_INCOMPATIBLE_KERNEL;
|
||||
switch(kstat_chain_update(kc))
|
||||
{
|
||||
{
|
||||
case -1: assert(0); /* Debugging purposes, shouldn't happen */
|
||||
case 0: break;
|
||||
default: glibtop_get_kstats(server);
|
||||
}
|
||||
}
|
||||
|
||||
if((ksp = server->_priv->machine.syspages) && kstat_read(kc, ksp, NULL) >= 0)
|
||||
{
|
||||
kn = (kstat_named_t *)kstat_data_lookup(ksp, "pagesfree");
|
||||
if(kn)
|
||||
{
|
||||
kn = (kstat_named_t *)kstat_data_lookup(ksp, "pagesfree");
|
||||
if(kn)
|
||||
{
|
||||
#ifdef _LP64
|
||||
buf->free = kn->value.ui64 << pagesize << 10;
|
||||
buf->free = kn->value.ui64 << pagesize << 10;
|
||||
#else
|
||||
buf->free = kn->value.ui32 << pagesize << 10;
|
||||
buf->free = kn->value.ui32 << pagesize << 10;
|
||||
#endif
|
||||
buf->used = buf->total - buf->free;
|
||||
}
|
||||
kn = (kstat_named_t *)kstat_data_lookup(ksp, "pageslocked");
|
||||
if(kn)
|
||||
buf->used = buf->total - buf->free;
|
||||
}
|
||||
kn = (kstat_named_t *)kstat_data_lookup(ksp, "pageslocked");
|
||||
if(kn)
|
||||
#ifdef _LP64
|
||||
buf->locked = kn->value.ui64 << pagesize;
|
||||
buf->locked = kn->value.ui64 << pagesize;
|
||||
#else
|
||||
buf->locked = kn->value.ui32 << pagesize;
|
||||
#endif
|
||||
buf->flags += _glibtop_sysdeps_mem_os_kstat;
|
||||
}
|
||||
buf->flags += _glibtop_sysdeps_mem_os_kstat;
|
||||
}
|
||||
|
||||
/* Bunyip module provides data in multiples of system page size */
|
||||
|
||||
if((ksp = server->_priv->machine.bunyip) && kstat_read(kc, ksp, NULL) >= 0)
|
||||
{
|
||||
kn = (kstat_named_t *)kstat_data_lookup(ksp, "pages_anon");
|
||||
if(kn)
|
||||
{
|
||||
kn = (kstat_named_t *)kstat_data_lookup(ksp, "pages_anon");
|
||||
if(kn)
|
||||
#ifdef _LP64
|
||||
buf->user = kn->value.ui64 << pagesize << 10;
|
||||
buf->user = kn->value.ui64 << pagesize << 10;
|
||||
#else
|
||||
buf->user = kn->value.ui32 << pagesize << 10;
|
||||
#endif
|
||||
kn = (kstat_named_t *)kstat_data_lookup(ksp, "pages_exec");
|
||||
if(kn)
|
||||
kn = (kstat_named_t *)kstat_data_lookup(ksp, "pages_exec");
|
||||
if(kn)
|
||||
#ifdef _LP64
|
||||
buf->shared = kn->value.ui64 << pagesize << 10;
|
||||
buf->shared = kn->value.ui64 << pagesize << 10;
|
||||
#else
|
||||
buf->shared = kn->value.ui32 << pagesize << 10;
|
||||
#endif
|
||||
kn = (kstat_named_t *)kstat_data_lookup(ksp, "pages_vnode");
|
||||
if(kn)
|
||||
kn = (kstat_named_t *)kstat_data_lookup(ksp, "pages_vnode");
|
||||
if(kn)
|
||||
#ifdef _LP64
|
||||
buf->buffer = kn->value.ui64 << pagesize << 10;
|
||||
buf->buffer = kn->value.ui64 << pagesize << 10;
|
||||
#else
|
||||
buf->buffer = kn->value.ui32 << pagesize << 10;
|
||||
#endif
|
||||
buf->flags += _glibtop_sysdeps_mem_bunyip;
|
||||
}
|
||||
buf->flags += _glibtop_sysdeps_mem_bunyip;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
@@ -46,25 +48,25 @@ glibtop_get_kstats(glibtop *server)
|
||||
new_ncpu = sysconf(_SC_NPROCESSORS_CONF);
|
||||
|
||||
if(!kc)
|
||||
{
|
||||
server->ncpu = new_ncpu;
|
||||
server->_priv->machine.vminfo_kstat = NULL;
|
||||
server->_priv->machine.system = NULL;
|
||||
server->_priv->machine.syspages = NULL;
|
||||
server->_priv->machine.bunyip = NULL;
|
||||
return;
|
||||
}
|
||||
{
|
||||
server->ncpu = new_ncpu;
|
||||
server->_priv->machine.vminfo_kstat = NULL;
|
||||
server->_priv->machine.system = NULL;
|
||||
server->_priv->machine.syspages = NULL;
|
||||
server->_priv->machine.bunyip = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
ksp = kstat_lookup(kc, "unix", -1, "vminfo");
|
||||
server->_priv->machine.vminfo_kstat = ksp;
|
||||
if(ksp)
|
||||
{
|
||||
kstat_read(kc, ksp, &server->_priv->machine.vminfo);
|
||||
/* Don't change snaptime if we only need to reinitialize kstats */
|
||||
if(!(server->_priv->machine.vminfo_snaptime))
|
||||
server->_priv->machine.vminfo_snaptime = ksp->ks_snaptime;
|
||||
}
|
||||
{
|
||||
kstat_read(kc, ksp, &server->_priv->machine.vminfo);
|
||||
/* Don't change snaptime if we only need to reinitialize kstats */
|
||||
if(!(server->_priv->machine.vminfo_snaptime))
|
||||
server->_priv->machine.vminfo_snaptime = ksp->ks_snaptime;
|
||||
}
|
||||
|
||||
/* We don't know why was kstat chain invalidated. It could have
|
||||
been because the number of processors changed. The sysconf()
|
||||
@@ -73,45 +75,45 @@ glibtop_get_kstats(glibtop *server)
|
||||
the documentation. */
|
||||
|
||||
if((nproc_same = new_ncpu) == server->ncpu)
|
||||
{
|
||||
int checked, i;
|
||||
char cpu[20];
|
||||
|
||||
for(i = 0, checked = 0; i < GLIBTOP_NCPU || checked == new_ncpu; ++i)
|
||||
if(server->_priv->machine.cpu_stat_kstat[i])
|
||||
{
|
||||
sprintf(cpu, "cpu_stat%d", i);
|
||||
if(!(server->_priv->machine.cpu_stat_kstat[i] =
|
||||
kstat_lookup(kc, "cpu_stat", -1, cpu)))
|
||||
{
|
||||
nproc_same = 0;
|
||||
break;
|
||||
}
|
||||
++checked;
|
||||
}
|
||||
}
|
||||
if(!nproc_same)
|
||||
{
|
||||
processorid_t p;
|
||||
int found;
|
||||
char cpu[20];
|
||||
|
||||
if(new_ncpu > GLIBTOP_NCPU)
|
||||
new_ncpu = GLIBTOP_NCPU;
|
||||
server->ncpu = new_ncpu;
|
||||
for(p = 0, found = 0; p < GLIBTOP_NCPU && found != new_ncpu; ++p)
|
||||
{
|
||||
if(p_online(p, P_STATUS) < 0)
|
||||
{
|
||||
server->_priv->machine.cpu_stat_kstat[p] = NULL;
|
||||
continue;
|
||||
}
|
||||
sprintf(cpu, "cpu_stat%d", (int)p);
|
||||
server->_priv->machine.cpu_stat_kstat[p] =
|
||||
kstat_lookup(kc, "cpu_stat", -1, cpu);
|
||||
++found;
|
||||
int checked, i;
|
||||
char cpu[20];
|
||||
|
||||
for(i = 0, checked = 0; i < GLIBTOP_NCPU || checked == new_ncpu; ++i)
|
||||
if(server->_priv->machine.cpu_stat_kstat[i])
|
||||
{
|
||||
sprintf(cpu, "cpu_stat%d", i);
|
||||
if(!(server->_priv->machine.cpu_stat_kstat[i] =
|
||||
kstat_lookup(kc, "cpu_stat", -1, cpu)))
|
||||
{
|
||||
nproc_same = 0;
|
||||
break;
|
||||
}
|
||||
++checked;
|
||||
}
|
||||
}
|
||||
if(!nproc_same)
|
||||
{
|
||||
processorid_t p;
|
||||
int found;
|
||||
char cpu[20];
|
||||
|
||||
if(new_ncpu > GLIBTOP_NCPU)
|
||||
new_ncpu = GLIBTOP_NCPU;
|
||||
server->ncpu = new_ncpu;
|
||||
for(p = 0, found = 0; p < GLIBTOP_NCPU && found != new_ncpu; ++p)
|
||||
{
|
||||
if(p_online(p, P_STATUS) < 0)
|
||||
{
|
||||
server->_priv->machine.cpu_stat_kstat[p] = NULL;
|
||||
continue;
|
||||
}
|
||||
sprintf(cpu, "cpu_stat%d", (int)p);
|
||||
server->_priv->machine.cpu_stat_kstat[p] =
|
||||
kstat_lookup(kc, "cpu_stat", -1, cpu);
|
||||
++found;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
server->_priv->machine.system = kstat_lookup(kc, "unix", -1, "system_misc");
|
||||
server->_priv->machine.syspages = kstat_lookup(kc, "unix", -1, "system_pages");
|
||||
@@ -176,32 +178,32 @@ glibtop_open_s (glibtop *server, const char *program_name,
|
||||
|
||||
server->_priv->machine.boot = 0;
|
||||
if((ksp = server->_priv->machine.system) && kstat_read(kc, ksp, NULL) >= 0)
|
||||
{
|
||||
kn = (kstat_named_t *)kstat_data_lookup(ksp, "boot_time");
|
||||
if(kn)
|
||||
switch(kn->data_type)
|
||||
{
|
||||
{
|
||||
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->_priv->machine.boot = kn->value.i32;
|
||||
break;
|
||||
case KSTAT_DATA_UINT32: server->_priv->machine.boot = kn->value.ui32;
|
||||
break;
|
||||
case KSTAT_DATA_INT64: server->_priv->machine.boot = kn->value.i64;
|
||||
break;
|
||||
case KSTAT_DATA_UINT64: server->_priv->machine.boot = kn->value.ui64;
|
||||
break;
|
||||
case KSTAT_DATA_INT32: server->_priv->machine.boot = kn->value.i32;
|
||||
break;
|
||||
case KSTAT_DATA_UINT32: server->_priv->machine.boot = kn->value.ui32;
|
||||
break;
|
||||
case KSTAT_DATA_INT64: server->_priv->machine.boot = kn->value.i64;
|
||||
break;
|
||||
case KSTAT_DATA_UINT64: server->_priv->machine.boot = kn->value.ui64;
|
||||
break;
|
||||
#else
|
||||
case KSTAT_DATA_LONG: server->_priv->machine.boot = kn->value.l;
|
||||
break;
|
||||
case KSTAT_DATA_ULONG: server->_priv->machine.boot = kn->value.ul;
|
||||
break;
|
||||
case KSTAT_DATA_LONGLONG: server->_priv->machine.boot = kn->value.ll;
|
||||
break;
|
||||
case KSTAT_DATA_ULONGLONG: server->_priv->machine.boot = kn->value.ull;
|
||||
break;
|
||||
case KSTAT_DATA_LONG: server->_priv->machine.boot = kn->value.l;
|
||||
break;
|
||||
case KSTAT_DATA_ULONG: server->_priv->machine.boot = kn->value.ul;
|
||||
break;
|
||||
case KSTAT_DATA_LONGLONG: server->_priv->machine.boot = kn->value.ll;
|
||||
break;
|
||||
case KSTAT_DATA_ULONGLONG: server->_priv->machine.boot = kn->value.ull;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Now let's have a bit of magic dust... */
|
||||
|
||||
@@ -210,24 +212,24 @@ glibtop_open_s (glibtop *server, const char *program_name,
|
||||
dl = dlopen("/usr/lib/libproc.so", RTLD_LAZY);
|
||||
server->_priv->machine.libproc = dl;
|
||||
if(dl)
|
||||
{
|
||||
void *func;
|
||||
{
|
||||
void *func;
|
||||
|
||||
func = dlsym(dl, "Pobjname"); /* Solaris 8 */
|
||||
if(!func)
|
||||
func = dlsym(dl, "proc_objname"); /* Solaris 7 */
|
||||
server->_priv->machine.objname = (void (*)
|
||||
(void *, uintptr_t, const char *, size_t))func;
|
||||
server->_priv->machine.pgrab = (struct ps_prochandle *(*)(pid_t, int, int *))
|
||||
dlsym(dl, "Pgrab");
|
||||
server->_priv->machine.pfree = (void (*)(void *))dlsym(dl, "Pfree");
|
||||
}
|
||||
func = dlsym(dl, "Pobjname"); /* Solaris 8 */
|
||||
if(!func)
|
||||
func = dlsym(dl, "proc_objname"); /* Solaris 7 */
|
||||
server->_priv->machine.objname = (void (*)
|
||||
(void *, uintptr_t, const char *, size_t))func;
|
||||
server->_priv->machine.pgrab = (struct ps_prochandle *(*)(pid_t, int, int *))
|
||||
dlsym(dl, "Pgrab");
|
||||
server->_priv->machine.pfree = (void (*)(void *))dlsym(dl, "Pfree");
|
||||
}
|
||||
else
|
||||
{
|
||||
server->_priv->machine.objname = NULL;
|
||||
server->_priv->machine.pgrab = NULL;
|
||||
server->_priv->machine.pfree = NULL;
|
||||
}
|
||||
{
|
||||
server->_priv->machine.objname = NULL;
|
||||
server->_priv->machine.pgrab = NULL;
|
||||
server->_priv->machine.pfree = NULL;
|
||||
}
|
||||
#endif
|
||||
server->_priv->machine.me = getpid();
|
||||
}
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
@@ -35,21 +37,21 @@ void
|
||||
glibtop_init_p (glibtop *server, const unsigned long features,
|
||||
const unsigned flags)
|
||||
{
|
||||
glibtop_init_func_t *init_fkt;
|
||||
glibtop_init_func_t *init_fkt;
|
||||
|
||||
if (server == NULL)
|
||||
glibtop_error_r (NULL, "glibtop_init_p (server == NULL)");
|
||||
if (server == NULL)
|
||||
glibtop_error_r (NULL, "glibtop_init_p (server == NULL)");
|
||||
|
||||
/* Do the initialization, but only if not already initialized. */
|
||||
/* Do the initialization, but only if not already initialized. */
|
||||
|
||||
if ((server->flags & _GLIBTOP_INIT_STATE_INIT) == 0) {
|
||||
glibtop_open_p (server, "glibtop", features, flags);
|
||||
if ((server->flags & _GLIBTOP_INIT_STATE_INIT) == 0) {
|
||||
glibtop_open_p (server, "glibtop", features, flags);
|
||||
|
||||
for (init_fkt = _glibtop_init_hook_p; *init_fkt; init_fkt++)
|
||||
(*init_fkt) (server);
|
||||
for (init_fkt = _glibtop_init_hook_p; *init_fkt; init_fkt++)
|
||||
(*init_fkt) (server);
|
||||
|
||||
server->flags |= _GLIBTOP_INIT_STATE_INIT;
|
||||
}
|
||||
server->flags |= _GLIBTOP_INIT_STATE_INIT;
|
||||
}
|
||||
}
|
||||
|
||||
/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
|
||||
@@ -58,18 +60,18 @@ void
|
||||
glibtop_open_p (glibtop *server, const char *program_name,
|
||||
const unsigned long features, const unsigned flags)
|
||||
{
|
||||
/* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
|
||||
/* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
|
||||
|
||||
server->name = program_name;
|
||||
server->name = program_name;
|
||||
|
||||
server->_priv->machine.uid = getuid ();
|
||||
server->_priv->machine.euid = geteuid ();
|
||||
server->_priv->machine.gid = getgid ();
|
||||
server->_priv->machine.egid = getegid ();
|
||||
server->_priv->machine.uid = getuid ();
|
||||
server->_priv->machine.euid = geteuid ();
|
||||
server->_priv->machine.gid = getgid ();
|
||||
server->_priv->machine.egid = getegid ();
|
||||
|
||||
server->_priv->machine.kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL);
|
||||
if(!server->_priv->machine.kd)
|
||||
glibtop_warn_io_r(server, "kvm_open()");
|
||||
server->_priv->machine.kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL);
|
||||
if(!server->_priv->machine.kd)
|
||||
glibtop_warn_io_r(server, "kvm_open()");
|
||||
|
||||
/* Drop priviledges; we only become root when necessary.
|
||||
|
||||
@@ -78,15 +80,15 @@ glibtop_open_p (glibtop *server, const char *program_name,
|
||||
|
||||
*/
|
||||
|
||||
if (setreuid (server->_priv->machine.euid, server->_priv->machine.uid))
|
||||
_exit (1);
|
||||
if (setreuid (server->_priv->machine.euid, server->_priv->machine.uid))
|
||||
_exit (1);
|
||||
|
||||
if (setregid (server->_priv->machine.egid, server->_priv->machine.gid))
|
||||
_exit (1);
|
||||
if (setregid (server->_priv->machine.egid, server->_priv->machine.gid))
|
||||
_exit (1);
|
||||
|
||||
/* !!! END OF SUID ROOT PART !!! */
|
||||
/* !!! END OF SUID ROOT PART !!! */
|
||||
|
||||
/* Our effective uid is now those of the user invoking the server,
|
||||
so we do no longer have any priviledges.
|
||||
*/
|
||||
/* Our effective uid is now those of the user invoking the server,
|
||||
so we do no longer have any priviledges.
|
||||
*/
|
||||
}
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
@@ -49,51 +51,51 @@
|
||||
int
|
||||
glibtop_get_proc_data_psinfo_s (glibtop *server, struct psinfo *psinfo, pid_t pid)
|
||||
{
|
||||
int fd;
|
||||
char buffer [BUFSIZ];
|
||||
int fd;
|
||||
char buffer [BUFSIZ];
|
||||
|
||||
sprintf (buffer, "/proc/%d/psinfo", (int) pid);
|
||||
fd = s_open (buffer, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
glibtop_warn_io_r (server, "open (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
sprintf (buffer, "/proc/%d/psinfo", (int) pid);
|
||||
fd = s_open (buffer, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
glibtop_warn_io_r (server, "open (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (s_pread (fd, psinfo, sizeof (struct psinfo), 0) !=
|
||||
sizeof (struct psinfo))
|
||||
if (s_pread (fd, psinfo, sizeof (struct psinfo), 0) !=
|
||||
sizeof (struct psinfo))
|
||||
{
|
||||
s_close (fd);
|
||||
glibtop_warn_io_r (server, "pread (%s)", buffer);
|
||||
return -1;
|
||||
s_close (fd);
|
||||
glibtop_warn_io_r (server, "pread (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
s_close (fd);
|
||||
return 0;
|
||||
s_close (fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
glibtop_get_proc_data_usage_s (glibtop *server, struct prusage *prusage, pid_t pid)
|
||||
{
|
||||
int fd;
|
||||
char buffer [BUFSIZ];
|
||||
int fd;
|
||||
char buffer [BUFSIZ];
|
||||
|
||||
sprintf (buffer, "/proc/%d/usage", (int) pid);
|
||||
fd = s_open (buffer, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
glibtop_warn_io_r (server, "open (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
sprintf (buffer, "/proc/%d/usage", (int) pid);
|
||||
fd = s_open (buffer, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
glibtop_warn_io_r (server, "open (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (s_pread (fd, prusage, sizeof (struct prusage), 0) !=
|
||||
sizeof (struct prusage))
|
||||
if (s_pread (fd, prusage, sizeof (struct prusage), 0) !=
|
||||
sizeof (struct prusage))
|
||||
{
|
||||
s_close (fd);
|
||||
glibtop_warn_io_r (server, "pread (%s)", buffer);
|
||||
return -1;
|
||||
s_close (fd);
|
||||
glibtop_warn_io_r (server, "pread (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
s_close (fd);
|
||||
return 0;
|
||||
s_close (fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -102,25 +104,25 @@ glibtop_get_proc_credentials_s(glibtop *server,
|
||||
gid_t *groups,
|
||||
pid_t pid)
|
||||
{
|
||||
int fd;
|
||||
size_t toread;
|
||||
char buffer[BUFSIZ];
|
||||
int fd;
|
||||
size_t toread;
|
||||
char buffer[BUFSIZ];
|
||||
|
||||
sprintf(buffer, "/proc/%d/cred", (int)pid);
|
||||
if((fd = s_open(buffer, O_RDONLY)) < 0)
|
||||
sprintf(buffer, "/proc/%d/cred", (int)pid);
|
||||
if((fd = s_open(buffer, O_RDONLY)) < 0)
|
||||
{
|
||||
if(errno != EPERM && errno != EACCES)
|
||||
glibtop_warn_io_r(server, "open (%s)", buffer);
|
||||
return -1;
|
||||
if(errno != EPERM && errno != EACCES)
|
||||
glibtop_warn_io_r(server, "open (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
if(s_pread(fd, prcred, sizeof(struct prcred), 0) !=
|
||||
sizeof(struct prcred))
|
||||
if(s_pread(fd, prcred, sizeof(struct prcred), 0) !=
|
||||
sizeof(struct prcred))
|
||||
{
|
||||
s_close(fd);
|
||||
glibtop_warn_io_r(server, "pread (%s)", buffer);
|
||||
return -1;
|
||||
s_close(fd);
|
||||
glibtop_warn_io_r(server, "pread (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
if(prcred->pr_ngroups >= 0)
|
||||
if(prcred->pr_ngroups >= 0)
|
||||
{
|
||||
if(prcred->pr_ngroups <= GLIBTOP_MAX_GROUPS)
|
||||
toread = prcred->pr_ngroups * sizeof(gid_t);
|
||||
@@ -128,34 +130,34 @@ glibtop_get_proc_credentials_s(glibtop *server,
|
||||
toread = GLIBTOP_MAX_GROUPS * sizeof(gid_t);
|
||||
if(s_pread(fd, groups, toread,
|
||||
(off_t)&(((struct prcred *)0)->pr_groups[0])) != toread)
|
||||
prcred->pr_ngroups = 0;
|
||||
prcred->pr_ngroups = 0;
|
||||
}
|
||||
s_close(fd);
|
||||
return 0;
|
||||
s_close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
glibtop_get_proc_status_s(glibtop *server, struct pstatus *pstatus, pid_t pid)
|
||||
{
|
||||
int fd;
|
||||
char buffer[BUFSIZ];
|
||||
int fd;
|
||||
char buffer[BUFSIZ];
|
||||
|
||||
sprintf(buffer, "/proc/%d/status", (int)pid);
|
||||
if((fd = s_open(buffer, O_RDONLY)) < 0)
|
||||
sprintf(buffer, "/proc/%d/status", (int)pid);
|
||||
if((fd = s_open(buffer, O_RDONLY)) < 0)
|
||||
{
|
||||
if(errno != EPERM && errno != EACCES)
|
||||
glibtop_warn_io_r(server, "open (%s)", buffer);
|
||||
return -1;
|
||||
if(errno != EPERM && errno != EACCES)
|
||||
glibtop_warn_io_r(server, "open (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
if(s_pread(fd, pstatus, sizeof(struct pstatus), 0) !=
|
||||
sizeof(struct pstatus))
|
||||
if(s_pread(fd, pstatus, sizeof(struct pstatus), 0) !=
|
||||
sizeof(struct pstatus))
|
||||
{
|
||||
s_close(fd);
|
||||
glibtop_warn_io_r(server, "pread (%s)", buffer);
|
||||
return -1;
|
||||
s_close(fd);
|
||||
glibtop_warn_io_r(server, "pread (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
s_close(fd);
|
||||
return 0;
|
||||
s_close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else /* old API */
|
||||
@@ -165,26 +167,26 @@ glibtop_get_proc_data_psinfo_s (glibtop *server,
|
||||
struct prpsinfo *psinfo,
|
||||
pid_t pid)
|
||||
{
|
||||
int fd;
|
||||
char buffer [BUFSIZ];
|
||||
int fd;
|
||||
char buffer [BUFSIZ];
|
||||
|
||||
sprintf (buffer, "/proc/%d", (int) pid);
|
||||
fd = s_open (buffer, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
if(errno != EPERM && errno != EACCES)
|
||||
glibtop_warn_io_r (server, "open (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
sprintf (buffer, "/proc/%d", (int) pid);
|
||||
fd = s_open (buffer, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
if(errno != EPERM && errno != EACCES)
|
||||
glibtop_warn_io_r (server, "open (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(ioctl(fd, PIOCPSINFO, psinfo) < 0)
|
||||
if(ioctl(fd, PIOCPSINFO, psinfo) < 0)
|
||||
{
|
||||
s_close (fd);
|
||||
glibtop_warn_io_r (server, "ioctl(%s, PIOCPSINFO)", buffer);
|
||||
return -1;
|
||||
s_close (fd);
|
||||
glibtop_warn_io_r (server, "ioctl(%s, PIOCPSINFO)", buffer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
s_close (fd);
|
||||
return 0;
|
||||
s_close (fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -192,26 +194,26 @@ glibtop_get_proc_data_usage_s (glibtop *server,
|
||||
struct prusage *prusage,
|
||||
pid_t pid)
|
||||
{
|
||||
int fd;
|
||||
char buffer [BUFSIZ];
|
||||
int fd;
|
||||
char buffer [BUFSIZ];
|
||||
|
||||
sprintf (buffer, "/proc/%d", (int) pid);
|
||||
fd = s_open (buffer, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
if(errno != EPERM && errno != EACCES)
|
||||
glibtop_warn_io_r (server, "open (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
sprintf (buffer, "/proc/%d", (int) pid);
|
||||
fd = s_open (buffer, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
if(errno != EPERM && errno != EACCES)
|
||||
glibtop_warn_io_r (server, "open (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(ioctl(fd, PIOCUSAGE, prusage) < 0)
|
||||
if(ioctl(fd, PIOCUSAGE, prusage) < 0)
|
||||
{
|
||||
s_close (fd);
|
||||
glibtop_warn_io_r (server, "ioctl(%s, PIOCUSAGE)", buffer);
|
||||
return -1;
|
||||
s_close (fd);
|
||||
glibtop_warn_io_r (server, "ioctl(%s, PIOCUSAGE)", buffer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
s_close (fd);
|
||||
return 0;
|
||||
s_close (fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -220,47 +222,47 @@ glibtop_get_proc_credentials_s(glibtop *server,
|
||||
gid_t *groups,
|
||||
pid_t pid)
|
||||
{
|
||||
int fd;
|
||||
size_t toread;
|
||||
char buffer[BUFSIZ];
|
||||
int fd;
|
||||
size_t toread;
|
||||
char buffer[BUFSIZ];
|
||||
|
||||
sprintf(buffer, "/proc/%d", (int)pid);
|
||||
if((fd = s_open(buffer, O_RDONLY)) < 0)
|
||||
sprintf(buffer, "/proc/%d", (int)pid);
|
||||
if((fd = s_open(buffer, O_RDONLY)) < 0)
|
||||
{
|
||||
if(errno != EPERM && errno != EACCES)
|
||||
glibtop_warn_io_r(server, "open (%s)", buffer);
|
||||
return -1;
|
||||
if(errno != EPERM && errno != EACCES)
|
||||
glibtop_warn_io_r(server, "open (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
if(ioctl(fd, PIOCCRED, prcred) < 0)
|
||||
if(ioctl(fd, PIOCCRED, prcred) < 0)
|
||||
{
|
||||
s_close(fd);
|
||||
glibtop_warn_io_r(server, "ioctl(%s, PIOCCRED)", buffer);
|
||||
return -1;
|
||||
s_close(fd);
|
||||
glibtop_warn_io_r(server, "ioctl(%s, PIOCCRED)", buffer);
|
||||
return -1;
|
||||
}
|
||||
s_close(fd);
|
||||
return 0;
|
||||
s_close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
glibtop_get_proc_status_s(glibtop *server, struct prstatus *pstatus, pid_t pid)
|
||||
{
|
||||
int fd;
|
||||
char buffer[BUFSIZ];
|
||||
int fd;
|
||||
char buffer[BUFSIZ];
|
||||
|
||||
sprintf(buffer, "/proc/%d", (int)pid);
|
||||
if((fd = s_open(buffer, O_RDONLY)) < 0)
|
||||
sprintf(buffer, "/proc/%d", (int)pid);
|
||||
if((fd = s_open(buffer, O_RDONLY)) < 0)
|
||||
{
|
||||
if(errno != EPERM && errno != EACCES)
|
||||
glibtop_warn_io_r(server, "open (%s)", buffer);
|
||||
return -1;
|
||||
if(errno != EPERM && errno != EACCES)
|
||||
glibtop_warn_io_r(server, "open (%s)", buffer);
|
||||
return -1;
|
||||
}
|
||||
if(ioctl(fd, PIOCSTATUS, pstatus) < 0)
|
||||
if(ioctl(fd, PIOCSTATUS, pstatus) < 0)
|
||||
{
|
||||
s_close(fd);
|
||||
glibtop_warn_io_r(server, "ioctl(%s, PIOCSTATUS)", buffer);
|
||||
return -1;
|
||||
s_close(fd);
|
||||
glibtop_warn_io_r(server, "ioctl(%s, PIOCSTATUS)", buffer);
|
||||
return -1;
|
||||
}
|
||||
s_close(fd);
|
||||
return 0;
|
||||
s_close(fd);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* Copyright (C) 1999 Drazen Kacar
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
@@ -62,11 +64,11 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
|
||||
return -GLIBTOP_ERROR_INCOMPATIBLE_KERNEL;
|
||||
|
||||
switch(kstat_chain_update(kc))
|
||||
{
|
||||
{
|
||||
case -1: assert(0); /* Debugging, shouldn't happen */
|
||||
case 0: break;
|
||||
default: glibtop_get_kstats(server);
|
||||
}
|
||||
}
|
||||
ret = kstat_read (kc, ksp, &vminfo);
|
||||
|
||||
if (ret == -1) {
|
||||
|
@@ -1,3 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
|
Reference in New Issue
Block a user