version 2.6.1

* configure.in: version 2.6.1
This commit is contained in:
Benoît Dejean
2004-07-11 21:01:27 +00:00
parent de7fd9e85b
commit c73d0eb3c9
54 changed files with 731 additions and 648 deletions

View File

@@ -15,7 +15,7 @@
2004-03-09 Bastien Nocera <hadess@hadess.net>
* procargs.c: (glibtop_get_proc_args_s): fix g_malloc usage on non-Linux
platforms (patch by Benoît Dejean <bnet@ifrance.com>)
platforms (patch by Benoit Dejean <bnet@ifrance.com>)
2003-10-21 Bastien Nocera <hadess@hadess.net>

View File

@@ -1,29 +1,14 @@
2004-07-07 Benoît Dejean <tazforever@dlfp.org>
* Makefile.am:
* procargs.c: (split_args0), (glibtop_get_proc_argv_l),
(glibtop_get_proc_argv_p), (glibtop_get_proc_argv_s): Added file to
repository. Provides glibtop_get_proc_argv*() for system dependant
glibtop_get_proc_args*().
2004-06-18 Benoît Dejean <tazforever@dlfp.org>
* error.c: (print_server_name), (glibtop_error_r),
(glibtop_warn_r), (glibtop_error_io_r), (glibtop_warn_io_r),
(glibtop_error), (glibtop_warn), (glibtop_error_io),
(glibtop_warn_io): These functions are now globally defined.
2004-06-12 Benoît Dejean <tazforever@dlfp.org>
* Makefile.am:
* fsusage-frontend.c:
* fsusage.h: Removed files.
* fsusage.c: (glibtop_get_fsusage_s), (statfs): Merged and cleaned.
* fsusage.c: (glibtop_get_fsusage_s), (statfs): Merged and cleaned.
2004-06-12 Benoît Dejean <tazforever@dlfp.org>
* mountlist.c: (xatoi) Removed, replaced by ISO strtoull.
* mountlist.c: (xatoi) Removed, replaced by ISO strtoull.
(fstype_to_string): Cleaned.
(read_filesystem_list) : Changed prototype. Cleaned and secured.
Replaced broken free by g_free.

View File

@@ -16,7 +16,6 @@ noinst_LTLIBRARIES = libgtop_common-2.0.la libgtop_suid_common-2.0.la
libgtop_common_2_0_la_SOURCES = error.c gnuslib.c \
fsusage.c \
mountlist.c mountlist.h \
procargs.c \
$(inodedb_SRCLIST)
libgtop_common_2_0_la_LDFLAGS = $(LT_VERSION_INFO)

View File

@@ -28,7 +28,7 @@
/* Prints error message and exits. */
static void
print_server_name (const glibtop *server)
print_server_name (glibtop *server)
{
fprintf (stderr, "%s: ", server ?
(server->name ? server->name : DEFAULT_NAME)
@@ -86,85 +86,3 @@ glibtop_warn_io_vr (glibtop *server, char *format, int error, va_list args)
abort ();
#endif
}
void G_GNUC_UNUSED
glibtop_error_r (glibtop *server, char *format, ...)
{
va_list args;
va_start (args, format);
glibtop_error_vr (server, format, args);
va_end (args);
}
void G_GNUC_UNUSED
glibtop_warn_r (glibtop *server, char *format, ...)
{
va_list args;
va_start (args, format);
glibtop_warn_vr (server, format, args);
va_end (args);
}
void G_GNUC_UNUSED
glibtop_error_io_r (glibtop *server, char *format, ...)
{
va_list args;
va_start (args, format);
glibtop_error_io_vr (server, format, errno, args);
va_end (args);
}
void G_GNUC_UNUSED
glibtop_warn_io_r (glibtop *server, char *format, ...)
{
va_list args;
va_start (args, format);
glibtop_warn_io_vr (server, format, errno, args);
va_end (args);
}
#ifndef __GNUC__
void
glibtop_error (char *format, ...)
{
va_list args;
va_start (args, format);
glibtop_error_vr (glibtop_global_server, format, args);
va_end (args);
}
void
glibtop_warn (char *format, ...)
{
va_list args;
va_start (args, format);
glibtop_warn_vr (glibtop_global_server, format, args);
va_end (args);
}
void
glibtop_error_io (char *format, ...)
{
va_list args;
va_start (args, format);
glibtop_error_io_vr (glibtop_global_server, format, errno, args);
va_end (args);
}
void
glibtop_warn_io (char *format, ...)
{
va_list args;
va_start (args, format);
glibtop_warn_io_vr (glibtop_global_server, format, errno, args);
va_end (args);
}
#endif /* __GNUC__ */

View File

@@ -0,0 +1,67 @@
/* fsusage-frontend.c -- return space usage of mounted filesystems.
Copyright (C) 2003 Ole Laursen.
This program 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, or (at your option)
any later version.
This program 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 this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* This code is simply a front-end for the actual code in fsusage.[ch] which
is stolen directly from the GNU Coreutils package. */
#if HAVE_CONFIG_H
# include <config.h>
#endif
#if HAVE_CONFIG_H
# include <config.h>
#endif
#if HAVE_INTTYPES_H
# include <inttypes.h>
#else
# if HAVE_STDINT_H
# include <stdint.h>
# endif
#endif
#ifndef UINTMAX_MAX
# define UINTMAX_MAX ((uintmax_t) -1)
#endif
#include "fsusage.h"
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/fsusage.h>
void
glibtop_get_fsusage_s (glibtop *server, glibtop_fsusage *buf,
const char *disk)
{
struct fs_usage fsp;
glibtop_init_r (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_fsusage));
memset (&fsp, 0, sizeof (struct fs_usage));
if (glibtop_private_get_fs_usage (disk, disk, &fsp) != 0)
return;
buf->blocks = fsp.fsu_blocks;
buf->bfree = fsp.fsu_bfree;
buf->bavail = fsp.fsu_bavail;
buf->files = fsp.fsu_files;
buf->ffree = fsp.fsu_ffree;
buf->block_size = fsp.fsu_blocksize;
}

