Stat "/proc/<pid>" instead of "/proc/<pid>/state" to get uid' and
gid'.
1999-11-28 Martin Baulig <martin@home-of-linux.org> * procstate.c (glibtop_get_procstate_s): Stat "/proc/<pid>" instead of "/proc/<pid>/state" to get `uid' and `gid'. Thanks to Jason Becker for pointing out that GTop reported wrong uid's.
This commit is contained in:
committed by
Martin Baulig
parent
afeb4d50a5
commit
caf17330b3
@@ -1,6 +0,0 @@
|
||||
.deps
|
||||
.libs
|
||||
Makefile
|
||||
Makefile.in
|
||||
libgtop_sysdeps.la
|
||||
*.lo
|
@@ -1,3 +1,9 @@
|
||||
1999-11-28 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* procstate.c (glibtop_get_procstate_s): Stat "/proc/<pid>" instead
|
||||
of "/proc/<pid>/state" to get `uid' and `gid'. Thanks to Jason Becker
|
||||
for pointing out that GTop reported wrong uid's.
|
||||
|
||||
1999-09-28 Radek Doulik <rodo@praha.eridan.cz>
|
||||
|
||||
* proclist.c (glibtop_get_proclist_s): fixed idle processes filtering
|
||||
|
@@ -1,17 +0,0 @@
|
||||
LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@
|
||||
|
||||
INCLUDES = @INCLUDES@
|
||||
|
||||
lib_LTLIBRARIES = libgtop_sysdeps.la
|
||||
|
||||
libgtop_sysdeps_la_SOURCES = open.c close.c cpu.c mem.c swap.c \
|
||||
uptime.c loadavg.c shm_limits.c msg_limits.c \
|
||||
sem_limits.c proclist.c procstate.c procuid.c \
|
||||
proctime.c procmem.c procsignal.c prockernel.c \
|
||||
procsegment.c procargs.c procmap.c siglist.c \
|
||||
sysinfo.c netload.c ppp.c
|
||||
libgtop_sysdeps_la_LIBADD = @GLIB_LIBS@
|
||||
|
||||
libgtop_sysdeps_la_LDFLAGS = $(LT_VERSION_INFO)
|
||||
|
||||
include_HEADERS = glibtop_server.h glibtop_machine.h
|
@@ -1,30 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <glibtop/close.h>
|
||||
|
||||
/* Closes pipe to gtop server. */
|
||||
|
||||
void
|
||||
glibtop_close_s (glibtop *server)
|
||||
{ }
|
@@ -1,111 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/cpu.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_cpu =
|
||||
(1L << GLIBTOP_CPU_TOTAL) + (1L << GLIBTOP_CPU_USER) +
|
||||
(1L << GLIBTOP_CPU_NICE) + (1L << GLIBTOP_CPU_SYS) +
|
||||
(1L << GLIBTOP_CPU_IDLE) + (1L << GLIBTOP_CPU_FREQUENCY);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_cpu_smp =
|
||||
(1L << GLIBTOP_XCPU_TOTAL) + (1L << GLIBTOP_XCPU_USER) +
|
||||
(1L << GLIBTOP_XCPU_NICE) + (1L << GLIBTOP_XCPU_SYS) +
|
||||
(1L << GLIBTOP_XCPU_IDLE);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_cpu_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.cpu = _glibtop_sysdeps_cpu;
|
||||
|
||||
if (server->ncpu)
|
||||
server->sysdeps.cpu |= _glibtop_sysdeps_cpu_smp;
|
||||
}
|
||||
|
||||
/* Provides information about cpu usage. */
|
||||
|
||||
#define FILENAME "/proc/stat"
|
||||
|
||||
void
|
||||
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
int fd, len, i;
|
||||
u_int64_t total;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_cpu));
|
||||
|
||||
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);
|
||||
|
||||
close (fd);
|
||||
|
||||
buffer [len] = '\0';
|
||||
|
||||
p = skip_token (buffer); /* "cpu" */
|
||||
|
||||
buf->user = strtoul (p, &p, 0);
|
||||
buf->nice = strtoul (p, &p, 0);
|
||||
buf->sys = strtoul (p, &p, 0);
|
||||
buf->idle = strtoul (p, &p, 0);
|
||||
|
||||
total = buf->user;
|
||||
total += buf->nice;
|
||||
total += buf->sys;
|
||||
total += buf->idle;
|
||||
buf->total = total;
|
||||
|
||||
buf->frequency = 100;
|
||||
buf->flags = _glibtop_sysdeps_cpu;
|
||||
|
||||
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);
|
||||
|
||||
total = buf->xcpu_user [i];
|
||||
total += buf->xcpu_nice [i];
|
||||
total += buf->xcpu_sys [i];
|
||||
total += buf->xcpu_idle [i];
|
||||
|
||||
buf->xcpu_total [i] = total;
|
||||
}
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_cpu_smp;
|
||||
}
|
@@ -1,58 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GLIBTOP_MACHINE_H__
|
||||
#define __GLIBTOP_MACHINE_H__
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
|
||||
BEGIN_LIBGTOP_DECLS
|
||||
|
||||
#if _IN_LIBGTOP
|
||||
|
||||
static inline char *
|
||||
skip_token(const char *p)
|
||||
{
|
||||
while (isspace(*p)) p++;
|
||||
while (*p && !isspace(*p)) p++;
|
||||
return (char *)p;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
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];
|
||||
};
|
||||
|
||||
END_LIBGTOP_DECLS
|
||||
|
||||
#endif
|
@@ -1,134 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GLIBTOP_SERVER_H__
|
||||
#define __GLIBTOP_SERVER_H__
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
|
||||
BEGIN_LIBGTOP_DECLS
|
||||
|
||||
#ifdef _IN_LIBGTOP
|
||||
|
||||
static inline char *
|
||||
skip_token (const 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;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
p = skip_token (p);
|
||||
|
||||
return (char *)p;
|
||||
}
|
||||
|
||||
static inline char *
|
||||
skip_line (const 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;
|
||||
|
||||
sprintf (filename, fmt, pid);
|
||||
|
||||
fd = open (filename, O_RDONLY);
|
||||
if (fd < 0) return -1;
|
||||
|
||||
len = read (fd, buffer, BUFSIZ-1);
|
||||
if (len < 0) return -1;
|
||||
|
||||
close (fd);
|
||||
|
||||
buffer [len] = '\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);
|
||||
}
|
||||
|
||||
static inline int
|
||||
proc_status_to_buffer (char *buffer, pid_t 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);
|
||||
}
|
||||
|
||||
static inline char *
|
||||
proc_stat_after_cmd (char *p)
|
||||
{
|
||||
p = strrchr (p, ')');
|
||||
if (!p) return p;
|
||||
|
||||
*p++ = '\0';
|
||||
return p;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#define GLIBTOP_SUID_CPU 0
|
||||
#define GLIBTOP_SUID_MEM 0
|
||||
#define GLIBTOP_SUID_SWAP 0
|
||||
#define GLIBTOP_SUID_UPTIME 0
|
||||
#define GLIBTOP_SUID_LOADAVG 0
|
||||
#define GLIBTOP_SUID_SHM_LIMITS 0
|
||||
#define GLIBTOP_SUID_MSG_LIMITS 0
|
||||
#define GLIBTOP_SUID_SEM_LIMITS 0
|
||||
#define GLIBTOP_SUID_PROCLIST 0
|
||||
#define GLIBTOP_SUID_PROC_STATE 0
|
||||
#define GLIBTOP_SUID_PROC_UID 0
|
||||
#define GLIBTOP_SUID_PROC_MEM 0
|
||||
#define GLIBTOP_SUID_PROC_TIME 0
|
||||
#define GLIBTOP_SUID_PROC_SIGNAL 0
|
||||
#define GLIBTOP_SUID_PROC_KERNEL 0
|
||||
#define GLIBTOP_SUID_PROC_SEGMENT 0
|
||||
#define GLIBTOP_SUID_PROC_ARGS 0
|
||||
#define GLIBTOP_SUID_PROC_MAP 0
|
||||
#define GLIBTOP_SUID_NETLOAD 0
|
||||
#define GLIBTOP_SUID_PPP 0
|
||||
|
||||
END_LIBGTOP_DECLS
|
||||
|
||||
#endif
|
@@ -1,19 +0,0 @@
|
||||
# libsysdeps.la - a libtool library file
|
||||
# Generated by ltmain.sh - GNU libtool 1.0h
|
||||
|
||||
# The name that we can dlopen(3).
|
||||
dlname=''
|
||||
|
||||
# Names of this library.
|
||||
library_names='libsysdeps.so.0.0.0 libsysdeps.so.0 libsysdeps.so'
|
||||
|
||||
# The name of the static archive.
|
||||
old_library='libsysdeps.a'
|
||||
|
||||
# Version information for libsysdeps.
|
||||
current=0
|
||||
age=0
|
||||
revision=0
|
||||
|
||||
# Directory that this library needs to be installed in:
|
||||
libdir='/usr/local/lib'
|
@@ -1,94 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/loadavg.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_loadavg =
|
||||
(1L << GLIBTOP_LOADAVG_LOADAVG);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_loadavg_tasks =
|
||||
(1L << GLIBTOP_LOADAVG_NR_RUNNING) +
|
||||
(1L << GLIBTOP_LOADAVG_NR_TASKS) +
|
||||
(1L << GLIBTOP_LOADAVG_LAST_PID);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_loadavg_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
|
||||
}
|
||||
|
||||
/* Provides load load averange. */
|
||||
|
||||
#define FILENAME "/proc/loadavg"
|
||||
|
||||
void
|
||||
glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
|
||||
{
|
||||
char buffer [BUFSIZ], *p, *old;
|
||||
int fd, len;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_LOADAVG, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_loadavg));
|
||||
|
||||
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);
|
||||
|
||||
close (fd);
|
||||
|
||||
buffer [len] = '\0';
|
||||
|
||||
buf->loadavg [0] = (float) strtod (buffer, &p);
|
||||
buf->loadavg [1] = (float) strtod (p, &p);
|
||||
buf->loadavg [2] = (float) strtod (p, &p);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_loadavg;
|
||||
|
||||
while (isspace(*p)) p++;
|
||||
|
||||
/* Older Linux versions don't have the nr_running/nr_tasks fields. */
|
||||
|
||||
old = p;
|
||||
while (*p) {
|
||||
if (*p == '/')
|
||||
break;
|
||||
if (!isdigit (*p))
|
||||
return;
|
||||
p++;
|
||||
}
|
||||
|
||||
buf->nr_running = strtoul (old, &p, 0); p++;
|
||||
buf->nr_tasks = strtoul (p, &p, 0);
|
||||
buf->last_pid = strtoul (p, &p, 0);
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_loadavg_tasks;
|
||||
}
|
@@ -1,81 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/mem.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_mem =
|
||||
(1L << GLIBTOP_MEM_TOTAL) + (1L << GLIBTOP_MEM_USED) +
|
||||
(1L << GLIBTOP_MEM_FREE) + (1L << GLIBTOP_MEM_SHARED) +
|
||||
(1L << GLIBTOP_MEM_BUFFER) + (1L << GLIBTOP_MEM_CACHED) +
|
||||
(1L << GLIBTOP_MEM_USER);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_mem_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.mem = _glibtop_sysdeps_mem;
|
||||
}
|
||||
|
||||
/* Provides information about memory usage. */
|
||||
|
||||
#define FILENAME "/proc/meminfo"
|
||||
|
||||
void
|
||||
glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
int fd, len;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_mem));
|
||||
|
||||
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);
|
||||
|
||||
close (fd);
|
||||
|
||||
buffer [len] = '\0';
|
||||
|
||||
p = skip_line (buffer);
|
||||
p = skip_token (p); /* "Mem:" */
|
||||
|
||||
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->user = buf->total - buf->free - buf->shared - buf->buffer;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_mem;
|
||||
}
|
@@ -1,65 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <glibtop/msg_limits.h>
|
||||
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/msg.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_msg_limits =
|
||||
(1L << GLIBTOP_IPC_MSGPOOL) + (1L << GLIBTOP_IPC_MSGMAP) +
|
||||
(1L << GLIBTOP_IPC_MSGMAX) + (1L << GLIBTOP_IPC_MSGMNB) +
|
||||
(1L << GLIBTOP_IPC_MSGMNI) + (1L << GLIBTOP_IPC_MSGSSZ) +
|
||||
(1L << GLIBTOP_IPC_MSGTQL);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_msg_limits_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.msg_limits = _glibtop_sysdeps_msg_limits;
|
||||
}
|
||||
|
||||
/* Provides information about sysv ipc limits. */
|
||||
|
||||
void
|
||||
glibtop_get_msg_limits_s (glibtop *server, glibtop_msg_limits *buf)
|
||||
{
|
||||
struct msginfo msginfo;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_MSG_LIMITS, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_msg_limits));
|
||||
|
||||
buf->flags = _glibtop_sysdeps_msg_limits;
|
||||
|
||||
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;
|
||||
}
|
@@ -1,351 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, October 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/netload.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#if !defined (_LIBC) && defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1
|
||||
/* GNU LibC */
|
||||
#include <net/if.h>
|
||||
#include <netinet/ip_icmp.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <net/if.h>
|
||||
#else /* Libc 5 */
|
||||
#include <linux/if.h>
|
||||
#include <linux/in.h>
|
||||
#include <linux/ip.h>
|
||||
#include <linux/icmp.h>
|
||||
#include <linux/tcp.h>
|
||||
#include <linux/udp.h>
|
||||
#endif
|
||||
|
||||
#define _GLIBTOP_IP_FW_ACCTIN 0x1000 /* Account incoming packets only. */
|
||||
#define _GLIBTOP_IP_FW_ACCTOUT 0x2000 /* Account outgoing packets only. */
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload =
|
||||
(1L << GLIBTOP_NETLOAD_ERRORS_IN) +
|
||||
(1L << GLIBTOP_NETLOAD_ERRORS_OUT) +
|
||||
(1L << GLIBTOP_NETLOAD_COLLISIONS);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload_data =
|
||||
(1L << GLIBTOP_NETLOAD_ADDRESS) +
|
||||
(1L << GLIBTOP_NETLOAD_SUBNET) +
|
||||
(1L << GLIBTOP_NETLOAD_MTU);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload_bytes =
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_IN) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_OUT) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_TOTAL);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload_packets =
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_IN) +
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_OUT) +
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_TOTAL);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload_total =
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_TOTAL) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_TOTAL);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload_in =
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_TOTAL) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_TOTAL) +
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_IN) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_IN);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload_out =
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_TOTAL) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_TOTAL) +
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_OUT) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_OUT);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_netload_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.netload = _glibtop_sysdeps_netload |
|
||||
_glibtop_sysdeps_netload_data |
|
||||
_glibtop_sysdeps_netload_bytes |
|
||||
_glibtop_sysdeps_netload_packets;
|
||||
}
|
||||
|
||||
/* Provides network statistics. */
|
||||
|
||||
void
|
||||
glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
|
||||
const char *interface)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
int have_bytes, fields, skfd;
|
||||
FILE *f;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_netload));
|
||||
|
||||
skfd = socket (AF_INET, SOCK_DGRAM, 0);
|
||||
if (skfd) {
|
||||
struct ifreq ifr;
|
||||
unsigned flags;
|
||||
|
||||
strcpy (ifr.ifr_name, interface);
|
||||
if (!ioctl (skfd, SIOCGIFFLAGS, &ifr)) {
|
||||
buf->flags |= (1L << GLIBTOP_NETLOAD_IF_FLAGS);
|
||||
flags = ifr.ifr_flags;
|
||||
} else
|
||||
flags = 0;
|
||||
|
||||
if (flags & IFF_UP)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_UP);
|
||||
|
||||
if (flags & IFF_BROADCAST)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_BROADCAST);
|
||||
|
||||
if (flags & IFF_DEBUG)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_DEBUG);
|
||||
|
||||
if (flags & IFF_LOOPBACK)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_LOOPBACK);
|
||||
|
||||
if (flags & IFF_POINTOPOINT)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_POINTOPOINT);
|
||||
|
||||
if (flags & IFF_RUNNING)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_RUNNING);
|
||||
|
||||
if (flags & IFF_NOARP)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_NOARP);
|
||||
|
||||
if (flags & IFF_PROMISC)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_PROMISC);
|
||||
|
||||
if (flags & IFF_ALLMULTI)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_ALLMULTI);
|
||||
|
||||
if (flags & IFF_MULTICAST)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_MULTICAST);
|
||||
|
||||
strcpy (ifr.ifr_name, interface);
|
||||
if (!ioctl (skfd, SIOCGIFADDR, &ifr)) {
|
||||
struct sockaddr_in addr =
|
||||
*(struct sockaddr_in *) &ifr.ifr_addr;
|
||||
buf->address = addr.sin_addr.s_addr;
|
||||
buf->flags |= (1L << GLIBTOP_NETLOAD_ADDRESS);
|
||||
}
|
||||
|
||||
strcpy (ifr.ifr_name, interface);
|
||||
if (!ioctl (skfd, SIOCGIFNETMASK, &ifr)) {
|
||||
struct sockaddr_in addr =
|
||||
*(struct sockaddr_in *) &ifr.ifr_addr;
|
||||
buf->subnet = addr.sin_addr.s_addr;
|
||||
buf->flags |= (1L << GLIBTOP_NETLOAD_SUBNET);
|
||||
}
|
||||
|
||||
strcpy (ifr.ifr_name, interface);
|
||||
if (!ioctl (skfd, SIOCGIFMTU, &ifr)) {
|
||||
buf->mtu = ifr.ifr_mtu;
|
||||
buf->flags |= (1L << GLIBTOP_NETLOAD_MTU);
|
||||
}
|
||||
|
||||
close (skfd);
|
||||
}
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
if (server->os_version_code < 131442) {
|
||||
|
||||
/* If IP accounting is enabled in the kernel and it is
|
||||
* enabled for the requested interface, we use it to
|
||||
* get the data. In this case, we don't use /proc/net/dev
|
||||
* to get errors and collisions.
|
||||
*/
|
||||
|
||||
f = fopen ("/proc/net/ip_acct", "r");
|
||||
if (f) {
|
||||
int success = 0;
|
||||
|
||||
/* Skip over the header line. */
|
||||
fgets (buffer, BUFSIZ-1, f);
|
||||
|
||||
while (fgets (buffer, BUFSIZ-1, f)) {
|
||||
unsigned long flags, packets, bytes;
|
||||
char *p, *dev;
|
||||
|
||||
/* Skip over the network thing. */
|
||||
dev = skip_token (buffer) + 1;
|
||||
p = skip_token (dev);
|
||||
*p++ = 0;
|
||||
|
||||
if (strcmp (dev, interface))
|
||||
continue;
|
||||
|
||||
success = 1;
|
||||
|
||||
p = skip_token (p);
|
||||
|
||||
flags = strtoul (p, &p, 16);
|
||||
|
||||
p = skip_multiple_token (p, 2);
|
||||
|
||||
packets = strtoul (p, &p, 0);
|
||||
bytes = strtoul (p, &p, 0);
|
||||
|
||||
if (flags & _GLIBTOP_IP_FW_ACCTIN) {
|
||||
/* Incoming packets only. */
|
||||
|
||||
buf->packets_total += packets;
|
||||
buf->packets_in += packets;
|
||||
|
||||
buf->bytes_total += bytes;
|
||||
buf->bytes_in += bytes;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_netload_in;
|
||||
|
||||
} else if (flags & _GLIBTOP_IP_FW_ACCTOUT) {
|
||||
/* Outgoing packets only. */
|
||||
|
||||
buf->packets_total += packets;
|
||||
buf->packets_out += packets;
|
||||
|
||||
buf->bytes_total += bytes;
|
||||
buf->bytes_out += bytes;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_netload_out;
|
||||
|
||||
} else {
|
||||
/* Only have total values. */
|
||||
|
||||
buf->packets_total += packets;
|
||||
buf->bytes_total += bytes;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_netload_total;
|
||||
}
|
||||
}
|
||||
|
||||
fclose (f);
|
||||
|
||||
if (success) return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Ok, either IP accounting is not enabled in the kernel or
|
||||
* it was not enabled for the requested interface. */
|
||||
|
||||
f = fopen ("/proc/net/dev", "r");
|
||||
if (!f) return;
|
||||
|
||||
/* 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. */
|
||||
|
||||
p = strchr (buffer, '|');
|
||||
if (!p) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Do we already have byte counters ? */
|
||||
have_bytes = strncmp (++p, "bytes", 5) == 0;
|
||||
|
||||
/* Count remaining 'Receive' fields so we know where
|
||||
* the first 'Transmit' field starts. */
|
||||
|
||||
fields = 0;
|
||||
while (*p != '|') {
|
||||
if (!isspace (*p++)) continue;
|
||||
while (isspace (*p++)) ;
|
||||
fields++;
|
||||
}
|
||||
|
||||
/* Should never happen. */
|
||||
if (fields < 2) return;
|
||||
fields--;
|
||||
|
||||
while (fgets (buffer, BUFSIZ-1, f)) {
|
||||
char *p, *dev;
|
||||
|
||||
dev = buffer;
|
||||
while (isspace (*dev)) dev++;
|
||||
|
||||
p = strchr (dev, ':');
|
||||
if (!p) continue;
|
||||
*p++ = 0;
|
||||
|
||||
/* If it's not a digit, then it's most likely an error
|
||||
* message like 'No statistics available'. */
|
||||
while (isspace (*p)) p++;
|
||||
if (!isdigit (*p)) continue;
|
||||
|
||||
if (strcmp (dev, interface))
|
||||
continue;
|
||||
|
||||
/* Only read byte counts if we really have them. */
|
||||
|
||||
if (have_bytes) {
|
||||
buf->bytes_in = strtoul (p, &p, 0);
|
||||
fields--;
|
||||
}
|
||||
|
||||
buf->packets_in = strtoul (p, &p, 0);
|
||||
buf->errors_in = strtoul (p, &p, 0);
|
||||
|
||||
p = skip_multiple_token (p, fields);
|
||||
|
||||
if (have_bytes)
|
||||
buf->bytes_out = strtoul (p, &p, 0);
|
||||
|
||||
buf->packets_out = strtoul (p, &p, 0);
|
||||
buf->errors_out = strtoul (p, &p, 0);
|
||||
|
||||
p = skip_multiple_token (p, 2);
|
||||
|
||||
buf->collisions = strtoul (p, &p, 0);
|
||||
|
||||
/* Compute total valules. */
|
||||
|
||||
buf->bytes_total = buf->bytes_in + buf->bytes_out;
|
||||
buf->packets_total = buf->packets_in + buf->packets_out;
|
||||
|
||||
/* And now the flags. */
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_netload;
|
||||
buf->flags |= _glibtop_sysdeps_netload_packets;
|
||||
|
||||
if (have_bytes)
|
||||
buf->flags |= _glibtop_sysdeps_netload_bytes;
|
||||
}
|
||||
|
||||
fclose (f);
|
||||
}
|
@@ -1,101 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/cpu.h>
|
||||
#include <glibtop/open.h>
|
||||
|
||||
/* =====================================================
|
||||
* Linux kernel version information for procps utilities
|
||||
* Copyright (c) 1996 Charles Blake <cblake@bbn.com>
|
||||
*/
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
|
||||
|
||||
static int linux_version_code = 0;
|
||||
|
||||
static void set_linux_version(void) {
|
||||
static struct utsname uts;
|
||||
int x = 0, y = 0, z = 0; /* cleared in case sscanf() < 3 */
|
||||
|
||||
if (linux_version_code) return;
|
||||
if (uname(&uts) == -1) /* failure most likely implies impending death */
|
||||
exit(1);
|
||||
if (sscanf(uts.release, "%d.%d.%d", &x, &y, &z) < 3)
|
||||
fprintf(stderr, /* *very* unlikely to happen by accident */
|
||||
"Non-standard uts for running kernel:\n"
|
||||
"release %s=%d.%d.%d gives version code %d\n",
|
||||
uts.release, x, y, z, LINUX_VERSION(x,y,z));
|
||||
linux_version_code = LINUX_VERSION(x, y, z);
|
||||
}
|
||||
|
||||
/* ======================================================= */
|
||||
|
||||
/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
|
||||
|
||||
#define FILENAME "/proc/stat"
|
||||
|
||||
void
|
||||
glibtop_open_s (glibtop *server, const char *program_name,
|
||||
const unsigned long features,
|
||||
const unsigned flags)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
int fd, len, i;
|
||||
|
||||
server->name = program_name;
|
||||
|
||||
set_linux_version ();
|
||||
server->os_version_code = (unsigned long) linux_version_code;
|
||||
|
||||
server->ncpu = 0;
|
||||
|
||||
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);
|
||||
|
||||
close (fd);
|
||||
|
||||
buffer [len] = '\0';
|
||||
|
||||
p = skip_multiple_token (buffer, 5) + 1;
|
||||
|
||||
for (i = 0; i < GLIBTOP_NCPU; i++) {
|
||||
|
||||
if (strncmp (p, "cpu", 3) || !isdigit (p [3]))
|
||||
break;
|
||||
|
||||
server->ncpu++;
|
||||
|
||||
p = skip_multiple_token (p, 5) + 1;
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
printf ("\nThis machine has %d CPUs.\n\n", server->ncpu);
|
||||
#endif
|
||||
}
|
@@ -1,201 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, October 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/xmalloc.h>
|
||||
#include <glibtop/ppp.h>
|
||||
|
||||
#include <linux/isdn.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_ppp =
|
||||
(1L << GLIBTOP_PPP_STATE) + (1L << GLIBTOP_PPP_BYTES_IN) +
|
||||
(1L << GLIBTOP_PPP_BYTES_OUT);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_ppp_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.ppp = _glibtop_sysdeps_ppp;
|
||||
}
|
||||
|
||||
static int
|
||||
get_ISDN_stats (glibtop *server, int *in, int *out)
|
||||
{
|
||||
unsigned long *isdn_stats, *ptr;
|
||||
int fd, i;
|
||||
|
||||
*in = *out = 0;
|
||||
|
||||
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++;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
/* 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");
|
||||
|
||||
if (!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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
fclose (f);
|
||||
|
||||
*online = FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Provides PPP/ISDN information. */
|
||||
|
||||
void
|
||||
glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device)
|
||||
{
|
||||
int in, out, online;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PPP, 0);
|
||||
|
||||
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 (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);
|
||||
}
|
||||
}
|
@@ -1,77 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/prockernel.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_kernel =
|
||||
(1L << GLIBTOP_PROC_KERNEL_K_FLAGS) + (1L << GLIBTOP_PROC_KERNEL_MIN_FLT) +
|
||||
(1L << GLIBTOP_PROC_KERNEL_MAJ_FLT) + (1L << GLIBTOP_PROC_KERNEL_CMIN_FLT) +
|
||||
(1L << GLIBTOP_PROC_KERNEL_CMAJ_FLT) + (1L << GLIBTOP_PROC_KERNEL_KSTK_ESP) +
|
||||
(1L << GLIBTOP_PROC_KERNEL_KSTK_EIP) + (1L << GLIBTOP_PROC_KERNEL_WCHAN);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_proc_kernel_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_kernel = _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)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_KERNEL, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_kernel));
|
||||
|
||||
if (proc_stat_to_buffer (buffer, pid))
|
||||
return;
|
||||
|
||||
p = proc_stat_after_cmd (buffer);
|
||||
if (!p) return;
|
||||
|
||||
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);
|
||||
|
||||
p = skip_multiple_token (p, 15);
|
||||
|
||||
buf->kstk_esp = strtoul (p, &p, 0);
|
||||
buf->kstk_eip = strtoul (p, &p, 0);
|
||||
|
||||
p = skip_multiple_token (p, 4);
|
||||
|
||||
buf->nwchan = strtoul (p, &p, 0);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_kernel;
|
||||
}
|
@@ -1,233 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/xmalloc.h>
|
||||
#include <glibtop/proclist.h>
|
||||
|
||||
#include <glibtop/procuid.h>
|
||||
#include <glibtop/procstate.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proclist =
|
||||
(1L << GLIBTOP_PROCLIST_TOTAL) + (1L << GLIBTOP_PROCLIST_NUMBER) +
|
||||
(1L << GLIBTOP_PROCLIST_SIZE);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_proclist_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proclist = _glibtop_sysdeps_proclist;
|
||||
}
|
||||
|
||||
#define BLOCK_COUNT 256
|
||||
#define BLOCK_SIZE (BLOCK_COUNT * sizeof (unsigned))
|
||||
|
||||
/* Fetch list of currently running processes.
|
||||
*
|
||||
* The interface of this function is a little bit different from the others:
|
||||
* buf->flags is only set if the call succeeded, in this case pids_chain,
|
||||
* a list of the pids of all currently running processes is returned,
|
||||
* buf->number is the number of elements of this list and buf->size is
|
||||
* the size of one single element (sizeof (unsigned)). The total size is
|
||||
* stored in buf->total.
|
||||
*
|
||||
* The calling function has to free the memory to which a pointer is returned.
|
||||
*
|
||||
* On error, NULL is returned and buf->flags is zero. */
|
||||
|
||||
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;
|
||||
|
||||
glibtop_proc_uid procuid;
|
||||
glibtop_proc_state procstate;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROCLIST, 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;
|
||||
|
||||
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_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);
|
||||
|
||||
/* count is only zero if an error occured (one a running Linux system,
|
||||
* we 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 the `pids_chain'. */
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proclist;
|
||||
|
||||
buf->size = sizeof (unsigned);
|
||||
buf->number = total;
|
||||
|
||||
buf->total = total * sizeof (unsigned);
|
||||
|
||||
return pids_chain;
|
||||
}
|
@@ -1,138 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/xmalloc.h>
|
||||
#include <glibtop/procmap.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_map =
|
||||
(1L << GLIBTOP_PROC_MAP_NUMBER) + (1L << GLIBTOP_PROC_MAP_TOTAL) +
|
||||
(1L << GLIBTOP_PROC_MAP_SIZE);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_map_entry =
|
||||
(1L << GLIBTOP_MAP_ENTRY_START) + (1L << GLIBTOP_MAP_ENTRY_END) +
|
||||
(1L << GLIBTOP_MAP_ENTRY_OFFSET) + (1L << GLIBTOP_MAP_ENTRY_PERM) +
|
||||
(1L << GLIBTOP_MAP_ENTRY_INODE) + (1L << GLIBTOP_MAP_ENTRY_DEVICE) +
|
||||
(1L << GLIBTOP_MAP_ENTRY_FILENAME);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_proc_map_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_map = _glibtop_sysdeps_proc_map;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
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;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_MAP, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_map));
|
||||
|
||||
sprintf (fn, "/proc/%d/maps", pid);
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
flags [4] = 0;
|
||||
|
||||
/* Compute access permissions. */
|
||||
|
||||
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;
|
||||
|
||||
/* Read filename. */
|
||||
|
||||
fn [0] = fgetc (maps);
|
||||
|
||||
if (fn [0] != '\n' && fn [0] != EOF) {
|
||||
|
||||
fscanf (maps, "%*[ ]%[^\n]\n", fn);
|
||||
|
||||
} else fn [0] = 0;
|
||||
|
||||
size = (n+1) * sizeof (glibtop_map_entry);
|
||||
|
||||
entry_list = glibtop_realloc_r (server, entry_list, size);
|
||||
|
||||
memset (&(entry_list [n]), 0, sizeof (glibtop_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;
|
||||
|
||||
strncpy (entry_list [n].filename, fn, GLIBTOP_MAP_FILENAME_LEN);
|
||||
entry_list [n].filename [GLIBTOP_MAP_FILENAME_LEN] = 0;
|
||||
|
||||
n++;
|
||||
|
||||
} while (rv != EOF && rv && fn [0] != EOF);
|
||||
|
||||
fclose (maps);
|
||||
|
||||
buf->number = n;
|
||||
buf->size = sizeof (glibtop_map_entry);
|
||||
buf->total = n * sizeof (glibtop_map_entry);
|
||||
|
||||
return entry_list;
|
||||
}
|
@@ -1,104 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/procmem.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_mem =
|
||||
(1L << GLIBTOP_PROC_MEM_VSIZE) + (1L << GLIBTOP_PROC_MEM_RSS) +
|
||||
(1L << GLIBTOP_PROC_MEM_RSS_RLIM);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_mem_statm =
|
||||
(1L << GLIBTOP_PROC_MEM_SIZE) + (1L << GLIBTOP_PROC_MEM_RESIDENT) +
|
||||
(1L << GLIBTOP_PROC_MEM_SHARE);
|
||||
|
||||
#ifndef LOG1024
|
||||
#define LOG1024 10
|
||||
#endif
|
||||
|
||||
/* these are for getting the memory statistics */
|
||||
static int pageshift; /* log base 2 of the pagesize */
|
||||
|
||||
/* define pagetok in terms of pageshift */
|
||||
#define pagetok(size) ((size) << pageshift)
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_proc_mem_s (glibtop *server)
|
||||
{
|
||||
register int pagesize;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_mem));
|
||||
|
||||
if (proc_stat_to_buffer (buffer, pid))
|
||||
return;
|
||||
|
||||
p = proc_stat_after_cmd (buffer);
|
||||
if (!p) return;
|
||||
|
||||
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->flags = _glibtop_sysdeps_proc_mem;
|
||||
|
||||
if (proc_statm_to_buffer (buffer, pid))
|
||||
return;
|
||||
|
||||
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->flags |= _glibtop_sysdeps_proc_mem_statm;
|
||||
}
|
@@ -1,115 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/procsegment.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_segment =
|
||||
(1L << GLIBTOP_PROC_SEGMENT_START_CODE) +
|
||||
(1L << GLIBTOP_PROC_SEGMENT_END_CODE) +
|
||||
(1L << GLIBTOP_PROC_SEGMENT_START_STACK);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_segment_statm =
|
||||
(1L << GLIBTOP_PROC_SEGMENT_TEXT_RSS) +
|
||||
/* Disabled due to bug in the Linux Kernel. */
|
||||
/* (1L << GLIBTOP_PROC_SEGMENT_SHLIB_RSS) + */
|
||||
(1L << GLIBTOP_PROC_SEGMENT_DATA_RSS) +
|
||||
(1L << GLIBTOP_PROC_SEGMENT_DIRTY_SIZE);
|
||||
|
||||
#ifndef LOG1024
|
||||
#define LOG1024 10
|
||||
#endif
|
||||
|
||||
/* these are for getting the memory statistics */
|
||||
static int pageshift; /* log base 2 of the pagesize */
|
||||
|
||||
/* define pagetok in terms of pageshift */
|
||||
#define pagetok(size) ((size) << pageshift)
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_proc_segment_s (glibtop *server)
|
||||
{
|
||||
register int pagesize;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_SEGMENT, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_segment));
|
||||
|
||||
if (proc_stat_to_buffer (buffer, pid))
|
||||
return;
|
||||
|
||||
p = proc_stat_after_cmd (buffer);
|
||||
if (!p) return;
|
||||
|
||||
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->flags = _glibtop_sysdeps_proc_segment;
|
||||
|
||||
if (proc_statm_to_buffer (buffer, pid))
|
||||
return;
|
||||
|
||||
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;
|
||||
}
|
@@ -1,65 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/procsignal.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_signal =
|
||||
(1L << GLIBTOP_PROC_SIGNAL_SIGNAL) + (1L << GLIBTOP_PROC_SIGNAL_BLOCKED) +
|
||||
(1L << GLIBTOP_PROC_SIGNAL_SIGIGNORE) + (1L << GLIBTOP_PROC_SIGNAL_SIGCATCH);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_proc_signal_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_signal = _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)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_SIGNAL, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_signal));
|
||||
|
||||
if (proc_stat_to_buffer (buffer, pid))
|
||||
return;
|
||||
|
||||
p = proc_stat_after_cmd (buffer);
|
||||
if (!p) return;
|
||||
|
||||
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->flags = _glibtop_sysdeps_proc_signal;
|
||||
}
|
@@ -59,7 +59,7 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
|
||||
* values; NEVER set their flags values if this
|
||||
* is not the case !!! */
|
||||
|
||||
sprintf (buffer, "/proc/%d/stat", pid);
|
||||
sprintf (buffer, "/proc/%d", pid);
|
||||
|
||||
if (stat (buffer, &statb))
|
||||
return;
|
||||
@@ -72,6 +72,8 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_state_uid;
|
||||
|
||||
sprintf (buffer, "/proc/%d", pid);
|
||||
|
||||
/* Now we read the remaining fields. */
|
||||
|
||||
if (proc_stat_to_buffer (buffer, pid))
|
||||
|
@@ -1,103 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/proctime.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_time =
|
||||
(1L << GLIBTOP_PROC_TIME_UTIME) + (1L << GLIBTOP_PROC_TIME_CUTIME) +
|
||||
(1L << GLIBTOP_PROC_TIME_STIME) + (1L << GLIBTOP_PROC_TIME_CSTIME) +
|
||||
(1L << GLIBTOP_PROC_TIME_FREQUENCY) + (1L << GLIBTOP_PROC_TIME_TIMEOUT) +
|
||||
(1L << GLIBTOP_PROC_TIME_IT_REAL_VALUE) + (1L << GLIBTOP_PROC_TIME_START_TIME);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_time_smp =
|
||||
(1L << GLIBTOP_PROC_TIME_XCPU_UTIME) + (1L << GLIBTOP_PROC_TIME_XCPU_STIME);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_proc_time_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_time = _glibtop_sysdeps_proc_time;
|
||||
|
||||
if (server->ncpu)
|
||||
server->sysdeps.proc_time |= _glibtop_sysdeps_proc_time_smp;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
int i;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_TIME, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_time));
|
||||
|
||||
if (proc_stat_to_buffer (buffer, pid))
|
||||
return;
|
||||
|
||||
p = proc_stat_after_cmd (buffer);
|
||||
if (!p) return;
|
||||
|
||||
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);
|
||||
|
||||
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->frequency = 100;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_time;
|
||||
|
||||
if (!server->ncpu)
|
||||
return;
|
||||
|
||||
if (proc_file_to_buffer (buffer, "/proc/%d/cpu", pid))
|
||||
return;
|
||||
|
||||
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;
|
||||
}
|
@@ -1,126 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/procuid.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_uid =
|
||||
(1L << GLIBTOP_PROC_UID_UID) + (1L << GLIBTOP_PROC_UID_EUID) +
|
||||
(1L << GLIBTOP_PROC_UID_GID) + (1L << GLIBTOP_PROC_UID_EGID);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_uid_stat =
|
||||
(1L << GLIBTOP_PROC_UID_PID) + (1L << GLIBTOP_PROC_UID_PPID) +
|
||||
(1L << GLIBTOP_PROC_UID_PGRP) + (1L << GLIBTOP_PROC_UID_SESSION) +
|
||||
(1L << GLIBTOP_PROC_UID_TTY) + (1L << GLIBTOP_PROC_UID_TPGID) +
|
||||
(1L << GLIBTOP_PROC_UID_PRIORITY) + (1L << GLIBTOP_PROC_UID_NICE);
|
||||
|
||||
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_proc_uid_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid |
|
||||
_glibtop_sysdeps_proc_uid_stat;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_UID, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_uid));
|
||||
|
||||
if (proc_status_to_buffer (buffer, pid))
|
||||
return;
|
||||
|
||||
/* Search substring 'Pid:' */
|
||||
|
||||
p = strstr (buffer, "\nPid:");
|
||||
if (!p) return;
|
||||
|
||||
p = skip_token (p); /* "Pid:" */
|
||||
buf->pid = 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;
|
||||
|
||||
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;
|
||||
|
||||
p = skip_token (p); /* "Gid:" */
|
||||
buf->gid = strtoul (p, &p, 0);
|
||||
buf->egid = strtoul (p, &p, 0);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_uid;
|
||||
|
||||
if (proc_stat_to_buffer (buffer, pid))
|
||||
return;
|
||||
|
||||
p = proc_stat_after_cmd (buffer);
|
||||
if (!p) return;
|
||||
|
||||
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);
|
||||
|
||||
p = skip_multiple_token (p, 9);
|
||||
|
||||
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 (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;
|
||||
}
|
@@ -1,86 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <glibtop/sem_limits.h>
|
||||
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/sem.h>
|
||||
|
||||
#ifdef _SEM_SEMUN_UNDEFINED
|
||||
|
||||
/* glibc 2.1 will no longer defines semun, instead it defines
|
||||
* _SEM_SEMUN_UNDEFINED so users can define semun on their own.
|
||||
* Thanks to Albert K T Hui <avatar@deva.net>. */
|
||||
|
||||
union semun
|
||||
{
|
||||
int val;
|
||||
struct semid_ds *buf;
|
||||
unsigned short int *array;
|
||||
struct seminfo *__buf;
|
||||
};
|
||||
#endif
|
||||
|
||||
static unsigned long _glibtop_sysdeps_sem_limits =
|
||||
(1L << GLIBTOP_IPC_SEMMAP) + (1L << GLIBTOP_IPC_SEMMNI) +
|
||||
(1L << GLIBTOP_IPC_SEMMNS) + (1L << GLIBTOP_IPC_SEMMNU) +
|
||||
(1L << GLIBTOP_IPC_SEMMSL) + (1L << GLIBTOP_IPC_SEMOPM) +
|
||||
(1L << GLIBTOP_IPC_SEMUME) + (1L << GLIBTOP_IPC_SEMUSZ) +
|
||||
(1L << GLIBTOP_IPC_SEMVMX) + (1L << GLIBTOP_IPC_SEMAEM);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_sem_limits_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.sem_limits = _glibtop_sysdeps_sem_limits;
|
||||
}
|
||||
|
||||
/* Provides information about sysv ipc limits. */
|
||||
|
||||
void
|
||||
glibtop_get_sem_limits_s (glibtop *server, glibtop_sem_limits *buf)
|
||||
{
|
||||
struct seminfo seminfo;
|
||||
union semun arg;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_SEM_LIMITS, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_sem_limits));
|
||||
|
||||
buf->flags = _glibtop_sysdeps_sem_limits;
|
||||
|
||||
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;
|
||||
}
|
@@ -1,62 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <glibtop/shm_limits.h>
|
||||
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
|
||||
static unsigned long _glibtop_sysdeps_shm_limits =
|
||||
(1L << GLIBTOP_IPC_SHMMAX) + (1L << GLIBTOP_IPC_SHMMIN) +
|
||||
(1L << GLIBTOP_IPC_SHMMNI) + (1L << GLIBTOP_IPC_SHMSEG) +
|
||||
(1L << GLIBTOP_IPC_SHMALL);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_shm_limits_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits;
|
||||
}
|
||||
|
||||
/* Provides information about sysv ipc limits. */
|
||||
|
||||
void
|
||||
glibtop_get_shm_limits_s (glibtop *server, glibtop_shm_limits *buf)
|
||||
{
|
||||
struct shminfo shminfo;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_SHM_LIMITS, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_shm_limits));
|
||||
|
||||
buf->flags = _glibtop_sysdeps_shm_limits;
|
||||
|
||||
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;
|
||||
}
|
@@ -1,60 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/signal.h>
|
||||
|
||||
const glibtop_signame glibtop_sys_siglist [] =
|
||||
{ { 1, "SIGHUP", NULL }, /* Hangup (POSIX). */
|
||||
{ 2, "SIGINT", NULL }, /* Interrupt (ANSI). */
|
||||
{ 3, "SIGQUIT", NULL }, /* Quit (POSIX). */
|
||||
{ 4, "SIGILL", NULL }, /* Illegal instruction (ANSI). */
|
||||
{ 5, "SIGTRAP", NULL }, /* Trace trap (POSIX). */
|
||||
{ 6, "SIGABRT", NULL }, /* Abort (ANSI). */
|
||||
{ 7, "SIGBUS", NULL }, /* BUS error (4.2 BSD). */
|
||||
{ 8, "SIGFPE", NULL }, /* Floating-point exception (ANSI). */
|
||||
{ 9, "SIGKILL", NULL }, /* Kill, unblockable (POSIX). */
|
||||
{ 10, "SIGUSR1", NULL }, /* User-defined signal 1 (POSIX). */
|
||||
{ 11, "SIGSEGV", NULL }, /* Segmentation violation (ANSI). */
|
||||
{ 12, "SIGUSR2", NULL }, /* User-defined signal 2 (POSIX). */
|
||||
{ 13, "SIGPIPE", NULL }, /* Broken pipe (POSIX). */
|
||||
{ 14, "SIGALRM", NULL }, /* Alarm clock (POSIX). */
|
||||
{ 15, "SIGTERM", NULL }, /* Termination (ANSI). */
|
||||
{ 16, "SIGSTKFLT", NULL }, /* ??? */
|
||||
{ 17, "SIGCHLD", NULL }, /* Child status has changed (POSIX). */
|
||||
{ 18, "SIGCONT", NULL }, /* Continue (POSIX). */
|
||||
{ 19, "SIGSTOP", NULL }, /* Stop, unblockable (POSIX). */
|
||||
{ 20, "SIGTSTP", NULL }, /* Keyboard stop (POSIX). */
|
||||
{ 21, "SIGTTIN", NULL }, /* Background read from tty (POSIX). */
|
||||
{ 22, "SIGTTOU", NULL }, /* Background write to tty (POSIX). */
|
||||
{ 23, "SIGURG", NULL }, /* Urgent condition on socket (4.2 BSD). */
|
||||
{ 24, "SIGXCPU", NULL }, /* CPU limit exceeded (4.2 BSD). */
|
||||
{ 25, "SIGXFSZ", NULL }, /* File size limit exceeded (4.2 BSD). */
|
||||
{ 26, "SIGVTALRM", NULL }, /* Virtual alarm clock (4.2 BSD). */
|
||||
{ 27, "SIGPROF", NULL }, /* Profiling alarm clock (4.2 BSD). */
|
||||
{ 28, "SIGWINCH", NULL }, /* Window size change (4.3 BSD, Sun). */
|
||||
{ 29, "SIGIO", NULL }, /* I/O now possible (4.2 BSD). */
|
||||
{ 30, "SIGPWR", NULL }, /* Power failure restart (System V). */
|
||||
{ 31, "SIGUNUSED", NULL },
|
||||
{ 0, NULL, NULL },
|
||||
};
|
@@ -1,104 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/swap.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
static unsigned long _glibtop_sysdeps_swap =
|
||||
(1L << GLIBTOP_SWAP_TOTAL) + (1L << GLIBTOP_SWAP_USED) +
|
||||
(1L << GLIBTOP_SWAP_FREE);
|
||||
|
||||
static unsigned long _glibtop_sysdeps_swap_paging =
|
||||
(1L << GLIBTOP_SWAP_PAGEIN) + (1L << GLIBTOP_SWAP_PAGEOUT);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_swap_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.swap = _glibtop_sysdeps_swap |
|
||||
_glibtop_sysdeps_swap_paging;
|
||||
}
|
||||
|
||||
/* Provides information about swap usage. */
|
||||
|
||||
#define MEMINFO "/proc/meminfo"
|
||||
#define PROC_STAT "/proc/stat"
|
||||
|
||||
void
|
||||
glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
int fd, len;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_SWAP, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_swap));
|
||||
|
||||
fd = open (MEMINFO, O_RDONLY);
|
||||
if (fd < 0)
|
||||
glibtop_error_io_r (server, "open (%s)", MEMINFO);
|
||||
|
||||
len = read (fd, buffer, BUFSIZ-1);
|
||||
if (len < 0)
|
||||
glibtop_error_io_r (server, "read (%s)", MEMINFO);
|
||||
|
||||
close (fd);
|
||||
|
||||
buffer [len] = '\0';
|
||||
|
||||
p = skip_line (buffer);
|
||||
p = skip_line (p);
|
||||
p = skip_token (p); /* "Swap:" */
|
||||
|
||||
buf->total = strtoul (p, &p, 0);
|
||||
buf->used = strtoul (p, &p, 0);
|
||||
buf->free = strtoul (p, &p, 0);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_swap;
|
||||
|
||||
fd = open (PROC_STAT, O_RDONLY);
|
||||
if (fd < 0)
|
||||
glibtop_error_io_r (server, "open (%s)", PROC_STAT);
|
||||
|
||||
len = read (fd, buffer, BUFSIZ-1);
|
||||
if (len < 0)
|
||||
glibtop_error_io_r (server, "read (%s)", PROC_STAT);
|
||||
|
||||
close (fd);
|
||||
|
||||
buffer [len] = '\0';
|
||||
|
||||
p = strstr (buffer, "\nswap");
|
||||
if (p == NULL) return;
|
||||
|
||||
p = skip_token (p);
|
||||
|
||||
buf->pagein = strtoul (p, &p, 0);
|
||||
buf->pageout = strtoul (p, &p, 0);
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_swap_paging;
|
||||
}
|
@@ -1,94 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/cpu.h>
|
||||
#include <glibtop/sysinfo.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_sysinfo =
|
||||
(1L << GLIBTOP_SYSINFO_CPUINFO);
|
||||
|
||||
static glibtop_sysinfo sysinfo;
|
||||
|
||||
static void
|
||||
init_sysinfo (glibtop *server)
|
||||
{
|
||||
char buffer [BUFSIZ];
|
||||
static int init = 0;
|
||||
glibtop_entry *cpuinfo = NULL;
|
||||
FILE *f;
|
||||
|
||||
if (init) return;
|
||||
|
||||
init = TRUE;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
|
||||
|
||||
memset (&sysinfo, 0, sizeof (glibtop_sysinfo));
|
||||
|
||||
g_return_if_fail (f = fopen ("/proc/cpuinfo", "r"));
|
||||
|
||||
while (fgets (buffer, BUFSIZ, f)) {
|
||||
char *p, *start, *key, *value;
|
||||
|
||||
if (cpuinfo == NULL) {
|
||||
cpuinfo = &sysinfo.cpuinfo [sysinfo.ncpu++];
|
||||
|
||||
cpuinfo->labels = g_ptr_array_new ();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
fclose (f);
|
||||
|
||||
sysinfo.flags = _glibtop_sysdeps_sysinfo;
|
||||
}
|
||||
|
||||
glibtop_sysinfo *
|
||||
glibtop_get_sysinfo_s (glibtop *server)
|
||||
{
|
||||
init_sysinfo (server);
|
||||
return &sysinfo;
|
||||
}
|
@@ -1,69 +0,0 @@
|
||||
/* $Id$ */
|
||||
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/uptime.h>
|
||||
|
||||
static unsigned long _glibtop_sysdeps_uptime =
|
||||
(1L << GLIBTOP_UPTIME_UPTIME) + (1L << GLIBTOP_UPTIME_IDLETIME);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_uptime_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.uptime = _glibtop_sysdeps_uptime;
|
||||
}
|
||||
|
||||
/* Provides uptime and idle time. */
|
||||
|
||||
#define FILENAME "/proc/uptime"
|
||||
|
||||
void
|
||||
glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
int fd, len;
|
||||
|
||||
glibtop_init_s (&server, GLIBTOP_SYSDEPS_UPTIME, 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_uptime));
|
||||
|
||||
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);
|
||||
|
||||
close (fd);
|
||||
|
||||
buffer [len] = '\0';
|
||||
|
||||
buf->uptime = (float) strtod (buffer, &p);
|
||||
buf->idletime = (float) strtod (p, &p);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_uptime;
|
||||
}
|
Reference in New Issue
Block a user