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:
Martin Baulig
1999-12-26 14:05:32 +00:00
parent d7f088bef0
commit f1a6e1ead8
272 changed files with 6300 additions and 5751 deletions

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -40,12 +42,12 @@ static const unsigned long _glibtop_sysdeps_cpu_smp =
int
glibtop_init_cpu_s (glibtop *server)
{
server->sysdeps.cpu = _glibtop_sysdeps_cpu;
server->sysdeps.cpu = _glibtop_sysdeps_cpu;
if (server->ncpu)
server->sysdeps.cpu |= _glibtop_sysdeps_cpu_smp;
if (server->ncpu)
server->sysdeps.cpu |= _glibtop_sysdeps_cpu_smp;
return 0;
return 0;
}
/* Provides information about cpu usage. */
@@ -55,69 +57,69 @@ glibtop_init_cpu_s (glibtop *server)
int
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
{
char buffer [BUFSIZ], *p;
int fd, len, i;
u_int64_t total;
char buffer [BUFSIZ], *p;
int fd, len, i;
u_int64_t total;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
memset (buf, 0, sizeof (glibtop_cpu));
memset (buf, 0, sizeof (glibtop_cpu));
fd = open (FILENAME, O_RDONLY);
if (fd < 0) {
glibtop_warn_io_r (server, "open (%s)", FILENAME);
return -1;
}
len = read (fd, buffer, BUFSIZ-1);
if (len < 0) {
close (fd);
glibtop_warn_io_r (server, "read (%s)", FILENAME);
return -1;
}
fd = open (FILENAME, O_RDONLY);
if (fd < 0) {
glibtop_warn_io_r (server, "open (%s)", FILENAME);
return -1;
}
len = read (fd, buffer, BUFSIZ-1);
if (len < 0) {
close (fd);
glibtop_warn_io_r (server, "read (%s)", FILENAME);
return -1;
}
buffer [len] = '\0';
close (fd);
p = skip_token (buffer); /* "cpu" */
buffer [len] = '\0';
buf->user = strtoul (p, &p, 0);
buf->nice = strtoul (p, &p, 0);
buf->sys = strtoul (p, &p, 0);
buf->idle = strtoul (p, &p, 0);
p = skip_token (buffer); /* "cpu" */
total = buf->user;
total += buf->nice;
total += buf->sys;
total += buf->idle;
buf->total = total;
buf->user = strtoul (p, &p, 0);
buf->nice = strtoul (p, &p, 0);
buf->sys = strtoul (p, &p, 0);
buf->idle = strtoul (p, &p, 0);
buf->frequency = 100;
buf->flags = _glibtop_sysdeps_cpu;
total = buf->user;
total += buf->nice;
total += buf->sys;
total += buf->idle;
buf->total = total;
for (i = 0; i < server->ncpu; i++) {
if (strncmp (p+1, "cpu", 3) || !isdigit (p [4]))
break;
buf->frequency = 100;
buf->flags = _glibtop_sysdeps_cpu;
buf->xcpu_flags |= (1L << (u_int64_t) i);
for (i = 0; i < server->ncpu; i++) {
if (strncmp (p+1, "cpu", 3) || !isdigit (p [4]))
break;
p += 6;
buf->xcpu_user [i] = strtoul (p, &p, 0);
buf->xcpu_nice [i] = strtoul (p, &p, 0);
buf->xcpu_sys [i] = strtoul (p, &p, 0);
buf->xcpu_idle [i] = strtoul (p, &p, 0);
buf->xcpu_flags |= (1L << (u_int64_t) i);
total = buf->xcpu_user [i];
total += buf->xcpu_nice [i];
total += buf->xcpu_sys [i];
total += buf->xcpu_idle [i];
p += 6;
buf->xcpu_user [i] = strtoul (p, &p, 0);
buf->xcpu_nice [i] = strtoul (p, &p, 0);
buf->xcpu_sys [i] = strtoul (p, &p, 0);
buf->xcpu_idle [i] = strtoul (p, &p, 0);
buf->xcpu_total [i] = total;
}
total = buf->xcpu_user [i];
total += buf->xcpu_nice [i];
total += buf->xcpu_sys [i];
total += buf->xcpu_idle [i];
if (buf->xcpu_flags)
buf->flags |= _glibtop_sysdeps_cpu_smp;
buf->xcpu_total [i] = total;
}
return 0;
if (buf->xcpu_flags)
buf->flags |= _glibtop_sysdeps_cpu_smp;
return 0;
}

View File