47
sysdeps/common/fsusage.h Normal file
View File

@@ -0,0 +1,47 @@
/* fsusage.h -- declarations for filesystem space usage info
Copyright (C) 1991, 1992, 1997 Free Software Foundation, Inc.
This program 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, or (at your option)
any later version.
This program 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 this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* Space usage statistics for a filesystem. Blocks are 512-byte. */
#include <glib.h>
#if !defined FSUSAGE_H_
# define FSUSAGE_H_
struct fs_usage
{
int fsu_blocksize; /* Size of a block. */
guint64 fsu_blocks; /* Total blocks. */
guint64 fsu_bfree; /* Free blocks available to superuser. */
guint64 fsu_bavail; /* Free blocks available to non-superuser. */
int fsu_bavail_top_bit_set; /* 1 if fsu_bavail represents a value < 0. */
guint64 fsu_files; /* Total file nodes. */
guint64 fsu_ffree; /* Free file nodes. */
};
# ifndef PARAMS
# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
# define PARAMS(Args) Args
# else
# define PARAMS(Args) ()
# endif
# endif
int glibtop_private_get_fs_usage PARAMS ((const char *path, const char *disk,
struct fs_usage *fsp));
#endif

View File

@@ -1,12 +1,12 @@
2004-06-07 Benoît Dejean <tazforever@dlfp.org>
* netload.c: (glibtop_get_netload_p):
* procstate.c: (glibtop_get_proc_state_p):
* procstate.c: (glibtop_get_proc_state_p):
* prockernel.c: (glibtop_get_proc_kernel_p): s/strncpy/g_strlcpy/.
* procargs.c: (glibtop_get_proc_args_p):
* procmap.c: (glibtop_get_proc_map_p): Cleaned.
2004-05-26 Benoît Dejean <tazforever@dlfp.org>
@@ -40,7 +40,7 @@
* procargs.c: (glibtop_get_proc_args_p):
* procmap.c: (glibtop_get_proc_map_p):
* swap.c: (glibtop_get_swap_p): fix g_malloc usage on non-Linux
platforms (patch by Benoît Dejean <bnet@ifrance.com>)
platforms (patch by Benoit Dejean <bnet@ifrance.com>)
2003-10-21 Bastien Nocera <hadess@hadess.net>
@@ -126,10 +126,10 @@
Tue Jun 15 16:04:10 1999 Timur Bakeyev <mc@bat.ru>
* procuid.c: A fix to a ommitted case, when nor NetBSD, nor
* procuid.c: A fix to a ommitted case, when nor NetBSD, nor
LibGTop >= 1.1.0. This should be investigated closely to cover
more cases....
1999-05-26 Martin Baulig <martin@home-of-linux.org>
More NetBSD 1.4 fixes.
@@ -140,7 +140,7 @@ Tue Jun 15 16:04:10 1999 Timur Bakeyev <mc@bat.ru>
this needs to be tested; I made it conditional to NetBSD 1.4 at
the moment. Please extend the conditionals to any other systems
where this works ...]
* procstate.c: Added `ruid' and `rgid' for LibGTop >= 1.1.0.
* procuid.c: Added `ngroups' and `groups' for LibGTop >= 1.1.0.
@@ -153,7 +153,7 @@ Thu Apr 8 23:47:29 1999 Timur Bakeyev <timur@gnu.org>
* cpu.c, mem.c, netload.c, procargs.c, procstate.c, proctime.c,
sem_limits.c, shm_limits.c, swap.c: Added initial port for BSD/OS
(aka BSDI) 2.x and 3.x. 4.x should also(?) work.
Still, this port require more close look and extended check.
1999-03-19 Martin Baulig <martin@home-of-linux.org>
@@ -191,7 +191,7 @@ Thu Apr 8 23:47:29 1999 Timur Bakeyev <timur@gnu.org>
* prockernel.c, proctime.c: Applied patch from the FreeBSD 2.2.8
ports collection.
* procsignal.c: Applied patch from the NetBSD-current ports
collection.
@@ -206,7 +206,7 @@ Thu Apr 8 23:47:29 1999 Timur Bakeyev <timur@gnu.org>
1998-11-17 Martin Baulig <martin@home-of-linux.org>
* Make it work with FreeBSD 3.0.
1998-11-11 Martin Baulig <martin@home-of-linux.org>
* *.c: It does not work to get information about the swapper task
@@ -240,7 +240,7 @@ Thu Apr 8 23:47:29 1999 Timur Bakeyev <timur@gnu.org>
* procstate.c (glibtop_get_procstate_s): Use correct values for
the `state' field.
* proclist.c (glibtop_get_proclist_p): Honor the GLIBTOP_EXCLUDE_IDLE
and GLIBTOP_EXCLUDE_SYSTEM flags of the `which' parameter.

