New file.
1998-07-21 Martin Baulig <martin@home-of-linux.org> * doc/ChangeLog: New file. * sysdeps/kernel/*.c: Using `glibtop_error_io_r' instead of `glibtop_error_r'. * sysdeps/kernel/proclist.c: Now using the table () function, too. This means that currently the table () function can fetch all information for libgtop and you can even unmount /proc !
This commit is contained in:
committed by
Martin Baulig
parent
5a1fa089f3
commit
7efcda3082
11
ChangeLog
11
ChangeLog
@@ -1,3 +1,14 @@
|
||||
1998-07-21 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* doc/ChangeLog: New file.
|
||||
|
||||
* sysdeps/kernel/*.c: Using `glibtop_error_io_r' instead
|
||||
of `glibtop_error_r'.
|
||||
|
||||
* sysdeps/kernel/proclist.c: Now using the table () function, too.
|
||||
This means that currently the table () function can fetch all
|
||||
information for libgtop and you can even unmount /proc !
|
||||
|
||||
1998-07-18 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* lib/{init, open}.c: Added `GLIBTOP_METHOD_PIPE' again.
|
||||
|
@@ -16,8 +16,8 @@ libgtop_sysdeps_la_SOURCES = init.c open.c close.c kernel.s cpu.c mem.c swap.c \
|
||||
|
||||
include_HEADERS = glibtop_server.h
|
||||
|
||||
kernel.o kernel.lo: kernel.s
|
||||
kernel.o kernel.lo: $(srcdir)/kernel.s
|
||||
rm -f kernel.o kernel.lo
|
||||
$(AS) -o kernel.o kernel.s
|
||||
$(AS) -o kernel.o $(srcdir)/kernel.s
|
||||
cp kernel.o kernel.lo
|
||||
|
||||
|
@@ -42,7 +42,7 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
||||
memset (buf, 0, sizeof (glibtop_cpu));
|
||||
|
||||
if (table (TABLE_CPU, &tbl, NULL))
|
||||
glibtop_error_r (server, "table(TABLE_CPU): %s\n", strerror (errno));
|
||||
glibtop_error_io_r (server, "table(TABLE_CPU)");
|
||||
|
||||
buf->flags = _glibtop_sysdeps_cpu;
|
||||
|
||||
|
@@ -19,7 +19,7 @@ gcc2_compiled.:
|
||||
table:
|
||||
pushl %ebp
|
||||
movl %esp,%ebp
|
||||
movl $168,%eax
|
||||
movl $188,%eax
|
||||
pushl %ebx
|
||||
movl 8(%ebp),%ebx
|
||||
movl 12(%ebp),%ecx
|
||||
|
@@ -40,17 +40,10 @@ glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
|
||||
memset (buf, 0, sizeof (glibtop_loadavg));
|
||||
|
||||
if (table (TABLE_LOADAVG, &tbl, NULL))
|
||||
glibtop_error_r (server, "table(TABLE_LOADAVG): %s\n", strerror (errno));
|
||||
glibtop_error_io_r (server, "table(TABLE_LOADAVG)");
|
||||
|
||||
buf->flags = _glibtop_sysdeps_loadavg;
|
||||
|
||||
#if 0
|
||||
fprintf (stderr, "Table (%u) = (%lu, %lu, %lu) - %u, %u, %u\n",
|
||||
TABLE_LOADAVG, tbl.loadavg.loadavg [0], tbl.loadavg.loadavg [1],
|
||||
tbl.loadavg.loadavg [2], tbl.loadavg.nr_running,
|
||||
tbl.loadavg.nr_tasks, tbl.loadavg.last_pid);
|
||||
#endif
|
||||
|
||||
buf->loadavg [0] = tbl.loadavg.loadavg [0];
|
||||
buf->loadavg [1] = tbl.loadavg.loadavg [1];
|
||||
buf->loadavg [2] = tbl.loadavg.loadavg [2];
|
||||
|
@@ -43,7 +43,7 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
|
||||
memset (buf, 0, sizeof (glibtop_mem));
|
||||
|
||||
if (table (TABLE_MEM, &tbl, NULL))
|
||||
glibtop_error_r (server, "table(TABLE_MEM): %s\n", strerror (errno));
|
||||
glibtop_error_io_r (server, "table(TABLE_MEM)");
|
||||
|
||||
buf->flags = _glibtop_sysdeps_mem;
|
||||
|
||||
|
@@ -54,7 +54,6 @@ void
|
||||
glibtop_open_r (glibtop *server, const char *program_name,
|
||||
const unsigned long features, const unsigned flags)
|
||||
{
|
||||
memset (server, 0, sizeof (glibtop));
|
||||
server->name = program_name;
|
||||
|
||||
set_linux_version ();
|
||||
|
@@ -34,7 +34,8 @@ static const unsigned long _glibtop_sysdeps_proc_kernel =
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid)
|
||||
glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
union table tbl;
|
||||
|
||||
@@ -49,7 +50,7 @@ glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid)
|
||||
}
|
||||
|
||||
if (table (TABLE_PROC_KERNEL, &tbl, &pid))
|
||||
glibtop_error_r (server, "table(TABLE_PROC_KERNEL): %s\n", strerror (errno));
|
||||
glibtop_error_io_r (server, "table(TABLE_PROC_KERNEL)");
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_kernel;
|
||||
|
||||
|
@@ -19,14 +19,11 @@
|
||||
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA. */
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/xmalloc.h>
|
||||
#include <glibtop/proclist.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
#include "kernel.h"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proclist =
|
||||
(1 << GLIBTOP_PROCLIST_TOTAL) + (1 << GLIBTOP_PROCLIST_NUMBER) +
|
||||
@@ -51,105 +48,24 @@ static const unsigned long _glibtop_sysdeps_proclist =
|
||||
unsigned *
|
||||
glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf)
|
||||
{
|
||||
DIR *proc;
|
||||
struct dirent *entry;
|
||||
char buffer [BUFSIZ];
|
||||
unsigned count, total, pid;
|
||||
unsigned pids [BLOCK_COUNT], *pids_chain = NULL;
|
||||
unsigned pids_size = 0, pids_offset = 0, new_size;
|
||||
struct stat statb;
|
||||
int len, i, ok;
|
||||
union table tbl;
|
||||
unsigned *pids_chain;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proclist));
|
||||
|
||||
proc = opendir ("/proc");
|
||||
if (!proc) return NULL;
|
||||
|
||||
/* read every every entry in /proc */
|
||||
|
||||
for (count = total = 0, entry = readdir (proc); entry; entry = readdir (proc)) {
|
||||
ok = 1; len = strlen (entry->d_name);
|
||||
|
||||
/* does it consist entirely of digits? */
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
if (!isdigit (entry->d_name [i])) ok = 0;
|
||||
if (!ok) continue;
|
||||
|
||||
/* convert it in a number */
|
||||
|
||||
if (sscanf (entry->d_name, "%u", &pid) != 1) continue;
|
||||
|
||||
/* is it really a directory? */
|
||||
|
||||
sprintf (buffer, "/proc/%d", pid);
|
||||
|
||||
if (stat (buffer, &statb)) continue;
|
||||
|
||||
if (!S_ISDIR (statb.st_mode)) continue;
|
||||
|
||||
/* Fine. Now we first try to store it in pids. If this buffer is
|
||||
* full, we copy it to the pids_chain. */
|
||||
|
||||
if (count >= BLOCK_COUNT) {
|
||||
/* The following call to glibtop_realloc will be equivalent to
|
||||
* glibtop_malloc if pids_chain is NULL. We just calculate the
|
||||
* new size and copy pids to the beginning of the newly allocated
|
||||
* block. */
|
||||
|
||||
new_size = pids_size + BLOCK_SIZE;
|
||||
|
||||
pids_chain = glibtop_realloc_r (server, pids_chain, new_size);
|
||||
|
||||
memcpy (pids_chain + pids_offset, pids, BLOCK_SIZE);
|
||||
|
||||
pids_size = new_size;
|
||||
|
||||
pids_offset += BLOCK_COUNT;
|
||||
|
||||
count = 0;
|
||||
}
|
||||
|
||||
/* pids is now big enough to hold at least one single pid. */
|
||||
|
||||
pids [count++] = pid;
|
||||
|
||||
total++;
|
||||
}
|
||||
|
||||
closedir (proc);
|
||||
|
||||
/* count is only zero if an error occured (one a running Linux system, we
|
||||
* only have at least one single process). */
|
||||
|
||||
if (!count) return NULL;
|
||||
|
||||
/* The following call to glibtop_realloc will be equivalent to
|
||||
* glibtop_malloc if pids_chain is NULL. We just calculate the
|
||||
* new size and copy pids to the beginning of the newly allocated
|
||||
* block. */
|
||||
|
||||
new_size = pids_size + count * sizeof (unsigned);
|
||||
|
||||
pids_chain = glibtop_realloc_r (server, pids_chain, new_size);
|
||||
|
||||
memcpy (pids_chain + pids_offset, pids, count * sizeof (unsigned));
|
||||
|
||||
pids_size = new_size;
|
||||
|
||||
pids_offset += BLOCK_COUNT;
|
||||
|
||||
/* Since everything is ok now, we can set buf->flags, fill in the remaining fields
|
||||
and return pids_chain. */
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proclist;
|
||||
if (table (TABLE_PROCLIST, &tbl, NULL))
|
||||
glibtop_error_io_r (server, "table(TABLE_PROCLIST)");
|
||||
|
||||
buf->size = sizeof (unsigned);
|
||||
buf->number = total;
|
||||
buf->number = tbl.proclist.nr_tasks;
|
||||
|
||||
buf->total = total * sizeof (unsigned);
|
||||
buf->total = buf->number * sizeof (unsigned);
|
||||
|
||||
pids_chain = glibtop_malloc_r (server, buf->total);
|
||||
|
||||
memcpy (pids_chain, tbl.proclist.pids, buf->total);
|
||||
|
||||
return pids_chain;
|
||||
}
|
||||
|
@@ -33,7 +33,8 @@ static const unsigned long _glibtop_sysdeps_proc_mem =
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
|
||||
glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
union table tbl;
|
||||
|
||||
@@ -48,13 +49,13 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
|
||||
}
|
||||
|
||||
if (table (TABLE_PROC_MEM, &tbl, &pid))
|
||||
glibtop_error_r (server, "table(TABLE_PROC_MEM): %s\n", strerror (errno));
|
||||
glibtop_error_io_r (server, "table(TABLE_PROC_MEM)");
|
||||
|
||||
buf->rss = tbl.proc_mem.rss;
|
||||
buf->rss_rlim = tbl.proc_mem.rlim;
|
||||
|
||||
if (table (TABLE_PROC_SEGMENT, &tbl, &pid))
|
||||
glibtop_error_r (server, "table(TABLE_PROC_SEGMENT): %s\n", strerror (errno));
|
||||
glibtop_error_io_r (server, "table(TABLE_PROC_SEGMENT)");
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_mem;
|
||||
|
||||
|
@@ -50,14 +50,14 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
|
||||
}
|
||||
|
||||
if (table (TABLE_PROC_MEM, &tbl, &pid))
|
||||
glibtop_error_r (server, "table(TABLE_PROC_MEM): %s\n", strerror (errno));
|
||||
glibtop_error_io_r (server, "table(TABLE_PROC_MEM)");
|
||||
|
||||
buf->start_code = tbl.proc_mem.start_code;
|
||||
buf->end_code = tbl.proc_mem.end_code;
|
||||
buf->start_stack = tbl.proc_mem.start_stack;
|
||||
|
||||
if (table (TABLE_PROC_SEGMENT, &tbl, &pid))
|
||||
glibtop_error_r (server, "table(TABLE_PROC_SEGMENT): %s\n", strerror (errno));
|
||||
glibtop_error_io_r (server, "table(TABLE_PROC_SEGMENT)");
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_segment;
|
||||
|
||||
|
@@ -32,7 +32,8 @@ static const unsigned long _glibtop_sysdeps_proc_signal =
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid)
|
||||
glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
union table tbl;
|
||||
|
||||
@@ -47,13 +48,12 @@ glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid)
|
||||
}
|
||||
|
||||
if (table (TABLE_PROC_SIGNAL, &tbl, &pid))
|
||||
glibtop_error_r (server, "table(TABLE_PROC_SIGNAL): %s\n", strerror (errno));
|
||||
glibtop_error_io_r (server, "table(TABLE_PROC_SIGNAL)");
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_signal;
|
||||
|
||||
buf->signal = tbl.proc_signal.signal;
|
||||
buf->blocked = tbl.proc_signal.blocked;
|
||||
buf->sigignore = tbl.proc_signal.ignored;
|
||||
buf->sigcatch = tbl.proc_signal.caught;
|
||||
|
||||
buf->signal = tbl.proc_signal.signal.__val [0];
|
||||
buf->blocked = tbl.proc_signal.blocked.__val [0];
|
||||
buf->sigignore = tbl.proc_signal.ignored.__val [0];
|
||||
buf->sigcatch = tbl.proc_signal.caught.__val [0];
|
||||
}
|
||||
|
@@ -33,10 +33,12 @@ static const unsigned long _glibtop_sysdeps_proc_state =
|
||||
#define NR_STATES 7
|
||||
|
||||
void
|
||||
glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
|
||||
glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
union table tbl;
|
||||
static const char states [NR_STATES] = { 'R', 'S', 'D', 'Z', 'T', 'W', '.' };
|
||||
static const char states [NR_STATES] =
|
||||
{ 'R', 'S', 'D', 'Z', 'T', 'W', '.' };
|
||||
unsigned state;
|
||||
|
||||
glibtop_init_r (&server, 0, 0);
|
||||
@@ -50,7 +52,7 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
|
||||
}
|
||||
|
||||
if (table (TABLE_PROC_STATE, &tbl, &pid))
|
||||
glibtop_error_r (server, "table(TABLE_PROC_STATE): %s\n", strerror (errno));
|
||||
glibtop_error_io_r (server, "table(TABLE_PROC_STATE)");
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_state;
|
||||
|
||||
|
@@ -34,7 +34,8 @@ static const unsigned long _glibtop_sysdeps_proc_time =
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
|
||||
glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
union table tbl;
|
||||
|
||||
@@ -49,7 +50,7 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
|
||||
}
|
||||
|
||||
if (table (TABLE_PROC_TIME, &tbl, &pid))
|
||||
glibtop_error_r (server, "table(TABLE_PROC_TIME): %s\n", strerror (errno));
|
||||
glibtop_error_io_r (server, "table(TABLE_PROC_TIME)");
|
||||
|
||||
buf->utime = tbl.proc_time.utime;
|
||||
buf->stime = tbl.proc_time.stime;
|
||||
|
@@ -38,7 +38,8 @@ static const unsigned long _glibtop_sysdeps_proc_uid =
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
|
||||
glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
union table tbl;
|
||||
long def_priority, priority, nice;
|
||||
@@ -54,7 +55,7 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
|
||||
}
|
||||
|
||||
if (table (TABLE_PROC_UID, &tbl, &pid))
|
||||
glibtop_error_r (server, "table(TABLE_PROC_UID): %s\n", strerror (errno));
|
||||
glibtop_error_io_r (server, "table(TABLE_PROC_UID)");
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_uid;
|
||||
|
||||
|
@@ -41,7 +41,7 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
|
||||
memset (buf, 0, sizeof (glibtop_swap));
|
||||
|
||||
if (table (TABLE_SWAP, &tbl, NULL))
|
||||
glibtop_error_r (server, "table(TABLE_SWAP): %s\n", strerror (errno));
|
||||
glibtop_error_io_r (server, "table(TABLE_SWAP)");
|
||||
|
||||
buf->flags = _glibtop_sysdeps_swap;
|
||||
|
||||
|
@@ -40,7 +40,7 @@ glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
|
||||
memset (buf, 0, sizeof (glibtop_uptime));
|
||||
|
||||
if (table (TABLE_UPTIME, &tbl, NULL))
|
||||
glibtop_error_r (server, "table(TABLE_UPTIME): %s\n", strerror (errno));
|
||||
glibtop_error_io_r (server, "table(TABLE_UPTIME)");
|
||||
|
||||
buf->flags = _glibtop_sysdeps_uptime;
|
||||
|
||||
|
Reference in New Issue
Block a user