@@ -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,11 +48,11 @@ typedef struct _glibtop_machine glibtop_machine;
struct _glibtop_machine
{
pid_t last_pid;
int no_update;
int fd_stat, fd_meminfo, fd_loadavg;
char proc_stat [BUFSIZ], proc_statm [BUFSIZ];
char proc_status [BUFSIZ];
pid_t last_pid;
int no_update;
int fd_stat, fd_meminfo, fd_loadavg;
char proc_stat [BUFSIZ], proc_statm [BUFSIZ];
char proc_status [BUFSIZ];
};
END_LIBGTOP_DECLS

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -34,76 +36,76 @@ BEGIN_LIBGTOP_DECLS
static inline char *
skip_token (const char *p)
{
while (isspace(*p)) p++;
while (*p && !isspace(*p)) p++;
return (char *)p;
while (isspace(*p)) p++;
while (*p && !isspace(*p)) p++;
return (char *)p;
}
static inline char *
skip_multiple_token (const char *p, int count)
{
int i;
int i;
for (i = 0; i < count; i++)
p = skip_token (p);
for (i = 0; i < count; i++)
p = skip_token (p);
return (char *)p;
return (char *)p;
}
static inline char *
skip_line (const char *p)
{
while (*p != '\n') p++;
return (char *) ++p;
while (*p != '\n') p++;
return (char *) ++p;
}
static inline int
proc_file_to_buffer (char *buffer, const char *fmt, pid_t pid)
{
char filename [BUFSIZ];
int fd, len;
char filename [BUFSIZ];
int fd, len;
sprintf (filename, fmt, pid);
sprintf (filename, fmt, pid);
fd = open (filename, O_RDONLY);
if (fd < 0) return -1;
fd = open (filename, O_RDONLY);
if (fd < 0) return -1;
len = read (fd, buffer, BUFSIZ-1);
if (len < 0) return -1;
len = read (fd, buffer, BUFSIZ-1);
if (len < 0) return -1;
close (fd);
close (fd);
buffer [len] = '\0';
buffer [len] = '\0';
return 0;
return 0;
}
static inline int
proc_stat_to_buffer (char *buffer, pid_t pid)
{
return proc_file_to_buffer (buffer, "/proc/%d/stat", pid);
return proc_file_to_buffer (buffer, "/proc/%d/stat", pid);
}
static inline int
proc_status_to_buffer (char *buffer, pid_t pid)
{
return proc_file_to_buffer (buffer, "/proc/%d/status", pid);
return proc_file_to_buffer (buffer, "/proc/%d/status", pid);
}
static inline int
proc_statm_to_buffer (char *buffer, pid_t pid)
{
return proc_file_to_buffer (buffer, "/proc/%d/statm", pid);
return proc_file_to_buffer (buffer, "/proc/%d/statm", pid);
}
static inline char *
proc_stat_after_cmd (char *p)
{
p = strrchr (p, ')');
if (!p) return p;
p = strrchr (p, ')');
if (!p) return p;
*p++ = '\0';
return p;
*p++ = '\0';
return p;
}
#endif

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -38,9 +40,9 @@ static const unsigned long _glibtop_sysdeps_loadavg_tasks =
int
glibtop_init_loadavg_s (glibtop *server)
{
server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
return 0;
return 0;
}
/* Provides load load averange. */
@@ -50,54 +52,54 @@ glibtop_init_loadavg_s (glibtop *server)
int
glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
{
char buffer [BUFSIZ], *p, *old;
int fd, len;
char buffer [BUFSIZ], *p, *old;
int fd, len;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_LOADAVG, 0);
glibtop_init_s (&server, GLIBTOP_SYSDEPS_LOADAVG, 0);
memset (buf, 0, sizeof (glibtop_loadavg));
memset (buf, 0, sizeof (glibtop_loadavg));
fd = open (FILENAME, O_RDONLY);
if (fd < 0) {
glibtop_warn_io_r (server, "open (%s)", FILENAME);
return -1;
}
len = read (fd, buffer, BUFSIZ-1);
if (len < 0) {
close (fd);
glibtop_warn_io_r (server, "read (%s)", FILENAME);
return -1;
}
fd = open (FILENAME, O_RDONLY);
if (fd < 0) {
glibtop_warn_io_r (server, "open (%s)", FILENAME);
return -1;
}
len = read (fd, buffer, BUFSIZ-1);
if (len < 0) {
close (fd);
glibtop_warn_io_r (server, "read (%s)", FILENAME);
return -1;
}
buffer [len] = '\0';
close (fd);
buf->loadavg [0] = (float) strtod (buffer, &p);
buf->loadavg [1] = (float) strtod (p, &p);
buf->loadavg [2] = (float) strtod (p, &p);
buffer [len] = '\0';
buf->flags = _glibtop_sysdeps_loadavg;
buf->loadavg [0] = (float) strtod (buffer, &p);
buf->loadavg [1] = (float) strtod (p, &p);
buf->loadavg [2] = (float) strtod (p, &p);
while (isspace(*p)) p++;
buf->flags = _glibtop_sysdeps_loadavg;
/* Older Linux versions don't have the nr_running/nr_tasks fields. */
while (isspace(*p)) p++;
old = p;
while (*p) {
if (*p == '/')
break;
if (!isdigit (*p))
return 0;
p++;
}
/* Older Linux versions don't have the nr_running/nr_tasks fields. */
buf->nr_running = strtoul (old, &p, 0); p++;
buf->nr_tasks = strtoul (p, &p, 0);
buf->last_pid = strtoul (p, &p, 0);
old = p;
while (*p) {
if (*p == '/')
break;
if (!isdigit (*p))
return 0;
p++;
}
buf->flags |= _glibtop_sysdeps_loadavg_tasks;
buf->nr_running = strtoul (old, &p, 0); p++;
buf->nr_tasks = strtoul (p, &p, 0);
buf->last_pid = strtoul (p, &p, 0);
return 0;
buf->flags |= _glibtop_sysdeps_loadavg_tasks;
return 0;
}

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -36,9 +38,9 @@ static const unsigned long _glibtop_sysdeps_mem =
int
glibtop_init_mem_s (glibtop *server)
{
server->sysdeps.mem = _glibtop_sysdeps_mem;
server->sysdeps.mem = _glibtop_sysdeps_mem;
return 0;
return 0;
}
/* Provides information about memory usage. */
@@ -48,44 +50,44 @@ glibtop_init_mem_s (glibtop *server)
int
glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
{
char buffer [BUFSIZ], *p;
int fd, len;
char buffer [BUFSIZ], *p;
int fd, len;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);
glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);
memset (buf, 0, sizeof (glibtop_mem));
memset (buf, 0, sizeof (glibtop_mem));
fd = open (FILENAME, O_RDONLY);
if (fd < 0) {
glibtop_warn_io_r (server, "open (%s)", FILENAME);
return -1;
fd = open (FILENAME, O_RDONLY);
if (fd < 0) {
glibtop_warn_io_r (server, "open (%s)", FILENAME);
return -1;
}
len = read (fd, buffer, BUFSIZ-1);
if (len < 0) {
close (fd);
glibtop_warn_io_r (server, "read (%s)", FILENAME);
return -1;
}
}
len = read (fd, buffer, BUFSIZ-1);
if (len < 0) {
close (fd);
glibtop_warn_io_r (server, "read (%s)", FILENAME);
return -1;
}
buffer [len] = '\0';
close (fd);
p = skip_line (buffer);
p = skip_token (p); /* "Mem:" */
buffer [len] = '\0';
buf->total = strtoul (p, &p, 0);
buf->used = strtoul (p, &p, 0);
buf->free = strtoul (p, &p, 0);
buf->shared = strtoul (p, &p, 0);
buf->buffer = strtoul (p, &p, 0);
buf->cached = strtoul (p, &p, 0);
p = skip_line (buffer);
p = skip_token (p); /* "Mem:" */
buf->user = buf->total - buf->free - buf->shared - buf->buffer;
buf->total = strtoul (p, &p, 0);
buf->used = strtoul (p, &p, 0);
buf->free = strtoul (p, &p, 0);
buf->shared = strtoul (p, &p, 0);
buf->buffer = strtoul (p, &p, 0);
buf->cached = strtoul (p, &p, 0);
buf->flags = _glibtop_sysdeps_mem;
buf->user = buf->total - buf->free - buf->shared - buf->buffer;
return 0;
buf->flags = _glibtop_sysdeps_mem;
return 0;
}

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -37,9 +39,9 @@ static const unsigned long _glibtop_sysdeps_msg_limits =
int
glibtop_init_msg_limits_s (glibtop *server)
{
server->sysdeps.msg_limits = _glibtop_sysdeps_msg_limits;
server->sysdeps.msg_limits = _glibtop_sysdeps_msg_limits;
return 0;
return 0;
}
/* Provides information about sysv ipc limits. */
@@ -47,23 +49,23 @@ glibtop_init_msg_limits_s (glibtop *server)
int
glibtop_get_msg_limits_s (glibtop *server, glibtop_msg_limits *buf)
{
struct msginfo msginfo;
struct msginfo msginfo;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_MSG_LIMITS, 0);
glibtop_init_s (&server, GLIBTOP_SYSDEPS_MSG_LIMITS, 0);
memset (buf, 0, sizeof (glibtop_msg_limits));
memset (buf, 0, sizeof (glibtop_msg_limits));
buf->flags = _glibtop_sysdeps_msg_limits;
buf->flags = _glibtop_sysdeps_msg_limits;
msgctl (0, IPC_INFO, (struct msqid_ds *) &msginfo);
msgctl (0, IPC_INFO, (struct msqid_ds *) &msginfo);
buf->msgpool = msginfo.msgpool;
buf->msgmap = msginfo.msgmap;
buf->msgmax = msginfo.msgmax;
buf->msgmnb = msginfo.msgmnb;
buf->msgmni = msginfo.msgmni;
buf->msgssz = msginfo.msgssz;
buf->msgtql = msginfo.msgtql;
buf->msgpool = msginfo.msgpool;
buf->msgmap = msginfo.msgmap;
buf->msgmax = msginfo.msgmax;
buf->msgmnb = msginfo.msgmnb;
buf->msgmni = msginfo.msgmni;
buf->msgssz = msginfo.msgssz;
buf->msgtql = msginfo.msgtql;
return 0;
return 0;
}

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -90,7 +92,7 @@ glibtop_init_netload_s (glibtop *server)
_glibtop_sysdeps_netload_bytes |
_glibtop_sysdeps_netload_packets;
return 0;
return 0;
}
/* Provides network statistics. */
@@ -107,9 +109,9 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
memset (buf, 0, sizeof (glibtop_netload));
/* Linux 2.1.114 - don't know where exactly this was added, but
* recent kernels have byte count in /proc/net/dev so we don't
* need IP accounting.
*/
* recent kernels have byte count in /proc/net/dev so we don't
* need IP accounting.
*/
if (server->os_version_code < 131442) {
@@ -188,17 +190,17 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
}
/* Ok, either IP accounting is not enabled in the kernel or
* it was not enabled for the requested interface. */
* it was not enabled for the requested interface. */
f = fopen ("/proc/net/dev", "r");
if (!f) return -1;
/* Skip over the header line. */
/* Skip over the header line. */
fgets (buffer, BUFSIZ-1, f);
fgets (buffer, BUFSIZ-1, f);
/* Starting with 2.1.xx (don't know exactly which version)
* /proc/net/dev contains both byte and package counters. */
/* Starting with 2.1.xx (don't know exactly which version)
* /proc/net/dev contains both byte and package counters. */
p = strchr (buffer, '|');
if (!p) {
@@ -210,7 +212,7 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
have_bytes = strncmp (++p, "bytes", 5) == 0;
/* Count remaining 'Receive' fields so we know where
* the first 'Transmit' field starts. */
* the first 'Transmit' field starts. */
fields = 0;
while (*p != '|') {

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -61,41 +63,41 @@ glibtop_open_s (glibtop *server, const char *program_name,
const unsigned long features,
const unsigned flags)
{
char buffer [BUFSIZ], *p;
int fd, len, i;
char buffer [BUFSIZ], *p;
int fd, len, i;
server->name = program_name;
server->name = program_name;
set_linux_version ();
server->os_version_code = (unsigned long) linux_version_code;
set_linux_version ();
server->os_version_code = (unsigned long) linux_version_code;
server->ncpu = 0;
server->ncpu = 0;
fd = open (FILENAME, O_RDONLY);
if (fd < 0)
glibtop_error_io_r (server, "open (%s)", FILENAME);
fd = open (FILENAME, O_RDONLY);
if (fd < 0)
glibtop_error_io_r (server, "open (%s)", FILENAME);
len = read (fd, buffer, BUFSIZ-1);
if (len < 0)
glibtop_error_io_r (server, "read (%s)", FILENAME);
len = read (fd, buffer, BUFSIZ-1);
if (len < 0)
glibtop_error_io_r (server, "read (%s)", FILENAME);
close (fd);
close (fd);
buffer [len] = '\0';
buffer [len] = '\0';
p = skip_multiple_token (buffer, 5) + 1;
p = skip_multiple_token (buffer, 5) + 1;
for (i = 0; i < GLIBTOP_NCPU; i++) {
for (i = 0; i < GLIBTOP_NCPU; i++) {
if (strncmp (p, "cpu", 3) || !isdigit (p [3]))
break;
if (strncmp (p, "cpu", 3) || !isdigit (p [3]))
break;
server->ncpu++;
server->ncpu++;
p = skip_multiple_token (p, 5) + 1;
}
p = skip_multiple_token (p, 5) + 1;
}
#if DEBUG
printf ("\nThis machine has %d CPUs.\n\n", server->ncpu);
printf ("\nThis machine has %d CPUs.\n\n", server->ncpu);
#endif
}

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -44,137 +46,137 @@ static const unsigned long _glibtop_sysdeps_ppp =
int
glibtop_init_ppp_s (glibtop *server)
{
server->sysdeps.ppp = _glibtop_sysdeps_ppp;
server->sysdeps.ppp = _glibtop_sysdeps_ppp;
return 0;
return 0;
}
static int
get_ISDN_stats (glibtop *server, int *in, int *out)
{
unsigned long *isdn_stats, *ptr;
int fd, i;
unsigned long *isdn_stats, *ptr;
int fd, i;
*in = *out = 0;
*in = *out = 0;
isdn_stats = glibtop_calloc_r (server, ISDN_MAX_CHANNELS * 2,
sizeof (unsigned long));
isdn_stats = glibtop_calloc_r (server, ISDN_MAX_CHANNELS * 2,
sizeof (unsigned long));
fd = open ("/dev/isdninfo", O_RDONLY);
if (fd < 0) {
glibtop_free_r (server, isdn_stats);
return FALSE;
}
if ((ioctl (fd, IIOCGETCPS, isdn_stats) < 0) && (errno != 0)) {
glibtop_free_r (server, isdn_stats);
close (fd);
return FALSE;
}
for (i = 0, ptr = isdn_stats; i < ISDN_MAX_CHANNELS; i++) {
*in += *ptr++; *out += *ptr++;
}
fd = open ("/dev/isdninfo", O_RDONLY);
if (fd < 0) {
glibtop_free_r (server, isdn_stats);
return FALSE;
}
if ((ioctl (fd, IIOCGETCPS, isdn_stats) < 0) && (errno != 0)) {
glibtop_free_r (server, isdn_stats);
close (fd);
return FALSE;
}
return TRUE;
for (i = 0, ptr = isdn_stats; i < ISDN_MAX_CHANNELS; i++) {
*in += *ptr++; *out += *ptr++;
}
glibtop_free_r (server, isdn_stats);
close (fd);
return TRUE;
}
static int is_ISDN_on (glibtop *server, int *online)
{
FILE *f = 0;
char buffer [BUFSIZ], *p;
int i;
FILE *f = 0;
char buffer [BUFSIZ], *p;
int i;
/* Perhaps I should try to explain this code a little bit.
*
* ------------------------------------------------------------
* This is from the manpage of isdninfo(4):
*
* DESCRIPTION
* /dev/isdninfo is a character device with major number 45
* and minor number 255. It delivers status information from
* the Linux ISDN subsystem to user level.
*
* DATA FORMAT
* When reading from this device, the current status of the
* Linux ISDN subsystem is delivered in 6 lines of text. Each
* line starts with a tag string followed by a colon and
* whitespace. After that the status values are appended sep-
* arated by whitespace.
*
* flags is the tag of line 5. In this line for every driver
* slot, it's B-Channel status is shown. If no driver
* is registered in a slot, a ? is shown. For every
* established B-Channel of the driver, a bit is set
* in the shown value. The driver's first channel is
* mapped to bit 0, the second channel to bit 1 and so
* on.
* ------------------------------------------------------------
*
* So we open /dev/isdninfo, discard the first four lines of text
* and then check whether we have something that is not `0' or `?'
* in one of the flags fields.
*
* Sounds complicated, but I don't see any other way to check whether
* we are connected. Also, this is the method some other ISDN tools
* for Linux use.
*
* Martin
*/
/* Perhaps I should try to explain this code a little bit.
*
* ------------------------------------------------------------
* This is from the manpage of isdninfo(4):
*
* DESCRIPTION
* /dev/isdninfo is a character device with major number 45
* and minor number 255. It delivers status information from
* the Linux ISDN subsystem to user level.
*
* DATA FORMAT
* When reading from this device, the current status of the
* Linux ISDN subsystem is delivered in 6 lines of text. Each
* line starts with a tag string followed by a colon and
* whitespace. After that the status values are appended sep-
* arated by whitespace.
*
* flags is the tag of line 5. In this line for every driver
* slot, it's B-Channel status is shown. If no driver
* is registered in a slot, a ? is shown. For every
* established B-Channel of the driver, a bit is set
* in the shown value. The driver's first channel is
* mapped to bit 0, the second channel to bit 1 and so
* on.
* ------------------------------------------------------------
*
* So we open /dev/isdninfo, discard the first four lines of text
* and then check whether we have something that is not `0' or `?'
* in one of the flags fields.
*
* Sounds complicated, but I don't see any other way to check whether
* we are connected. Also, this is the method some other ISDN tools
* for Linux use.
*
* Martin
*/
f = fopen ("/dev/isdninfo", "r");
f = fopen ("/dev/isdninfo", "r");
if (!f) return FALSE;
if (!f) return FALSE;
for (i = 0; i < 5; i++) {
if (fgets (buffer, BUFSIZ, f) == NULL) {
fclose (f);
return FALSE;
}
for (i = 0; i < 5; i++) {
if (fgets (buffer, BUFSIZ, f) == NULL) {
fclose (f);
return FALSE;
}
}
if (strncmp (buffer, "flags:", 6)) {
fclose (f);
return FALSE;
}
p = buffer+6;
while (*p) {
char *end = p;
if (isspace (*p)) {
p++;
continue;
}
if (strncmp (buffer, "flags:", 6)) {
fclose (f);
return FALSE;
}
for (end = p; *end && !isspace (*end); end++)
;
p = buffer+6;
if (*end == 0)
break;
else
*end = 0;
while (*p) {
char *end = p;
if (isspace (*p)) {
p++;
continue;
}
for (end = p; *end && !isspace (*end); end++)
;
if (*end == 0)
break;
else
*end = 0;
if (!strcmp (p, "?") || !strcmp (p, "0")) {
p = end+1;
continue;
}
fclose (f);
*online = TRUE;
return TRUE;
if (!strcmp (p, "?") || !strcmp (p, "0")) {
p = end+1;
continue;
}
fclose (f);
*online = FALSE;
*online = TRUE;
return TRUE;
}
fclose (f);
*online = FALSE;
return TRUE;
}
/* Provides PPP/ISDN information. */
@@ -182,24 +184,24 @@ static int is_ISDN_on (glibtop *server, int *online)
int
glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device)
{
int in, out, online;
int in, out, online;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PPP, 0);
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PPP, 0);
memset (buf, 0, sizeof (glibtop_ppp));
memset (buf, 0, sizeof (glibtop_ppp));
if (is_ISDN_on (server, &online)) {
buf->state = online ? GLIBTOP_PPP_STATE_ONLINE :
GLIBTOP_PPP_STATE_HANGUP;
buf->flags |= (1L << GLIBTOP_PPP_STATE);
}
if (is_ISDN_on (server, &online)) {
buf->state = online ? GLIBTOP_PPP_STATE_ONLINE :
GLIBTOP_PPP_STATE_HANGUP;
buf->flags |= (1L << GLIBTOP_PPP_STATE);
}
if (get_ISDN_stats (server, &in, &out)) {
buf->bytes_in = in;
buf->bytes_out = out;
buf->flags |= (1L << GLIBTOP_PPP_BYTES_IN) |
(1L << GLIBTOP_PPP_BYTES_OUT);
}
if (get_ISDN_stats (server, &in, &out)) {
buf->bytes_in = in;
buf->bytes_out = out;
buf->flags |= (1L << GLIBTOP_PPP_BYTES_IN) |
(1L << GLIBTOP_PPP_BYTES_OUT);
}
return 0;
return 0;
}

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -34,9 +36,9 @@ static const unsigned long _glibtop_sysdeps_proc_args =
int
glibtop_init_proc_args_s (glibtop *server)
{
server->sysdeps.proc_args = _glibtop_sysdeps_proc_args;
server->sysdeps.proc_args = _glibtop_sysdeps_proc_args;
return 0;
return 0;
}
/* Provides detailed information about a process. */
@@ -45,51 +47,51 @@ char *
glibtop_get_proc_args_s (glibtop *server, glibtop_proc_args *buf,
pid_t pid, unsigned max_len)
{
char fn [BUFSIZ], buffer [BUFSIZ];
int cmdline, len, total = 0;
char *retval = NULL;
char fn [BUFSIZ], buffer [BUFSIZ];
int cmdline, len, total = 0;
char *retval = NULL;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_ARGS, 0);
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_ARGS, 0);
memset (buf, 0, sizeof (glibtop_proc_args));
memset (buf, 0, sizeof (glibtop_proc_args));
sprintf (fn, "/proc/%d/cmdline", pid);
sprintf (fn, "/proc/%d/cmdline", pid);
cmdline = open (fn, O_RDONLY);
if (cmdline < 0) return NULL;
cmdline = open (fn, O_RDONLY);
if (cmdline < 0) return NULL;
if (max_len) {
retval = glibtop_malloc_r (server, max_len+1);
if (max_len) {
retval = glibtop_malloc_r (server, max_len+1);
len = read (cmdline, retval, max_len);
if (len < 0) {
glibtop_free_r (server, retval);
return NULL;
}
len = read (cmdline, retval, max_len);
if (len < 0) {
glibtop_free_r (server, retval);
return NULL;
}
return retval;
}
while (1) {
len = read (cmdline, buffer, BUFSIZ-1);
if (len < 0) {
glibtop_free_r (server, retval);
return NULL;
}
if (len == 0)
break;
retval = glibtop_realloc_r (server, retval, total+len+1);
memcpy (retval+total, buffer, len);
*(retval+total+len) = 0;
total += len;
}
close (cmdline);
buf->size = total;
buf->flags = _glibtop_sysdeps_proc_args;
return retval;
}
while (1) {
len = read (cmdline, buffer, BUFSIZ-1);
if (len < 0) {
glibtop_free_r (server, retval);
return NULL;
}
if (len == 0)
break;
retval = glibtop_realloc_r (server, retval, total+len+1);
memcpy (retval+total, buffer, len);
*(retval+total+len) = 0;
total += len;
}
close (cmdline);
buf->size = total;
buf->flags = _glibtop_sysdeps_proc_args;
return retval;
}

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -36,9 +38,9 @@ static const unsigned long _glibtop_sysdeps_proc_kernel =
int
glibtop_init_proc_kernel_s (glibtop *server)
{
server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel;
server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel;
return 0;
return 0;
}
/* Provides detailed information about a process. */
@@ -46,36 +48,36 @@ glibtop_init_proc_kernel_s (glibtop *server)
int
glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid)
{
char buffer [BUFSIZ], *p;
char buffer [BUFSIZ], *p;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_KERNEL, 0);
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_KERNEL, 0);
memset (buf, 0, sizeof (glibtop_proc_kernel));
memset (buf, 0, sizeof (glibtop_proc_kernel));
if (proc_stat_to_buffer (buffer, pid))
return -1;
if (proc_stat_to_buffer (buffer, pid))
return -1;
p = proc_stat_after_cmd (buffer);
if (!p) return -1;
p = proc_stat_after_cmd (buffer);
if (!p) return -1;
p = skip_multiple_token (p, 6);
p = skip_multiple_token (p, 6);
buf->k_flags = strtoul (p, &p, 0);
buf->min_flt = strtoul (p, &p, 0);
buf->cmin_flt = strtoul (p, &p, 0);
buf->maj_flt = strtoul (p, &p, 0);
buf->cmaj_flt = strtoul (p, &p, 0);
buf->k_flags = strtoul (p, &p, 0);
buf->min_flt = strtoul (p, &p, 0);
buf->cmin_flt = strtoul (p, &p, 0);
buf->maj_flt = strtoul (p, &p, 0);
buf->cmaj_flt = strtoul (p, &p, 0);
p = skip_multiple_token (p, 15);
p = skip_multiple_token (p, 15);
buf->kstk_esp = strtoul (p, &p, 0);
buf->kstk_eip = strtoul (p, &p, 0);
buf->kstk_esp = strtoul (p, &p, 0);
buf->kstk_eip = strtoul (p, &p, 0);
p = skip_multiple_token (p, 4);
p = skip_multiple_token (p, 4);
buf->nwchan = strtoul (p, &p, 0);
buf->nwchan = strtoul (p, &p, 0);
buf->flags = _glibtop_sysdeps_proc_kernel;
buf->flags = _glibtop_sysdeps_proc_kernel;
return 0;
return 0;
}

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -42,9 +44,9 @@ static const unsigned long _glibtop_sysdeps_proclist =
int
glibtop_init_proclist_s (glibtop *server)
{
server->sysdeps.proclist = _glibtop_sysdeps_proclist;
server->sysdeps.proclist = _glibtop_sysdeps_proclist;
return 0;
return 0;
}
#define BLOCK_COUNT 256
@@ -67,176 +69,176 @@ unsigned *
glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf,
int64_t which, int64_t arg)
{
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;
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;
glibtop_proc_uid procuid;
glibtop_proc_state procstate;
glibtop_proc_uid procuid;
glibtop_proc_state procstate;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROCLIST, 0);
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROCLIST, 0);
memset (buf, 0, sizeof (glibtop_proclist));
memset (buf, 0, sizeof (glibtop_proclist));
proc = opendir ("/proc");
if (!proc) return NULL;
proc = opendir ("/proc");
if (!proc) return NULL;
/* read every every entry in /proc */
/* read every every entry in /proc */
for (count = total = 0, entry = readdir (proc);
entry; entry = readdir (proc)) {
ok = 1; len = strlen (entry->d_name);
for (count = total = 0, entry = readdir (proc);
entry; entry = readdir (proc)) {
ok = 1; len = strlen (entry->d_name);
/* does it consist entirely of digits? */
/* does it consist entirely of digits? */
for (i = 0; i < len; i++)
if (!isdigit (entry->d_name [i])) ok = 0;
if (!ok) continue;
for (i = 0; i < len; i++)
if (!isdigit (entry->d_name [i])) ok = 0;
if (!ok) continue;
/* convert it in a number */
/* convert it in a number */
if (sscanf (entry->d_name, "%u", &pid) != 1) continue;
if (sscanf (entry->d_name, "%u", &pid) != 1) continue;
/* is it really a directory? */
/* is it really a directory? */
sprintf (buffer, "/proc/%d", pid);
sprintf (buffer, "/proc/%d", pid);
if (stat (buffer, &statb)) continue;
if (stat (buffer, &statb)) continue;
if (!S_ISDIR (statb.st_mode)) continue;
if (!S_ISDIR (statb.st_mode)) continue;
switch (which & GLIBTOP_KERN_PROC_MASK) {
case GLIBTOP_KERN_PROC_ALL:
break;
case GLIBTOP_KERN_PROC_PID:
if ((unsigned) arg != pid)
continue;
break;
case GLIBTOP_KERN_PROC_UID:
if ((uid_t) arg != statb.st_uid)
continue;
break;
case GLIBTOP_KERN_PROC_PGRP:
/* Do you really, really need this ? */
glibtop_get_proc_uid_s (server, &procuid, pid);
if (procuid.flags & (1L << GLIBTOP_PROC_UID_PGRP))
if ((int) arg != procuid.pgrp)
continue;
break;
case GLIBTOP_KERN_PROC_PPID:
/* Do you really, really need this ? */
glibtop_get_proc_uid_s (server, &procuid, pid);
if (procuid.flags & (1L << GLIBTOP_PROC_UID_PPID))
if ((int) arg != procuid.ppid)
continue;
break;
case GLIBTOP_KERN_PROC_SESSION:
/* Do you really, really need this ? */
glibtop_get_proc_uid_s (server, &procuid, pid);
if (procuid.flags & (1L << GLIBTOP_PROC_UID_SESSION))
if ((int) arg != procuid.session)
continue;
break;
case GLIBTOP_KERN_PROC_TTY:
/* Do you really, really need this ? */
glibtop_get_proc_uid_s (server, &procuid, pid);
if (procuid.flags & (1L << GLIBTOP_PROC_UID_TTY))
if ((int) arg != procuid.tty)
continue;
break;
case GLIBTOP_KERN_PROC_RUID:
/* Do you really, really need this ? */
glibtop_get_proc_uid_s (server, &procuid, pid);
if (procuid.flags & (1L << GLIBTOP_PROC_UID_EUID))
if ((int) arg != procuid.euid)
continue;
break;
}
if (which & GLIBTOP_EXCLUDE_NOTTY) {
glibtop_get_proc_uid_s (server, &procuid, pid);
if (procuid.flags & (1L << GLIBTOP_PROC_UID_TTY))
if (procuid.tty == -1) continue;
}
if (which & GLIBTOP_EXCLUDE_IDLE) {
glibtop_get_proc_state_s (server, &procstate, pid);
if (procstate.flags & (1L << GLIBTOP_PROC_STATE_STATE))
if (!(procstate.state & GLIBTOP_PROCESS_RUNNING)) continue;
}
if (which & GLIBTOP_EXCLUDE_SYSTEM) {
glibtop_get_proc_uid_s (server, &procuid, pid);
if (procuid.flags & (1L << GLIBTOP_PROC_UID_UID))
if (procuid.uid == 0) 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++;
switch (which & GLIBTOP_KERN_PROC_MASK) {
case GLIBTOP_KERN_PROC_ALL:
break;
case GLIBTOP_KERN_PROC_PID:
if ((unsigned) arg != pid)
continue;
break;
case GLIBTOP_KERN_PROC_UID:
if ((uid_t) arg != statb.st_uid)
continue;
break;
case GLIBTOP_KERN_PROC_PGRP:
/* Do you really, really need this ? */
glibtop_get_proc_uid_s (server, &procuid, pid);
if (procuid.flags & (1L << GLIBTOP_PROC_UID_PGRP))
if ((int) arg != procuid.pgrp)
continue;
break;
case GLIBTOP_KERN_PROC_PPID:
/* Do you really, really need this ? */
glibtop_get_proc_uid_s (server, &procuid, pid);
if (procuid.flags & (1L << GLIBTOP_PROC_UID_PPID))
if ((int) arg != procuid.ppid)
continue;
break;
case GLIBTOP_KERN_PROC_SESSION:
/* Do you really, really need this ? */
glibtop_get_proc_uid_s (server, &procuid, pid);
if (procuid.flags & (1L << GLIBTOP_PROC_UID_SESSION))
if ((int) arg != procuid.session)
continue;
break;
case GLIBTOP_KERN_PROC_TTY:
/* Do you really, really need this ? */
glibtop_get_proc_uid_s (server, &procuid, pid);
if (procuid.flags & (1L << GLIBTOP_PROC_UID_TTY))
if ((int) arg != procuid.tty)
continue;
break;
case GLIBTOP_KERN_PROC_RUID:
/* Do you really, really need this ? */
glibtop_get_proc_uid_s (server, &procuid, pid);
if (procuid.flags & (1L << GLIBTOP_PROC_UID_EUID))
if ((int) arg != procuid.euid)
continue;
break;
}
if (which & GLIBTOP_EXCLUDE_NOTTY) {
glibtop_get_proc_uid_s (server, &procuid, pid);
if (procuid.flags & (1L << GLIBTOP_PROC_UID_TTY))
if (procuid.tty == -1) continue;
}
if (which & GLIBTOP_EXCLUDE_IDLE) {
glibtop_get_proc_state_s (server, &procstate, pid);
if (procstate.flags & (1L << GLIBTOP_PROC_STATE_STATE))
if (!(procstate.state & GLIBTOP_PROCESS_RUNNING)) continue;
}
if (which & GLIBTOP_EXCLUDE_SYSTEM) {
glibtop_get_proc_uid_s (server, &procuid, pid);
if (procuid.flags & (1L << GLIBTOP_PROC_UID_UID))
if (procuid.uid == 0) 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);
closedir (proc);
/* count is only zero if an error occured (one a running Linux system,
* we have at least one single process). */
/* count is only zero if an error occured (one a running Linux system,
* we have at least one single process). */
if (!count) return NULL;
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. */
/* 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);
new_size = pids_size + count * sizeof (unsigned);
pids_chain = glibtop_realloc_r (server, pids_chain, new_size);
pids_chain = glibtop_realloc_r (server, pids_chain, new_size);
memcpy (pids_chain + pids_offset, pids, count * sizeof (unsigned));
memcpy (pids_chain + pids_offset, pids, count * sizeof (unsigned));
pids_size = new_size;
pids_size = new_size;
pids_offset += BLOCK_COUNT;
pids_offset += BLOCK_COUNT;
/* Since everything is ok now, we can set buf->flags, fill in the
* remaining fields and return the `pids_chain'. */
/* Since everything is ok now, we can set buf->flags, fill in the
* remaining fields and return the `pids_chain'. */
buf->flags = _glibtop_sysdeps_proclist;
buf->flags = _glibtop_sysdeps_proclist;
buf->size = sizeof (unsigned);
buf->number = total;
buf->size = sizeof (unsigned);
buf->number = total;
buf->total = total * sizeof (unsigned);
buf->total = total * sizeof (unsigned);
return pids_chain;
return pids_chain;
}

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -41,9 +43,9 @@ static const unsigned long _glibtop_sysdeps_map_entry =
int
glibtop_init_proc_map_s (glibtop *server)
{
server->sysdeps.proc_map = _glibtop_sysdeps_proc_map;
server->sysdeps.proc_map = _glibtop_sysdeps_proc_map;
return 0;
return 0;
}
/* Provides detailed information about a process. */
@@ -51,90 +53,90 @@ glibtop_init_proc_map_s (glibtop *server)
glibtop_map_entry *
glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
{
char fn [BUFSIZ];
glibtop_map_entry *entry_list = NULL;
int rv, n = 0;
FILE *maps;
char fn [BUFSIZ];
glibtop_map_entry *entry_list = NULL;
int rv, n = 0;
FILE *maps;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_MAP, 0);
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_MAP, 0);
memset (buf, 0, sizeof (glibtop_proc_map));
memset (buf, 0, sizeof (glibtop_proc_map));
sprintf (fn, "/proc/%d/maps", pid);
sprintf (fn, "/proc/%d/maps", pid);
maps = fopen (fn, "r");
if (!maps) return NULL;
maps = fopen (fn, "r");
if (!maps) return NULL;
do {
short dev_major, dev_minor;
unsigned long start, end, offset, inode, perm;
char flags [5], *format;
size_t size;
do {
short dev_major, dev_minor;
unsigned long start, end, offset, inode, perm;
char flags [5], *format;
size_t size;
if (sizeof (void*) == 8)
format = "%16lx-%16lx %4c\n %16lx %02hx:%02hx %ld";
else
format = "%08lx-%08lx %4c\n %08lx %02hx:%02hx %ld";
if (sizeof (void*) == 8)
format = "%16lx-%16lx %4c\n %16lx %02hx:%02hx %ld";
else
format = "%08lx-%08lx %4c\n %08lx %02hx:%02hx %ld";
rv = fscanf (maps, format,
&start, &end, flags, &offset,
&dev_major, &dev_minor, &inode);
rv = fscanf (maps, format,
&start, &end, flags, &offset,
&dev_major, &dev_minor, &inode);
flags [4] = 0;
flags [4] = 0;
/* Compute access permissions. */
/* Compute access permissions. */
perm = 0;
perm = 0;
if (flags [0] == 'r')
perm |= GLIBTOP_MAP_PERM_READ;
if (flags [1] == 'w')
perm |= GLIBTOP_MAP_PERM_WRITE;
if (flags [2] == 'x')
perm |= GLIBTOP_MAP_PERM_EXECUTE;
if (flags [3] == 's')
perm |= GLIBTOP_MAP_PERM_SHARED;
if (flags [3] == 'p')
perm |= GLIBTOP_MAP_PERM_PRIVATE;
if (flags [0] == 'r')
perm |= GLIBTOP_MAP_PERM_READ;
if (flags [1] == 'w')
perm |= GLIBTOP_MAP_PERM_WRITE;
if (flags [2] == 'x')
perm |= GLIBTOP_MAP_PERM_EXECUTE;
if (flags [3] == 's')
perm |= GLIBTOP_MAP_PERM_SHARED;
if (flags [3] == 'p')
perm |= GLIBTOP_MAP_PERM_PRIVATE;
/* Read filename. */
/* Read filename. */
fn [0] = fgetc (maps);
fn [0] = fgetc (maps);
if (fn [0] != '\n' && fn [0] != EOF) {
if (fn [0] != '\n' && fn [0] != EOF) {
fscanf (maps, "%*[ ]%[^\n]\n", fn);
fscanf (maps, "%*[ ]%[^\n]\n", fn);
} else fn [0] = 0;
} else fn [0] = 0;
size = (n+1) * sizeof (glibtop_map_entry);
size = (n+1) * sizeof (glibtop_map_entry);
entry_list = glibtop_realloc_r (server, entry_list, size);
entry_list = glibtop_realloc_r (server, entry_list, size);
memset (&(entry_list [n]), 0, sizeof (glibtop_map_entry));
memset (&(entry_list [n]), 0, sizeof (glibtop_map_entry));
entry_list [n].flags = _glibtop_sysdeps_map_entry;
entry_list [n].flags = _glibtop_sysdeps_map_entry;
entry_list [n].start = (u_int64_t) start;
entry_list [n].end = (u_int64_t) end;
entry_list [n].offset = (u_int64_t) offset;
entry_list [n].perm = (u_int64_t) perm;
entry_list [n].device = (u_int64_t) (dev_major << 8) +
(u_int64_t) dev_minor;
entry_list [n].inode = (u_int64_t) inode;
entry_list [n].start = (u_int64_t) start;
entry_list [n].end = (u_int64_t) end;
entry_list [n].offset = (u_int64_t) offset;
entry_list [n].perm = (u_int64_t) perm;
entry_list [n].device = (u_int64_t) (dev_major << 8) +
(u_int64_t) dev_minor;
entry_list [n].inode = (u_int64_t) inode;
strncpy (entry_list [n].filename, fn, GLIBTOP_MAP_FILENAME_LEN);
entry_list [n].filename [GLIBTOP_MAP_FILENAME_LEN] = 0;
strncpy (entry_list [n].filename, fn, GLIBTOP_MAP_FILENAME_LEN);
entry_list [n].filename [GLIBTOP_MAP_FILENAME_LEN] = 0;
n++;
n++;
} while (rv != EOF && rv && fn [0] != EOF);
} while (rv != EOF && rv && fn [0] != EOF);
fclose (maps);
fclose (maps);
buf->number = n;
buf->size = sizeof (glibtop_map_entry);
buf->total = n * sizeof (glibtop_map_entry);
buf->number = n;
buf->size = sizeof (glibtop_map_entry);
buf->total = n * sizeof (glibtop_map_entry);
return entry_list;
return entry_list;
}

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -48,21 +50,21 @@ static int pageshift; /* log base 2 of the pagesize */
int
glibtop_init_proc_mem_s (glibtop *server)
{
register int pagesize;
register int pagesize;
server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem |
_glibtop_sysdeps_proc_mem_statm;
server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem |
_glibtop_sysdeps_proc_mem_statm;
/* get the page size with "getpagesize" and calculate pageshift
* from it */
pagesize = getpagesize ();
pageshift = 0;
while (pagesize > 1) {
pageshift++;
pagesize >>= 1;
}
/* get the page size with "getpagesize" and calculate pageshift
* from it */
pagesize = getpagesize ();
pageshift = 0;
while (pagesize > 1) {
pageshift++;
pagesize >>= 1;
}
return 0;
return 0;
}
/* Provides detailed information about a process. */
@@ -70,39 +72,39 @@ glibtop_init_proc_mem_s (glibtop *server)
int
glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
{
char buffer [BUFSIZ], *p;
char buffer [BUFSIZ], *p;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);
glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);
memset (buf, 0, sizeof (glibtop_proc_mem));
memset (buf, 0, sizeof (glibtop_proc_mem));
if (proc_stat_to_buffer (buffer, pid))
return -1;
if (proc_stat_to_buffer (buffer, pid))
return -1;
p = proc_stat_after_cmd (buffer);
if (!p) return -1;
p = proc_stat_after_cmd (buffer);
if (!p) return -1;
p = skip_multiple_token (p, 20);
p = skip_multiple_token (p, 20);
buf->vsize = strtoul (p, &p, 0);
buf->rss = strtoul (p, &p, 0);
buf->rss_rlim = strtoul (p, &p, 0);
buf->vsize = strtoul (p, &p, 0);
buf->rss = strtoul (p, &p, 0);
buf->rss_rlim = strtoul (p, &p, 0);
buf->flags = _glibtop_sysdeps_proc_mem;
buf->flags = _glibtop_sysdeps_proc_mem;
if (proc_statm_to_buffer (buffer, pid))
return -1;
if (proc_statm_to_buffer (buffer, pid))
return -1;
buf->size = strtoul (buffer, &p, 0);
buf->resident = strtoul (p, &p, 0);
buf->share = strtoul (p, &p, 0);
buf->size = strtoul (buffer, &p, 0);
buf->resident = strtoul (p, &p, 0);
buf->share = strtoul (p, &p, 0);
buf->size <<= pageshift;
buf->resident <<= pageshift;
buf->share <<= pageshift;
buf->rss <<= pageshift;
buf->size <<= pageshift;
buf->resident <<= pageshift;
buf->share <<= pageshift;
buf->rss <<= pageshift;
buf->flags |= _glibtop_sysdeps_proc_mem_statm;
buf->flags |= _glibtop_sysdeps_proc_mem_statm;
return 0;
return 0;
}

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -52,21 +54,21 @@ static int pageshift; /* log base 2 of the pagesize */
int
glibtop_init_proc_segment_s (glibtop *server)
{
register int pagesize;
register int pagesize;
server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment |
_glibtop_sysdeps_proc_segment_statm;
server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment |
_glibtop_sysdeps_proc_segment_statm;
/* get the page size with "getpagesize" and calculate pageshift
* from it */
pagesize = getpagesize ();
pageshift = 0;
while (pagesize > 1) {
pageshift++;
pagesize >>= 1;
}
/* get the page size with "getpagesize" and calculate pageshift
* from it */
pagesize = getpagesize ();
pageshift = 0;
while (pagesize > 1) {
pageshift++;
pagesize >>= 1;
}
return 0;
return 0;
}
/* Provides detailed information about a process. */
@@ -75,45 +77,45 @@ int
glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
pid_t pid)
{
char buffer [BUFSIZ], *p;
char buffer [BUFSIZ], *p;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_SEGMENT, 0);
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_SEGMENT, 0);
memset (buf, 0, sizeof (glibtop_proc_segment));
memset (buf, 0, sizeof (glibtop_proc_segment));
if (proc_stat_to_buffer (buffer, pid))
return -1;
if (proc_stat_to_buffer (buffer, pid))
return -1;
p = proc_stat_after_cmd (buffer);
if (!p) return -1;
p = proc_stat_after_cmd (buffer);
if (!p) return -1;
p = skip_multiple_token (p, 23);
p = skip_multiple_token (p, 23);
buf->start_code = strtoul (p, &p, 0);
buf->end_code = strtoul (p, &p, 0);
buf->start_stack = strtoul (p, &p, 0);
buf->start_code = strtoul (p, &p, 0);
buf->end_code = strtoul (p, &p, 0);
buf->start_stack = strtoul (p, &p, 0);
buf->flags = _glibtop_sysdeps_proc_segment;
if (proc_statm_to_buffer (buffer, pid))
return 0;
p = skip_multiple_token (buffer, 3);
/* This doesn't work very well due to a bug in the Linux kernel.
* I'll submit a patch to the kernel mailing list soon. */
buf->text_rss = strtoul (p, &p, 0);
buf->shlib_rss = strtoul (p, &p, 0);
buf->data_rss = strtoul (p, &p, 0);
buf->dirty_size = strtoul (p, &p, 0);
buf->text_rss <<= pageshift;
buf->shlib_rss <<= pageshift;
buf->data_rss <<= pageshift;
buf->dirty_size <<= pageshift;
buf->flags |= _glibtop_sysdeps_proc_segment_statm;
buf->flags = _glibtop_sysdeps_proc_segment;
if (proc_statm_to_buffer (buffer, pid))
return 0;
p = skip_multiple_token (buffer, 3);
/* This doesn't work very well due to a bug in the Linux kernel.
* I'll submit a patch to the kernel mailing list soon. */
buf->text_rss = strtoul (p, &p, 0);
buf->shlib_rss = strtoul (p, &p, 0);
buf->data_rss = strtoul (p, &p, 0);
buf->dirty_size = strtoul (p, &p, 0);
buf->text_rss <<= pageshift;
buf->shlib_rss <<= pageshift;
buf->data_rss <<= pageshift;
buf->dirty_size <<= pageshift;
buf->flags |= _glibtop_sysdeps_proc_segment_statm;
return 0;
}

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -34,9 +36,9 @@ static const unsigned long _glibtop_sysdeps_proc_signal =
int
glibtop_init_proc_signal_s (glibtop *server)
{
server->sysdeps.proc_signal = _glibtop_sysdeps_proc_signal;
server->sysdeps.proc_signal = _glibtop_sysdeps_proc_signal;
return 0;
return 0;
}
/* Provides detailed information about a process. */
@@ -44,26 +46,26 @@ glibtop_init_proc_signal_s (glibtop *server)
int
glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid)
{
char buffer [BUFSIZ], *p;
char buffer [BUFSIZ], *p;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_SIGNAL, 0);
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_SIGNAL, 0);
memset (buf, 0, sizeof (glibtop_proc_signal));
memset (buf, 0, sizeof (glibtop_proc_signal));
if (proc_stat_to_buffer (buffer, pid))
return -1;
if (proc_stat_to_buffer (buffer, pid))
return -1;
p = proc_stat_after_cmd (buffer);
if (!p) return -1;
p = proc_stat_after_cmd (buffer);
if (!p) return -1;
p = skip_multiple_token (p, 28);
p = skip_multiple_token (p, 28);
buf->signal [0] = strtoul (p, &p, 0);
buf->blocked [0] = strtoul (p, &p, 0);
buf->sigignore [0] = strtoul (p, &p, 0);
buf->sigcatch [0] = strtoul (p, &p, 0);
buf->signal [0] = strtoul (p, &p, 0);
buf->blocked [0] = strtoul (p, &p, 0);
buf->sigignore [0] = strtoul (p, &p, 0);
buf->sigcatch [0] = strtoul (p, &p, 0);
buf->flags = _glibtop_sysdeps_proc_signal;
buf->flags = _glibtop_sysdeps_proc_signal;
return 0;
return 0;
}

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -38,10 +40,10 @@ static const unsigned long _glibtop_sysdeps_proc_state_uid =
int
glibtop_init_proc_state_s (glibtop *server)
{
server->sysdeps.proc_state = _glibtop_sysdeps_proc_state |
_glibtop_sysdeps_proc_state_uid;
server->sysdeps.proc_state = _glibtop_sysdeps_proc_state |
_glibtop_sysdeps_proc_state_uid;
return 0;
return 0;
}
/* Provides detailed information about a process. */
@@ -49,74 +51,74 @@ glibtop_init_proc_state_s (glibtop *server)
int
glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
{
char buffer [BUFSIZ], state, *p;
struct stat statb;
char buffer [BUFSIZ], state, *p;
struct stat statb;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_STATE, 0);
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_STATE, 0);
memset (buf, 0, sizeof (glibtop_proc_state));
memset (buf, 0, sizeof (glibtop_proc_state));
/* IMPORTANT NOTICE: For security reasons it is extremely important
* that the 'uid' and 'gid' fields have correct
* values; NEVER set their flags values if this
* is not the case !!! */
/* IMPORTANT NOTICE: For security reasons it is extremely important
* that the 'uid' and 'gid' fields have correct
* values; NEVER set their flags values if this
* is not the case !!! */
sprintf (buffer, "/proc/%d", pid);
sprintf (buffer, "/proc/%d", pid);
if (stat (buffer, &statb))
return -1;
if (stat (buffer, &statb))
return -1;
/* For security reasons we use stat () since it is
* more failsafe than parsing the file. */
/* For security reasons we use stat () since it is
* more failsafe than parsing the file. */
buf->uid = statb.st_uid;
buf->gid = statb.st_gid;
buf->uid = statb.st_uid;
buf->gid = statb.st_gid;
buf->flags = _glibtop_sysdeps_proc_state_uid;
buf->flags = _glibtop_sysdeps_proc_state_uid;
sprintf (buffer, "/proc/%d", pid);
sprintf (buffer, "/proc/%d", pid);
/* Now we read the remaining fields. */
/* Now we read the remaining fields. */
if (proc_stat_to_buffer (buffer, pid))
return -1;
if (proc_stat_to_buffer (buffer, pid))
return -1;
p = strrchr (buffer, ')'); *p = '\0';
state = p [2];
p = strrchr (buffer, ')'); *p = '\0';
state = p [2];
p = skip_token (buffer); p++; /* pid */
if (*p++ != '(')
glibtop_error_r (server, "Bad data in /proc/%d/stat", pid);
p = skip_token (buffer); p++; /* pid */
if (*p++ != '(')
glibtop_error_r (server, "Bad data in /proc/%d/stat", pid);
strncpy (buf->cmd, p, sizeof (buf->cmd)-1);
buf->cmd [sizeof (buf->cmd)-1] = 0;
strncpy (buf->cmd, p, sizeof (buf->cmd)-1);
buf->cmd [sizeof (buf->cmd)-1] = 0;
buf->flags |= _glibtop_sysdeps_proc_state;
buf->flags |= _glibtop_sysdeps_proc_state;
switch (state) {
case 'R':
buf->state = GLIBTOP_PROCESS_RUNNING;
break;
case 'S':
buf->state = GLIBTOP_PROCESS_INTERRUPTIBLE;
break;
case 'D':
buf->state = GLIBTOP_PROCESS_UNINTERRUPTIBLE;
break;
case 'Z':
buf->state = GLIBTOP_PROCESS_ZOMBIE;
break;
case 'T':
buf->state = GLIBTOP_PROCESS_STOPPED;
break;
case 'W':
buf->state = GLIBTOP_PROCESS_SWAPPING;
break;
default:
return -1;
}
switch (state) {
case 'R':
buf->state = GLIBTOP_PROCESS_RUNNING;
break;
case 'S':
buf->state = GLIBTOP_PROCESS_INTERRUPTIBLE;
break;
case 'D':
buf->state = GLIBTOP_PROCESS_UNINTERRUPTIBLE;
break;
case 'Z':
buf->state = GLIBTOP_PROCESS_ZOMBIE;
break;
case 'T':
buf->state = GLIBTOP_PROCESS_STOPPED;
break;
case 'W':
buf->state = GLIBTOP_PROCESS_SWAPPING;
break;
default:
return -1;
}
buf->flags |= (1L << GLIBTOP_PROC_STATE_STATE);
buf->flags |= (1L << GLIBTOP_PROC_STATE_STATE);
return 0;
return 0;
}

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -39,12 +41,12 @@ static const unsigned long _glibtop_sysdeps_proc_time_smp =
int
glibtop_init_proc_time_s (glibtop *server)
{
server->sysdeps.proc_time = _glibtop_sysdeps_proc_time;
server->sysdeps.proc_time = _glibtop_sysdeps_proc_time;
if (server->ncpu)
server->sysdeps.proc_time |= _glibtop_sysdeps_proc_time_smp;
if (server->ncpu)
server->sysdeps.proc_time |= _glibtop_sysdeps_proc_time_smp;
return 0;
return 0;
}
/* Provides detailed information about a process. */
@@ -52,56 +54,56 @@ glibtop_init_proc_time_s (glibtop *server)
int
glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
{
char buffer [BUFSIZ], *p;
int i;
char buffer [BUFSIZ], *p;
int i;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_TIME, 0);
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_TIME, 0);
memset (buf, 0, sizeof (glibtop_proc_time));
memset (buf, 0, sizeof (glibtop_proc_time));
if (proc_stat_to_buffer (buffer, pid))
return -1;
if (proc_stat_to_buffer (buffer, pid))
return -1;
p = proc_stat_after_cmd (buffer);
if (!p) return -1;
p = proc_stat_after_cmd (buffer);
if (!p) return -1;
p = skip_multiple_token (p, 11);
p = skip_multiple_token (p, 11);
buf->utime = strtoul (p, &p, 0);
buf->stime = strtoul (p, &p, 0);
buf->cutime = strtoul (p, &p, 0);
buf->cstime = strtoul (p, &p, 0);
buf->utime = strtoul (p, &p, 0);
buf->stime = strtoul (p, &p, 0);
buf->cutime = strtoul (p, &p, 0);
buf->cstime = strtoul (p, &p, 0);
p = skip_multiple_token (p, 2);
p = skip_multiple_token (p, 2);
buf->timeout = strtoul (p, &p, 0);
buf->it_real_value = strtoul (p, &p, 0);
buf->start_time = strtoul (p, &p, 0);
buf->timeout = strtoul (p, &p, 0);
buf->it_real_value = strtoul (p, &p, 0);
buf->start_time = strtoul (p, &p, 0);
buf->frequency = 100;
buf->frequency = 100;
buf->flags = _glibtop_sysdeps_proc_time;
if (!server->ncpu)
return 0;
if (proc_file_to_buffer (buffer, "/proc/%d/cpu", pid))
return -1;
p = skip_token (buffer);
buf->utime = strtoul (p, &p, 0);
buf->stime = strtoul (p, &p, 0);
for (i = 0; i < GLIBTOP_NCPU; i++) {
if (strncmp (p+1, "cpu", 3) || !isdigit (p [4]))
break;
p += 6;
buf->xcpu_utime [i] = strtoul (p, &p, 0);
buf->xcpu_stime [i] = strtoul (p, &p, 0);
}
buf->flags |= _glibtop_sysdeps_proc_time_smp;
buf->flags = _glibtop_sysdeps_proc_time;
if (!server->ncpu)
return 0;
if (proc_file_to_buffer (buffer, "/proc/%d/cpu", pid))
return -1;
p = skip_token (buffer);
buf->utime = strtoul (p, &p, 0);
buf->stime = strtoul (p, &p, 0);
for (i = 0; i < GLIBTOP_NCPU; i++) {
if (strncmp (p+1, "cpu", 3) || !isdigit (p [4]))
break;
p += 6;
buf->xcpu_utime [i] = strtoul (p, &p, 0);
buf->xcpu_stime [i] = strtoul (p, &p, 0);
}
buf->flags |= _glibtop_sysdeps_proc_time_smp;
return 0;
}

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -42,10 +44,10 @@ static const unsigned long _glibtop_sysdeps_proc_uid_stat =
int
glibtop_init_proc_uid_s (glibtop *server)
{
server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid |
_glibtop_sysdeps_proc_uid_stat;
server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid |
_glibtop_sysdeps_proc_uid_stat;
return 0;
return 0;
}
/* Provides detailed information about a process. */
@@ -53,78 +55,78 @@ glibtop_init_proc_uid_s (glibtop *server)
int
glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
{
char buffer [BUFSIZ], *p;
char buffer [BUFSIZ], *p;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_UID, 0);
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_UID, 0);
memset (buf, 0, sizeof (glibtop_proc_uid));
memset (buf, 0, sizeof (glibtop_proc_uid));
if (proc_status_to_buffer (buffer, pid))
return -1;
if (proc_status_to_buffer (buffer, pid))
return -1;
/* Search substring 'Pid:' */
/* Search substring 'Pid:' */
p = strstr (buffer, "\nPid:");
if (!p) return -1;
p = strstr (buffer, "\nPid:");
if (!p) return -1;
p = skip_token (p); /* "Pid:" */
buf->pid = strtoul (p, &p, 0);
p = skip_token (p); /* "Pid:" */
buf->pid = strtoul (p, &p, 0);
p = skip_token (p); /* "PPid:" */
buf->ppid = strtoul (p, &p, 0);
p = skip_token (p); /* "PPid:" */
buf->ppid = strtoul (p, &p, 0);
/* Maybe future Linux versions place something between
* "PPid" and "Uid", so we catch this here. */
p = strstr (p, "\nUid:");
if (!p) return -1;
/* Maybe future Linux versions place something between
* "PPid" and "Uid", so we catch this here. */
p = strstr (p, "\nUid:");
if (!p) return -1;
p = skip_token (p); /* "Uid:" */
buf->uid = strtoul (p, &p, 0);
buf->euid = strtoul (p, &p, 0);
p = skip_token (p); /* "Uid:" */
buf->uid = strtoul (p, &p, 0);
buf->euid = strtoul (p, &p, 0);
/* We don't know how many entries on the "Uid:" line
* future Linux version will have, so we catch this here. */
p = strstr (p, "\nGid:");
if (!p) return -1;
/* We don't know how many entries on the "Uid:" line
* future Linux version will have, so we catch this here. */
p = strstr (p, "\nGid:");
if (!p) return -1;
p = skip_token (p); /* "Gid:" */
buf->gid = strtoul (p, &p, 0);
buf->egid = strtoul (p, &p, 0);
p = skip_token (p); /* "Gid:" */
buf->gid = strtoul (p, &p, 0);
buf->egid = strtoul (p, &p, 0);
buf->flags = _glibtop_sysdeps_proc_uid;
buf->flags = _glibtop_sysdeps_proc_uid;
if (proc_stat_to_buffer (buffer, pid))
return -1;
if (proc_stat_to_buffer (buffer, pid))
return -1;
p = proc_stat_after_cmd (buffer);
if (!p) return -1;
p = proc_stat_after_cmd (buffer);
if (!p) return -1;
p = skip_multiple_token (p, 2);
p = skip_multiple_token (p, 2);
buf->pgrp = strtoul (p, &p, 0);
buf->session = strtoul (p, &p, 0);
buf->tty = strtoul (p, &p, 0);
buf->tpgid = strtoul (p, &p, 0);
buf->pgrp = strtoul (p, &p, 0);
buf->session = strtoul (p, &p, 0);
buf->tty = strtoul (p, &p, 0);
buf->tpgid = strtoul (p, &p, 0);
p = skip_multiple_token (p, 9);
p = skip_multiple_token (p, 9);
buf->priority = strtoul (p, &p, 0);
buf->nice = strtoul (p, &p, 0);
buf->priority = strtoul (p, &p, 0);
buf->nice = strtoul (p, &p, 0);
if (buf->tty == 0)
/* the old notty val, update elsewhere bef. moving to 0 */
buf->tty = -1;
if (buf->tty == 0)
/* the old notty val, update elsewhere bef. moving to 0 */
buf->tty = -1;
if (server->os_version_code < LINUX_VERSION(1,3,39)) {
/* map old meanings to new */
buf->priority = 2*15 - buf->priority;
buf->nice = 15 - buf->nice;
}
if (server->os_version_code < LINUX_VERSION(1,1,30) && buf->tty != -1)
/* when tty wasn't full devno */
buf->tty = 4*0x100 + buf->tty;
if (server->os_version_code < LINUX_VERSION(1,3,39)) {
/* map old meanings to new */
buf->priority = 2*15 - buf->priority;
buf->nice = 15 - buf->nice;
}
if (server->os_version_code < LINUX_VERSION(1,1,30) && buf->tty != -1)
/* when tty wasn't full devno */
buf->tty = 4*0x100 + buf->tty;
buf->flags |= _glibtop_sysdeps_proc_uid_stat;
buf->flags |= _glibtop_sysdeps_proc_uid_stat;
return 0;
return 0;
}

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -34,10 +36,10 @@
union semun
{
int val;
struct semid_ds *buf;
unsigned short int *array;
struct seminfo *__buf;
int val;
struct semid_ds *buf;
unsigned short int *array;
struct seminfo *__buf;
};
#endif
@@ -53,9 +55,9 @@ static unsigned long _glibtop_sysdeps_sem_limits =
int
glibtop_init_sem_limits_s (glibtop *server)
{
server->sysdeps.sem_limits = _glibtop_sysdeps_sem_limits;
server->sysdeps.sem_limits = _glibtop_sysdeps_sem_limits;
return 0;
return 0;
}
/* Provides information about sysv ipc limits. */
@@ -63,28 +65,28 @@ glibtop_init_sem_limits_s (glibtop *server)
int
glibtop_get_sem_limits_s (glibtop *server, glibtop_sem_limits *buf)
{
struct seminfo seminfo;
union semun arg;
struct seminfo seminfo;
union semun arg;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_SEM_LIMITS, 0);
glibtop_init_s (&server, GLIBTOP_SYSDEPS_SEM_LIMITS, 0);
memset (buf, 0, sizeof (glibtop_sem_limits));
memset (buf, 0, sizeof (glibtop_sem_limits));
buf->flags = _glibtop_sysdeps_sem_limits;
buf->flags = _glibtop_sysdeps_sem_limits;
arg.array = (ushort *) &seminfo;
semctl (0, 0, IPC_INFO, arg);
arg.array = (ushort *) &seminfo;
semctl (0, 0, IPC_INFO, arg);
buf->semmap = seminfo.semmap;
buf->semmni = seminfo.semmni;
buf->semmns = seminfo.semmns;
buf->semmnu = seminfo.semmnu;
buf->semmsl = seminfo.semmsl;
buf->semopm = seminfo.semopm;
buf->semume = seminfo.semume;
buf->semusz = seminfo.semusz;
buf->semvmx = seminfo.semvmx;
buf->semaem = seminfo.semaem;
buf->semmap = seminfo.semmap;
buf->semmni = seminfo.semmni;
buf->semmns = seminfo.semmns;
buf->semmnu = seminfo.semmnu;
buf->semmsl = seminfo.semmsl;
buf->semopm = seminfo.semopm;
buf->semume = seminfo.semume;
buf->semusz = seminfo.semusz;
buf->semvmx = seminfo.semvmx;
buf->semaem = seminfo.semaem;
return 0;
return 0;
}

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -36,9 +38,9 @@ static unsigned long _glibtop_sysdeps_shm_limits =
int
glibtop_init_shm_limits_s (glibtop *server)
{
server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits;
server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits;
return 0;
return 0;
}
/* Provides information about sysv ipc limits. */
@@ -46,21 +48,21 @@ glibtop_init_shm_limits_s (glibtop *server)
int
glibtop_get_shm_limits_s (glibtop *server, glibtop_shm_limits *buf)
{
struct shminfo shminfo;
struct shminfo shminfo;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_SHM_LIMITS, 0);
glibtop_init_s (&server, GLIBTOP_SYSDEPS_SHM_LIMITS, 0);
memset (buf, 0, sizeof (glibtop_shm_limits));
memset (buf, 0, sizeof (glibtop_shm_limits));
buf->flags = _glibtop_sysdeps_shm_limits;
buf->flags = _glibtop_sysdeps_shm_limits;
shmctl (0, IPC_INFO, (struct shmid_ds *) &shminfo);
shmctl (0, IPC_INFO, (struct shmid_ds *) &shminfo);
buf->shmmax = shminfo.shmmax;
buf->shmmin = shminfo.shmmin;
buf->shmmni = shminfo.shmmni;
buf->shmseg = shminfo.shmseg;
buf->shmall = shminfo.shmall;
buf->shmmax = shminfo.shmmax;
buf->shmmin = shminfo.shmmin;
buf->shmmni = shminfo.shmmni;
buf->shmseg = shminfo.shmseg;
buf->shmall = shminfo.shmall;
return 0;
return 0;
}

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -39,10 +41,10 @@ static unsigned long _glibtop_sysdeps_swap_paging =
int
glibtop_init_swap_s (glibtop *server)
{
server->sysdeps.swap = _glibtop_sysdeps_swap |
_glibtop_sysdeps_swap_paging;
server->sysdeps.swap = _glibtop_sysdeps_swap |
_glibtop_sysdeps_swap_paging;
return 0;
return 0;
}
/* Provides information about swap usage. */
@@ -53,66 +55,66 @@ glibtop_init_swap_s (glibtop *server)
int
glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
{
char buffer [BUFSIZ], *p;
int fd, len;
char buffer [BUFSIZ], *p;
int fd, len;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_SWAP, 0);
glibtop_init_s (&server, GLIBTOP_SYSDEPS_SWAP, 0);
memset (buf, 0, sizeof (glibtop_swap));
memset (buf, 0, sizeof (glibtop_swap));
fd = open (MEMINFO, O_RDONLY);
if (fd < 0) {
glibtop_warn_io_r (server, "open (%s)", MEMINFO);
return -1;
}
len = read (fd, buffer, BUFSIZ-1);
if (len < 0) {
close (fd);
glibtop_warn_io_r (server, "read (%s)", MEMINFO);
return -1;
}
fd = open (MEMINFO, O_RDONLY);
if (fd < 0) {
glibtop_warn_io_r (server, "open (%s)", MEMINFO);
return -1;
}
len = read (fd, buffer, BUFSIZ-1);
if (len < 0) {
close (fd);
glibtop_warn_io_r (server, "read (%s)", MEMINFO);
return -1;
}
buffer [len] = '\0';
close (fd);
p = skip_line (buffer);
p = skip_line (p);
p = skip_token (p); /* "Swap:" */
buffer [len] = '\0';
buf->total = strtoul (p, &p, 0);
buf->used = strtoul (p, &p, 0);
buf->free = strtoul (p, &p, 0);
p = skip_line (buffer);
p = skip_line (p);
p = skip_token (p); /* "Swap:" */
buf->flags = _glibtop_sysdeps_swap;
buf->total = strtoul (p, &p, 0);
buf->used = strtoul (p, &p, 0);
buf->free = strtoul (p, &p, 0);
fd = open (PROC_STAT, O_RDONLY);
if (fd < 0) {
glibtop_warn_io_r (server, "open (%s)", PROC_STAT);
return -1;
}
buf->flags = _glibtop_sysdeps_swap;
len = read (fd, buffer, BUFSIZ-1);
if (len < 0) {
close (fd);
glibtop_warn_io_r (server, "read (%s)", PROC_STAT);
return -1;
}
fd = open (PROC_STAT, O_RDONLY);
if (fd < 0) {
glibtop_warn_io_r (server, "open (%s)", PROC_STAT);
return -1;
}
len = read (fd, buffer, BUFSIZ-1);
if (len < 0) {
close (fd);
glibtop_warn_io_r (server, "read (%s)", PROC_STAT);
return -1;
}
buffer [len] = '\0';
close (fd);
p = strstr (buffer, "\nswap");
if (p == NULL) return 0;
buffer [len] = '\0';
p = skip_token (p);
p = strstr (buffer, "\nswap");
if (p == NULL) return 0;
buf->pagein = strtoul (p, &p, 0);
buf->pageout = strtoul (p, &p, 0);
p = skip_token (p);
buf->flags |= _glibtop_sysdeps_swap_paging;
buf->pagein = strtoul (p, &p, 0);
buf->pageout = strtoul (p, &p, 0);
return 0;
buf->flags |= _glibtop_sysdeps_swap_paging;
return 0;
}

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -33,62 +35,62 @@ static glibtop_sysinfo sysinfo;
static void
init_sysinfo (glibtop *server)
{
char buffer [BUFSIZ];
static int init = 0;
glibtop_entry *cpuinfo = NULL;
FILE *f;
char buffer [BUFSIZ];
static int init = 0;
glibtop_entry *cpuinfo = NULL;
FILE *f;
if (init) return;
if (init) return;
init = TRUE;
init = TRUE;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
memset (&sysinfo, 0, sizeof (glibtop_sysinfo));
memset (&sysinfo, 0, sizeof (glibtop_sysinfo));
g_return_if_fail (f = fopen ("/proc/cpuinfo", "r"));
g_return_if_fail (f = fopen ("/proc/cpuinfo", "r"));
while (fgets (buffer, BUFSIZ, f)) {
char *p, *start, *key, *value;
while (fgets (buffer, BUFSIZ, f)) {
char *p, *start, *key, *value;
if (cpuinfo == NULL) {
cpuinfo = &sysinfo.cpuinfo [sysinfo.ncpu++];
if (cpuinfo == NULL) {
cpuinfo = &sysinfo.cpuinfo [sysinfo.ncpu++];
cpuinfo->labels = g_ptr_array_new ();
cpuinfo->labels = g_ptr_array_new ();
cpuinfo->values = g_hash_table_new (NULL, NULL);
cpuinfo->values = g_hash_table_new (NULL, NULL);
if (sysinfo.ncpu > GLIBTOP_NCPU)
sysinfo.ncpu = GLIBTOP_NCPU;
}
p = strchr (buffer, ':');
if (!p) continue;
/* Remove leading spaces from `p'. */
*p = '\0'; start = p; p++;
while (isspace (*p)) p++;
/* Remove trailing spaces from `buffer'. */
while ((start > buffer) && (*start) && isspace (*start))
*start-- = '\0';
key = g_strdup (buffer);
value = g_strdup (p);
g_ptr_array_add (cpuinfo->labels, key);
g_hash_table_insert (cpuinfo->values, key, value);
if (sysinfo.ncpu > GLIBTOP_NCPU)
sysinfo.ncpu = GLIBTOP_NCPU;
}
fclose (f);
p = strchr (buffer, ':');
if (!p) continue;
sysinfo.flags = _glibtop_sysdeps_sysinfo;
/* Remove leading spaces from `p'. */
*p = '\0'; start = p; p++;
while (isspace (*p)) p++;
/* Remove trailing spaces from `buffer'. */
while ((start > buffer) && (*start) && isspace (*start))
*start-- = '\0';
key = g_strdup (buffer);
value = g_strdup (p);
g_ptr_array_add (cpuinfo->labels, key);
g_hash_table_insert (cpuinfo->values, key, value);
}
fclose (f);
sysinfo.flags = _glibtop_sysdeps_sysinfo;
}
glibtop_sysinfo *
glibtop_get_sysinfo_s (glibtop *server)
{
init_sysinfo (server);
return &sysinfo;
init_sysinfo (server);
return &sysinfo;
}

View File

@@ -1,3 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $Id$ */
/* Copyright (C) 1998-99 Martin Baulig
@@ -33,9 +35,9 @@ static unsigned long _glibtop_sysdeps_uptime =
int
glibtop_init_uptime_s (glibtop *server)
{
server->sysdeps.uptime = _glibtop_sysdeps_uptime;
server->sysdeps.uptime = _glibtop_sysdeps_uptime;
return 0;
return 0;
}
/* Provides uptime and idle time. */
@@ -45,34 +47,34 @@ glibtop_init_uptime_s (glibtop *server)
int
glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
{
char buffer [BUFSIZ], *p;
int fd, len;
char buffer [BUFSIZ], *p;
int fd, len;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_UPTIME, 0);
glibtop_init_s (&server, GLIBTOP_SYSDEPS_UPTIME, 0);
memset (buf, 0, sizeof (glibtop_uptime));
memset (buf, 0, sizeof (glibtop_uptime));
fd = open (FILENAME, O_RDONLY);
if (fd < 0) {
glibtop_warn_io_r (server, "open (%s)", FILENAME);
return -1;
}
len = read (fd, buffer, BUFSIZ-1);
if (len < 0) {
close (fd);
glibtop_warn_io_r (server, "read (%s)", FILENAME);
return -1;
}
fd = open (FILENAME, O_RDONLY);
if (fd < 0) {
glibtop_warn_io_r (server, "open (%s)", FILENAME);
return -1;
}
len = read (fd, buffer, BUFSIZ-1);
if (len < 0) {
close (fd);
glibtop_warn_io_r (server, "read (%s)", FILENAME);
return -1;
}
buffer [len] = '\0';
close (fd);
buf->uptime = strtod (buffer, &p);
buf->idletime = strtod (p, &p);
buffer [len] = '\0';
buf->flags = _glibtop_sysdeps_uptime;
buf->uptime = strtod (buffer, &p);
buf->idletime = strtod (p, &p);
return 0;
buf->flags = _glibtop_sysdeps_uptime;
return 0;
}