View File

@@ -11,13 +11,13 @@
* sem_limits.c:
* shm_limits.c:
* swap.c: Added missing const qualifiers.
* uptime.c: (glibtop_get_uptime_s): Cleaned up. Added boot_time.
2004-03-09 Bastien Nocera <hadess@hadess.net>
* proclist.c: (glibtop_get_proclist_s): fix g_malloc usage on non-Linux
platforms (patch by Benoît Dejean <bnet@ifrance.com>)
platforms (patch by Benoit Dejean <bnet@ifrance.com>)
2003-10-21 Bastien Nocera <hadess@hadess.net>

View File

@@ -1,48 +1,3 @@
2004-07-07 Benoît Dejean <tazforever@dlfp.org>
* procargs.c: (glibtop_get_proc_args_s): Fixed. error is now correctly
set to NULL before is's used. Fixed max_len behaviour.
2004-07-03 Benoît Dejean <tazforever@dlfp.org>
* sysinfo.c: (init_sysinfo): Removed useless memset.
2004-07-03 Benoît Dejean <tazforever@dlfp.org>
* glibtop_server.h:
* glibtop_server.c: (try_file_to_buffer), (file_to_buffer): Added. These
functions are commonly used. Misc cleanups.
* cpu.c: (glibtop_get_cpu_s):
* loadavg.c: (glibtop_get_loadavg_s):
* mem.c: (glibtop_get_mem_s):
* open.c: (glibtop_open_s):
* swap.c: (glibtop_get_swap_s):
* sysinfo.c: (init_sysinfo):
* uptime.c: (glibtop_get_uptime_s): Replaced open/read/close by file_to_buffer().
2004-06-18 Benoît Dejean <tazforever@dlfp.org>
* loadavg.c: (glibtop_get_loadavg_s): Whitespace cleanup.
* ppp.c: (get_ISDN_stats), (is_ISDN_on): Replace g_malloc by an
array.
* glibtop_server.c: (get_pageshift):
* glibtop_server.h:
* procmem.c: (glibtop_init_proc_mem_s), (glibtop_get_proc_mem_s):
* procsegment.c: (glibtop_init_proc_segment_s),
(glibtop_get_proc_segment_s): Moved the pageshift calculation to
glibtop_server.[ch]
* procstate.c: (glibtop_get_proc_state_s):
* procuid.c: (glibtop_get_proc_uid_s):
* sysinfo.c: (init_sysinfo): Minor cleanups.
2004-06-18 Benoît Dejean <tazforever@dlfp.org>
* netload.c: (glibtop_get_netload_s): Implemented new IPv6 feature.
2004-06-13 Benoît Dejean <tazforever@dlfp.org>
* procargs.c: (glibtop_get_proc_args_s): Replaced by g_file_get_contents.
@@ -51,8 +6,8 @@
* glibtop_server.h:
* glibtop_server.c: (get_scaled): Cleaned.
(proc_file_to_buffer): Uninlined.
(proc_file_to_buffer): Uninlined.
* sysinfo.c: (init_sysinfo): Re-implemented.
Fixed segfault on SMP.
Stores keys in cpuinfo->labels.
@@ -61,21 +16,21 @@
* Makefile.am:
* glibtop_server.c: Added to repository.
* glibtop_server.h: (get_scaled): Uninlined and moved it to glibtop_server.c.
(skip_token) : Fixed indentation.
(skip_token) : Fixed indentation.
* procmap.c: (glibtop_get_proc_map_s): Big cleanup. Better allocation
algorithm.
* procmem.c:
* procsegment.c: Added missing initializations.
* sem_limits.c:
* shm_limits.c: (glibtop_get_shm_limits_s):
* swap.c:
* uptime.c: Added missing const qualifiers.
* sysinfo.c: (init_sysinfo): Added missing 0 initialization.
Saved 1 gboolean :D.
@@ -108,7 +63,7 @@
* glibtop_server.h:
* open.c:
* procuid.c: Moved LINUX_VERSION macro to glibtop_server.h.
* Changelog: Converted to UTF-8.
2004-05-19 Benoît Dejean <TazForEver@dlfp.org>
@@ -132,7 +87,7 @@
the file (Closes: #126504)
2004-02-02 Sebastien Bacher <seb128@debian.org>
* sysdeps/linux/mem.c: (glibtop_get_mem_s): patch from
Benoît Dejean <bnet@ifrance.com> to fix libtop_mem.used
and glibtop_mem.shared values (Closes: #129863).
@@ -279,7 +234,7 @@
* netload.c (glibtop_get_netload_s): Added implementation
for this function.
The code here is smart enough to use /proc/net/ip_acct if
IP accounting is enabled in the kernel and activated on the
requested device and /proc/net/dev if not.

View File

@@ -54,13 +54,24 @@ void
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
{
char buffer [BUFSIZ], *p;
int fd, len;
int i;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
memset (buf, 0, sizeof (glibtop_cpu));
file_to_buffer(server, buffer, 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);
close (fd);
buffer [len] = '\0';
/*
* GLOBAL

View File

@@ -1,17 +1,12 @@
#include <glibtop.h>
#include <glibtop/error.h>
#include <glib.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
/* gcc warning bug */
unsigned get_pageshift();
unsigned long long
get_scaled(const char *buffer, const char *key)
@@ -33,73 +28,25 @@ get_scaled(const char *buffer, const char *key)
}
/*
* Read functions
*/
enum TRY_FILE_TO_BUFFER
int
proc_file_to_buffer (char *buffer, const char *fmt, pid_t pid)
{
TRY_FILE_TO_BUFFER_OK = 0,
TRY_FILE_TO_BUFFER_OPEN = -1,
TRY_FILE_TO_BUFFER_READ = -2
};
int try_file_to_buffer(char *buffer, const char *format, ...)
{
char path[4096];
char filename [256];
int fd;
ssize_t len;
va_list pa;
va_start(pa, format);
g_snprintf (filename, sizeof filename, fmt, pid);
/* C99 also provides vsnprintf */
g_vsnprintf(path, sizeof path, format, pa);
va_end(pa);
if((fd = open (path, O_RDONLY)) < 0)
return TRY_FILE_TO_BUFFER_OPEN;
fd = open (filename, O_RDONLY);
if (fd < 0) return -1;
len = read (fd, buffer, BUFSIZ-1);
close (fd);
if (len < 0)
return TRY_FILE_TO_BUFFER_READ;
if (len < 0) return -1;
buffer [len] = '\0';
return TRY_FILE_TO_BUFFER_OK;
return 0;
}
void
file_to_buffer(glibtop *server, char *buffer, const char *filename)
{
switch(try_file_to_buffer(buffer, filename))
{
case TRY_FILE_TO_BUFFER_OPEN:
glibtop_error_io_r (server, "open (%s)", filename);
case TRY_FILE_TO_BUFFER_READ:
glibtop_error_io_r (server, "read (%s)", filename);
}
}
#warning "Ignore the following warning"
unsigned get_pageshift()
{
static unsigned pageshift = 0;
if(G_UNLIKELY(!pageshift))
{
register unsigned pagesize = getpagesize();
while( pagesize > 1 )
{
pagesize >>= 1;
pageshift++;
}
}
return pageshift;
}

View File

@@ -21,16 +21,12 @@
Boston, MA 02111-1307, USA.
*/
#ifndef __LINUX__GLIBTOP_SERVER_H__
#define __LINUX__GLIBTOP_SERVER_H__
#ifndef __GLIBTOP_SERVER_H__
#define __GLIBTOP_SERVER_H__
#include <glibtop.h>
#include <glib.h>
#include <fcntl.h>
#include <ctype.h>
#include <string.h>
G_BEGIN_DECLS
@@ -38,10 +34,6 @@ G_BEGIN_DECLS
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
unsigned get_pageshift();
static inline char *
skip_token (const char *p)
{
@@ -59,7 +51,6 @@ skip_multiple_token (const char *p, size_t count)
return (char *)p;
}
static inline char *
skip_line (const char *p)
{
@@ -67,29 +58,12 @@ skip_line (const char *p)
return (char *) (*p ? p+1 : p);
}
unsigned long long
get_scaled(const char *buffer, const char *key);
/* aborts on error */
void
file_to_buffer(glibtop *server, char *buffer, const char *filename);
/* return < 0 on error, otherwise 0 on success */
int
try_file_to_buffer(char *buffer, const char *format, ...);
/* some inline functions that wrap proc path
* as fast as macros :)
*/
static inline int
proc_file_to_buffer (char *buffer, const char *fmt, pid_t pid)
{
return try_file_to_buffer(buffer, fmt, pid);
}
proc_file_to_buffer (char *buffer, const char *fmt, pid_t pid);
static inline int
proc_stat_to_buffer (char *buffer, pid_t pid)
@@ -109,13 +83,13 @@ 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 (G_LIKELY(p))
*p++ = '\0';
if (!p) return p;
*p++ = '\0';
return p;
}
@@ -144,4 +118,4 @@ proc_stat_after_cmd (char *p)
G_END_DECLS
#endif /* __LINUX__GLIBTOP_SERVER_H__ */
#endif

View File

@@ -49,12 +49,23 @@ 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));
file_to_buffer(server, buffer, 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);
close (fd);
buffer [len] = '\0';
buf->loadavg [0] = strtod (buffer, &p);
buf->loadavg [1] = strtod (p, &p);
@@ -62,12 +73,12 @@ glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
buf->flags = _glibtop_sysdeps_loadavg;
while (isspace(*p)) p++;
while (isspace(*p)) p++;
/* Older Linux versions don't have the nr_running/nr_tasks fields. */
old = p;
while (*p) {
while (*p) {
if (*p == '/')
break;
if (!isdigit (*p))

View File

@@ -47,10 +47,23 @@ void
glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
{
char buffer [BUFSIZ];
int fd, len;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);
file_to_buffer(server, buffer, FILENAME);
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';
buf->total = get_scaled(buffer, "MemTotal:");
buf->free = get_scaled(buffer, "MemFree:");
@@ -59,6 +72,6 @@ glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
buf->buffer = get_scaled(buffer, "Buffers:");
buf->cached = get_scaled(buffer, "Cached:");
buf->user = buf->total - buf->free - buf->cached - buf->buffer;
buf->flags = _glibtop_sysdeps_mem;
buf->user = buf->total - buf->free - buf->cached - buf->buffer;
buf->flags = _glibtop_sysdeps_mem;
}

View File

@@ -47,17 +47,6 @@
#include <linux/udp.h>
#endif
/* IPV6 */
#include <ifaddrs.h>
#ifndef IN6_IS_ADDR_GLOBAL
#define IN6_IS_ADDR_GLOBAL(a) \
(((((__const uint8_t *) (a))[0] & 0xff) == 0x3f \
|| (((__const uint8_t *) (a))[0] & 0xff) == 0x20))
#endif
/* IPV6 */
#define _GLIBTOP_IP_FW_ACCTIN 0x1000 /* Account incoming packets only. */
#define _GLIBTOP_IP_FW_ACCTOUT 0x2000 /* Account outgoing packets only. */
@@ -97,11 +86,6 @@ static const unsigned long _glibtop_sysdeps_netload_out =
(1L << GLIBTOP_NETLOAD_PACKETS_OUT) +
(1L << GLIBTOP_NETLOAD_BYTES_OUT);
static const unsigned long _glibtop_sysdeps_netload_6 =
(1L << GLIBTOP_NETLOAD_ADDRESS6) +
(1L << GLIBTOP_NETLOAD_PREFIX6) +
(1L << GLIBTOP_NETLOAD_SCOPE6);
/* Init function. */
void
@@ -330,8 +314,6 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
if (strcmp (dev, interface))
continue;
/* Ok, we've found the interface */
/* Only read byte counts if we really have them. */
if (have_bytes) {
@@ -366,56 +348,7 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
if (have_bytes)
buf->flags |= _glibtop_sysdeps_netload_bytes;
break; /* finished */
}
fclose (f);
/* IPv6 */
{
struct ifaddrs *ifa0, *ifr6;
getifaddrs (&ifa0);
for (ifr6 = ifa0; ifr6; ifr6 = ifr6->ifa_next) {
if (strcmp (ifr6->ifa_name, interface) == 0
&& ifr6->ifa_addr->sa_family == AF_INET6)
break;
}
if(!ifr6) return;
memcpy(buf->address6,
&((struct sockaddr_in6 *) ifr6->ifa_addr)->sin6_addr,
16);
memcpy(buf->prefix6,
&((struct sockaddr_in6 *) ifr6->ifa_netmask)->sin6_addr,
16);
if (IN6_IS_ADDR_LINKLOCAL (buf->address6))
buf->scope6 = GLIBTOP_IF_IN6_SCOPE_LINK;
else if (IN6_IS_ADDR_SITELOCAL (buf->address6))
buf->scope6 = GLIBTOP_IF_IN6_SCOPE_SITE;
else if (IN6_IS_ADDR_GLOBAL (buf->address6)
|| IN6_IS_ADDR_MC_ORGLOCAL (buf->address6)
|| IN6_IS_ADDR_V4COMPAT (buf->address6)
|| IN6_IS_ADDR_MULTICAST (buf->address6)
|| IN6_IS_ADDR_UNSPECIFIED (buf->address6)
)
buf->scope6 = GLIBTOP_IF_IN6_SCOPE_GLOBAL;
else if (IN6_IS_ADDR_LOOPBACK (buf->address6))
buf->scope6 = GLIBTOP_IF_IN6_SCOPE_HOST;
else
buf->scope6 = GLIBTOP_IF_IN6_SCOPE_UNKNOWN;
buf->flags |= _glibtop_sysdeps_netload_6;
} /* IPV6 */
}

View File

@@ -66,12 +66,23 @@ glibtop_open_s (glibtop *server, const char *program_name,
const unsigned flags)
{
char buffer [BUFSIZ], *p = buffer;
int fd, len;
server->name = program_name;
server->os_version_code = get_linux_version();
file_to_buffer(server, buffer, 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);
close (fd);
buffer [len] = '\0';
for (server->ncpu = 0; server->ncpu < GLIBTOP_NCPU; server->ncpu++) {

View File

@@ -52,35 +52,40 @@ glibtop_init_ppp_s (glibtop *server)
server->sysdeps.ppp = _glibtop_sysdeps_ppp;
}
static gboolean
static int
get_ISDN_stats (glibtop *server, int *in, int *out)
{
unsigned long isdn_stats[2 * ISDN_MAX_CHANNELS], *ptr;
int fd;
unsigned long *isdn_stats, *ptr;
int fd, i;
*in = *out = 0;
isdn_stats = g_malloc (ISDN_MAX_CHANNELS * 2 * sizeof (unsigned long));
fd = open ("/dev/isdninfo", O_RDONLY);
if (fd < 0) {
g_free (isdn_stats);
return FALSE;
}
if ((ioctl (fd, IIOCGETCPS, isdn_stats) < 0) && (errno != 0)) {
close(fd);
g_free (isdn_stats);
close (fd);
return FALSE;
}
for (ptr = isdn_stats;
ptr != (isdn_stats + G_N_ELEMENTS(isdn_stats));
/* NOOP */) {
for (i = 0, ptr = isdn_stats; i < ISDN_MAX_CHANNELS; i++) {
*in += *ptr++; *out += *ptr++;
}
g_free (isdn_stats);
close (fd);
return TRUE;
}
static gboolean is_ISDN_on (glibtop *server, int *online)
static int is_ISDN_on (glibtop *server, int *online)
{
FILE *f = 0;
char buffer [BUFSIZ], *p;

View File

@@ -42,11 +42,11 @@ char *
glibtop_get_proc_args_s (glibtop *server, glibtop_proc_args *buf,
pid_t pid, unsigned max_len)
{
char filename[48]; /* magiv */
char filename[48];
char *args;
gsize length;
GError *error = NULL;
GError *error;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_ARGS, 0);
@@ -55,14 +55,13 @@ glibtop_get_proc_args_s (glibtop *server, glibtop_proc_args *buf,
sprintf (filename, "/proc/%d/cmdline", pid);
if(!g_file_get_contents(filename, &args, &length, &error)) {
g_error_free(error);
buf->size = 0;
return NULL;
}
if(max_len && max_len < length) {
args = g_realloc(args, max_len);
args[max_len - 1] = '\0';
args = g_realloc(args, max_len+1);
args[max_len] = '\0';
length = max_len;
}

View File

@@ -33,14 +33,34 @@ 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 = 0; /* 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. */
@@ -49,7 +69,6 @@ void
glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
{
char buffer [BUFSIZ], *p;
const unsigned pageshift = get_pageshift();
glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);

View File

@@ -37,13 +37,34 @@ static const unsigned long _glibtop_sysdeps_proc_segment_statm =
(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 = 0; /* 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. */
@@ -53,7 +74,6 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
pid_t pid)
{
char buffer [BUFSIZ], *p;
const unsigned pageshift = get_pageshift();
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_SEGMENT, 0);

View File

@@ -83,7 +83,7 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
buf->state = p [2];
p = skip_token (buffer); p++; /* pid */
if (G_UNLIKELY(*p++ != '('))
if (*p++ != '(')
glibtop_error_r (server, "Bad data in /proc/%d/stat", pid);
g_strlcpy (buf->cmd, p, sizeof buf->cmd);

View File

@@ -117,7 +117,7 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
buf->priority = 2*15 - buf->priority;
buf->nice = 15 - buf->nice;
}
else if (server->os_version_code < LINUX_VERSION(1,1,30) && buf->tty != -1)
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;

View File

@@ -52,12 +52,23 @@ 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));
file_to_buffer(server, buffer, MEMINFO);
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';
/* Kernel 2.6 with multiple lines */
@@ -67,7 +78,17 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
buf->flags = _glibtop_sysdeps_swap;
file_to_buffer(server, buffer, PROC_STAT);
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;

View File

@@ -36,13 +36,31 @@ static glibtop_sysinfo sysinfo = { .flags = 0 };
static void
init_sysinfo (glibtop *server)
{
int fd;
ssize_t len;
char buffer [BUFSIZ];
if(G_LIKELY(sysinfo.flags)) return;
if(sysinfo.flags) return;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
file_to_buffer(server, buffer, FILENAME);
memset (&sysinfo, 0, sizeof (glibtop_sysinfo));
/* load the file */
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';
/* cpuinfo records are seperated by a blank line */
gchar ** const processors = g_strsplit(buffer, "\n\n", 0);
@@ -79,7 +97,8 @@ init_sysinfo (glibtop *server)
/* the last key has no value and has not been added */
if(*p) g_free(*p);
if(*p)
g_free(*p);
/* just g_free instead of g_strvfree because we stole
the memory*/

View File

@@ -45,12 +45,23 @@ 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));
file_to_buffer(server, buffer, 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);
close (fd);
buffer [len] = '\0';
buf->uptime = strtod (buffer, &p);
buf->idletime = strtod (p, &p);

View File

@@ -26,13 +26,13 @@
const char *glibtop_names_fsusage [GLIBTOP_MAX_FSUSAGE] =
{
"blocks", "bfree", "bavail", "files", "ffree", "block_size"
"blocks", "bfree", "bavail", "files", "ffree"
};
const unsigned glibtop_types_fsusage [GLIBTOP_MAX_FSUSAGE] =
{
GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG,
GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_INT
GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG
};
const char *glibtop_labels_fsusage [GLIBTOP_MAX_FSUSAGE] =
@@ -41,8 +41,7 @@ const char *glibtop_labels_fsusage [GLIBTOP_MAX_FSUSAGE] =
N_("Free blocks"),
N_("Available blocks"),
N_("Total file nodes"),
N_("Free file nodes"),
N_("Block size")
N_("Free file nodes")
};
const char *glibtop_descriptions_fsusage [GLIBTOP_MAX_FSUSAGE] =
@@ -51,6 +50,5 @@ const char *glibtop_descriptions_fsusage [GLIBTOP_MAX_FSUSAGE] =
N_("Free blocks available to the superuser"),
N_("Free blocks available to non-superusers"),
N_("Total file nodes"),
N_("Free file nodes"),
N_("Block size")
N_("Free file nodes")
};

56
sysdeps/names/netinfo.c Normal file
View File

@@ -0,0 +1,56 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* $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/netinfo.h>
#include "libgtop-i18n.h"
const char *glibtop_names_netinfo[GLIBTOP_MAX_NETINFO] =
{
"if_flags", "transport", "mtu", "subnet", "address"
};
const unsigned glibtop_types_netinfo[GLIBTOP_MAX_NETINFO] =
{
GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG,
GLIBTOP_TYPE_ULONG, GLIBTOP_TYPE_ULONG
};
const char *glibtop_labels_netinfo[GLIBTOP_MAX_NETINFO] =
{
N_ ("Interface Flags"),
N_ ("Transport Method"),
N_ ("MTU"),
N_ ("Subnet"),
N_ ("Address"),
};
const char *glibtop_descriptions_netinfo[GLIBTOP_MAX_NETINFO] =
{
N_ ("Interface Flags"),
N_ ("Transport Method"),
N_ ("Maximum Transfer Unit"),
N_ ("Subnet"),
N_ ("Address"),
};

View File

@@ -29,7 +29,7 @@ const char *glibtop_names_netload [GLIBTOP_MAX_NETLOAD] =
"if_flags", "mtu", "subnet", "address", "packets_in",
"packets_out", "packets_total", "bytes_in", "bytes_out",
"bytes_total", "errors_in", "errors_out", "errors_total",
"collisions", "address6", "prefix6", "scope6"
"collisions"
};
const unsigned glibtop_types_netload [GLIBTOP_MAX_NETLOAD] =
@@ -45,8 +45,8 @@ const char *glibtop_labels_netload [GLIBTOP_MAX_NETLOAD] =
{
N_("Interface Flags"),
N_("MTU"),
N_("IPv4 Subnet"),
N_("IPv4 Address"),
N_("Subnet"),
N_("Address"),
N_("Packets In"),
N_("Packets Out"),
N_("Packets Total"),
@@ -56,18 +56,15 @@ const char *glibtop_labels_netload [GLIBTOP_MAX_NETLOAD] =
N_("Errors In"),
N_("Errors Out"),
N_("Errors Total"),
N_("Collisions"),
N_("IPv6 Address"),
N_("IPv6 Prefix"),
N_("IPv6 Scope")
N_("Collisions")
};
const char *glibtop_descriptions_netload [GLIBTOP_MAX_NETLOAD] =
{
N_("Interface Flags"),
N_("Maximum Transfer Unit"),
N_("IPv4 Subnet"),
N_("IPv4 Address"),
N_("Subnet"),
N_("Address"),
N_("Packets In"),
N_("Packets Out"),
N_("Packets Total"),
@@ -77,8 +74,5 @@ const char *glibtop_descriptions_netload [GLIBTOP_MAX_NETLOAD] =
N_("Errors In"),
N_("Errors Out"),
N_("Errors Total"),
N_("Collisions"),
N_("IPv6 Address"),
N_("IPv6 Prefix"),
N_("IPv6 Scope")
N_("Collisions")
};

View File

@@ -8,7 +8,7 @@
* sem_limits.c:
* shm_limits.c:
* swap.c: Added missing const qualifiers.
* uptime.c: (glibtop_get_uptime_s): Cleaned up. Added boot_time.
2003-10-21 Bastien Nocera <hadess@hadess.net>

View File

@@ -16,7 +16,7 @@
* procargs.c: (glibtop_get_proc_args_s):
* procmap.c: (glibtop_get_proc_map_s): fix g_malloc usage on non-Linux
platforms (patch by Benoît Dejean <bnet@ifrance.com>)
platforms (patch by Benoit Dejean <bnet@ifrance.com>)
2003-10-21 Bastien Nocera <hadess@hadess.net>
@@ -184,7 +184,7 @@
1999-05-04 Drazen Kacar <dave@srce.hr>
* glibtop_machine.h: Changed boot time to unsigned long long.
* open.c: Added proper type checking for boot value. There's
no point in saving a few nanoseconds in init function. And
one day it will become 64-bit value.

View File

@@ -28,6 +28,6 @@
1998-08-24 Martin Baulig <martin@home-of-linux.org>
* *.c: Added initialization functions `glibtop_init_<feature>_s'.
* ChangeLog: New file.

View File

@@ -7,7 +7,7 @@
* open.c: (glibtop_open_p):
* proclist.c: (glibtop_get_proclist_p): fix g_malloc usage on non-Linux
platforms (patch by Benoît Dejean <bnet@ifrance.com>)
platforms (patch by Benoit Dejean <bnet@ifrance.com>)
2003-10-21 Bastien Nocera <hadess@hadess.net>