New fields error_method', sysdeps' and `required'. I added an improved

1998-08-07  Martin Baulig  <martin@home-of-linux.org>

	* glibtop.h (_glibtop): New fields `error_method', `sysdeps' and
	`required'. I added an improved error handling: the client can tell
	the libraries which fields are absolutely required for each features
	and if it fails to set one of them, this will create an error which
	is handled depending upon the `error_method'.

	* include/glibtop/open.h: Define some constants for `error_method'.

	* lib/sysdeps.c (glibtop_get_sysdeps_r): No longer actually call any
	sysdeps function, it now simply copies `server->sysdeps'.
	(_glibtop_init_hook_s): Added. List of functions to be called during
	`glibtop_init_s' set to `glibtop_init_<no-suid-feature>_s'.

	* include/glibtop/sysdeps.h (<glibtop/union.h>): Removed.
	(glibtop_init_func_t): New typedef.
	(_glibtop_init_hook_s): Added.

	* sysdeps/linux/*.c (glibtop_init_<feature>_s): New functions.
	(glibtop_get_proc_*): Zero is now a valid pid.

	* sysdeps/kernel/*.c (glibtop_init_<feature>_s): New functions.
	(glibtop_get_proc_*): Zero is now a valid pid.

1998-08-06  Martin Baulig  <martin@home-of-linux.org>
This commit is contained in:
Martin Baulig
1998-08-07 10:01:55 +00:00
committed by Martin Baulig
parent 09e1353d0d
commit 4b3fcf149a
61 changed files with 537 additions and 191 deletions

View File

@@ -1,3 +1,28 @@
1998-08-07 Martin Baulig <martin@home-of-linux.org>
* glibtop.h (_glibtop): New fields `error_method', `sysdeps' and
`required'. I added an improved error handling: the client can tell
the libraries which fields are absolutely required for each features
and if it fails to set one of them, this will create an error which
is handled depending upon the `error_method'.
* include/glibtop/open.h: Define some constants for `error_method'.
* lib/sysdeps.c (glibtop_get_sysdeps_r): No longer actually call any
sysdeps function, it now simply copies `server->sysdeps'.
(_glibtop_init_hook_s): Added. List of functions to be called during
`glibtop_init_s' set to `glibtop_init_<no-suid-feature>_s'.
* include/glibtop/sysdeps.h (<glibtop/union.h>): Removed.
(glibtop_init_func_t): New typedef.
(_glibtop_init_hook_s): Added.
* sysdeps/linux/*.c (glibtop_init_<feature>_s): New functions.
(glibtop_get_proc_*): Zero is now a valid pid.
* sysdeps/kernel/*.c (glibtop_init_<feature>_s): New functions.
(glibtop_get_proc_*): Zero is now a valid pid.
1998-08-06 Martin Baulig <martin@home-of-linux.org> 1998-08-06 Martin Baulig <martin@home-of-linux.org>
* configure.in (HAVE_SOCKETS, HAVE_SOCKADDR_SUN_LEN): New checks. * configure.in (HAVE_SOCKETS, HAVE_SOCKADDR_SUN_LEN): New checks.

View File

@@ -33,10 +33,13 @@
typedef struct _glibtop glibtop; typedef struct _glibtop glibtop;
#include <glibtop/sysdeps.h>
struct _glibtop struct _glibtop
{ {
unsigned flags; unsigned flags;
unsigned method; /* Server Method */ unsigned method; /* Server Method */
unsigned error_method; /* Error Method */
#ifdef HAVE_GLIBTOP_MACHINE_H #ifdef HAVE_GLIBTOP_MACHINE_H
glibtop_machine machine; /* Machine dependent data */ glibtop_machine machine; /* Machine dependent data */
#endif #endif
@@ -51,6 +54,8 @@ struct _glibtop
const char *server_rsh; /* Command used to connect to the target host */ const char *server_rsh; /* Command used to connect to the target host */
unsigned long features; /* Server is required for this features */ unsigned long features; /* Server is required for this features */
unsigned long server_port; /* Port on which daemon is listening */ unsigned long server_port; /* Port on which daemon is listening */
glibtop_sysdeps sysdeps; /* Detailed feature list */
glibtop_sysdeps required; /* Required feature list */
pid_t pid; /* PID of the server */ pid_t pid; /* PID of the server */
}; };

View File

@@ -24,6 +24,7 @@
#include <glibtop.h> #include <glibtop.h>
#include <glibtop/sysdeps.h> #include <glibtop/sysdeps.h>
#include <glibtop/union.h>
__BEGIN_DECLS __BEGIN_DECLS

View File

@@ -60,8 +60,10 @@ struct _glibtop_cpu
extern void glibtop_get_cpu_l __P((glibtop *, glibtop_cpu *)); extern void glibtop_get_cpu_l __P((glibtop *, glibtop_cpu *));
#if GLIBTOP_SUID_CPU #if GLIBTOP_SUID_CPU
extern void glibtop_init_cpu_p __P((glibtop *));
extern void glibtop_get_cpu_p __P((glibtop *, glibtop_cpu *)); extern void glibtop_get_cpu_p __P((glibtop *, glibtop_cpu *));
#else #else
extern void glibtop_init_cpu_s __P((glibtop *));
extern void glibtop_get_cpu_s __P((glibtop *, glibtop_cpu *)); extern void glibtop_get_cpu_s __P((glibtop *, glibtop_cpu *));
#endif #endif

View File

@@ -50,8 +50,10 @@ struct _glibtop_loadavg
extern void glibtop_get_loadavg_l __P((glibtop *, glibtop_loadavg *)); extern void glibtop_get_loadavg_l __P((glibtop *, glibtop_loadavg *));
#if GLIBTOP_SUID_LOADAVG #if GLIBTOP_SUID_LOADAVG
extern void glibtop_init_loadavg_p __P((glibtop *));
extern void glibtop_get_loadavg_p __P((glibtop *, glibtop_loadavg *)); extern void glibtop_get_loadavg_p __P((glibtop *, glibtop_loadavg *));
#else #else
extern void glibtop_init_loadavg_s __P((glibtop *));
extern void glibtop_get_loadavg_s __P((glibtop *, glibtop_loadavg *)); extern void glibtop_get_loadavg_s __P((glibtop *, glibtop_loadavg *));
#endif #endif

View File

@@ -64,8 +64,10 @@ struct _glibtop_mem
extern void glibtop_get_mem_l __P((glibtop *, glibtop_mem *)); extern void glibtop_get_mem_l __P((glibtop *, glibtop_mem *));
#if GLIBTOP_SUID_MEM #if GLIBTOP_SUID_MEM
extern void glibtop_init_mem_p __P((glibtop *));
extern void glibtop_get_mem_p __P((glibtop *, glibtop_mem *)); extern void glibtop_get_mem_p __P((glibtop *, glibtop_mem *));
#else #else
extern void glibtop_init_mem_s __P((glibtop *));
extern void glibtop_get_mem_s __P((glibtop *, glibtop_mem *)); extern void glibtop_get_mem_s __P((glibtop *, glibtop_mem *));
#endif #endif

View File

@@ -62,8 +62,10 @@ struct _glibtop_msg_limits
extern void glibtop_get_msg_limits_l __P((glibtop *, glibtop_msg_limits *)); extern void glibtop_get_msg_limits_l __P((glibtop *, glibtop_msg_limits *));
#if GLIBTOP_SUID_MSG_LIMITS #if GLIBTOP_SUID_MSG_LIMITS
extern void glibtop_init_msg_limits_p __P((glibtop *));
extern void glibtop_get_msg_limits_p __P((glibtop *, glibtop_msg_limits *)); extern void glibtop_get_msg_limits_p __P((glibtop *, glibtop_msg_limits *));
#else #else
extern void glibtop_init_msg_limits_s __P((glibtop *));
extern void glibtop_get_msg_limits_s __P((glibtop *, glibtop_msg_limits *)); extern void glibtop_get_msg_limits_s __P((glibtop *, glibtop_msg_limits *));
#endif #endif

View File

@@ -41,6 +41,13 @@ __BEGIN_DECLS
#define GLIBTOP_METHOD_INET 3 #define GLIBTOP_METHOD_INET 3
#define GLIBTOP_METHOD_UNIX 4 #define GLIBTOP_METHOD_UNIX 4
#define GLIBTOP_ERROR_METHOD_IGNORE 0
#define GLIBTOP_ERROR_METHOD_WARN_ONCE 1
#define GLIBTOP_ERROR_METHOD_WARN 2
#define GLIBTOP_ERROR_METHOD_ABORT 3
#define GLIBTOP_ERROR_METHOD_DEFAULT GLIBTOP_ERROR_METHOD_WARN_ONCE
extern void glibtop_open_l __P((glibtop *, const char *, const unsigned long, const unsigned)); extern void glibtop_open_l __P((glibtop *, const char *, const unsigned long, const unsigned));
extern void glibtop_open_p __P((glibtop *, const char *, const unsigned long, const unsigned)); extern void glibtop_open_p __P((glibtop *, const char *, const unsigned long, const unsigned));

View File

@@ -30,6 +30,7 @@ __BEGIN_DECLS
#define GLIBTOP_PARAM_COMMAND 3 #define GLIBTOP_PARAM_COMMAND 3
#define GLIBTOP_PARAM_HOST 4 #define GLIBTOP_PARAM_HOST 4
#define GLIBTOP_PARAM_PORT 5 #define GLIBTOP_PARAM_PORT 5
#define GLIBTOP_PARAM_ERROR_METHOD 6
#define glibtop_get_parameter(p1,p2,p3) glibtop_get_parameter_l(glibtop_global_server,p1,p2,p3) #define glibtop_get_parameter(p1,p2,p3) glibtop_get_parameter_l(glibtop_global_server,p1,p2,p3)
#define glibtop_set_parameter(p1,p2,p3) glibtop_set_parameter_l(glibtop_global_server,p1,p2,p3) #define glibtop_set_parameter(p1,p2,p3) glibtop_set_parameter_l(glibtop_global_server,p1,p2,p3)

View File

@@ -71,8 +71,10 @@ struct _glibtop_proc_kernel
extern void glibtop_get_proc_kernel_l __P((glibtop *, glibtop_proc_kernel *, pid_t)); extern void glibtop_get_proc_kernel_l __P((glibtop *, glibtop_proc_kernel *, pid_t));
#if GLIBTOP_SUID_PROC_KERNEL #if GLIBTOP_SUID_PROC_KERNEL
extern void glibtop_init_proc_kernel_p __P((glibtop *));
extern void glibtop_get_proc_kernel_p __P((glibtop *, glibtop_proc_kernel *, pid_t)); extern void glibtop_get_proc_kernel_p __P((glibtop *, glibtop_proc_kernel *, pid_t));
#else #else
extern void glibtop_init_proc_kernel_s __P((glibtop *));
extern void glibtop_get_proc_kernel_s __P((glibtop *, glibtop_proc_kernel *, pid_t)); extern void glibtop_get_proc_kernel_s __P((glibtop *, glibtop_proc_kernel *, pid_t));
#endif #endif

View File

@@ -54,8 +54,10 @@ struct _glibtop_proclist
extern unsigned *glibtop_get_proclist_l __P((glibtop *, glibtop_proclist *)); extern unsigned *glibtop_get_proclist_l __P((glibtop *, glibtop_proclist *));
#if GLIBTOP_SUID_PROCLIST #if GLIBTOP_SUID_PROCLIST
extern void glibtop_init_proclist_p __P((glibtop *));
extern unsigned *glibtop_get_proclist_p __P((glibtop *, glibtop_proclist *)); extern unsigned *glibtop_get_proclist_p __P((glibtop *, glibtop_proclist *));
#else #else
extern void glibtop_init_proclist_s __P((glibtop *));
extern unsigned *glibtop_get_proclist_s __P((glibtop *, glibtop_proclist *)); extern unsigned *glibtop_get_proclist_s __P((glibtop *, glibtop_proclist *));
#endif #endif

View File

@@ -64,8 +64,10 @@ struct _glibtop_proc_mem
extern void glibtop_get_proc_mem_l __P((glibtop *, glibtop_proc_mem *, pid_t)); extern void glibtop_get_proc_mem_l __P((glibtop *, glibtop_proc_mem *, pid_t));
#if GLIBTOP_SUID_PROC_MEM #if GLIBTOP_SUID_PROC_MEM
extern void glibtop_init_proc_mem_p __P((glibtop *));
extern void glibtop_get_proc_mem_p __P((glibtop *, glibtop_proc_mem *, pid_t)); extern void glibtop_get_proc_mem_p __P((glibtop *, glibtop_proc_mem *, pid_t));
#else #else
extern void glibtop_init_proc_mem_s __P((glibtop *));
extern void glibtop_get_proc_mem_s __P((glibtop *, glibtop_proc_mem *, pid_t)); extern void glibtop_get_proc_mem_s __P((glibtop *, glibtop_proc_mem *, pid_t));
#endif #endif

View File

@@ -65,8 +65,10 @@ struct _glibtop_proc_segment
extern void glibtop_get_proc_segment_l __P((glibtop *, glibtop_proc_segment *, pid_t)); extern void glibtop_get_proc_segment_l __P((glibtop *, glibtop_proc_segment *, pid_t));
#if GLIBTOP_SUID_PROC_SEGMENT #if GLIBTOP_SUID_PROC_SEGMENT
extern void glibtop_init_proc_segment_p __P((glibtop *));
extern void glibtop_get_proc_segment_p __P((glibtop *, glibtop_proc_segment *, pid_t)); extern void glibtop_get_proc_segment_p __P((glibtop *, glibtop_proc_segment *, pid_t));
#else #else
extern void glibtop_init_proc_segment_s __P((glibtop *));
extern void glibtop_get_proc_segment_s __P((glibtop *, glibtop_proc_segment *, pid_t)); extern void glibtop_get_proc_segment_s __P((glibtop *, glibtop_proc_segment *, pid_t));
#endif #endif

View File

@@ -58,8 +58,10 @@ struct _glibtop_proc_signal
extern void glibtop_get_proc_signal_l __P((glibtop *, glibtop_proc_signal *, pid_t)); extern void glibtop_get_proc_signal_l __P((glibtop *, glibtop_proc_signal *, pid_t));
#if GLIBTOP_SUID_PROC_SIGNAL #if GLIBTOP_SUID_PROC_SIGNAL
extern void glibtop_init_proc_signal_p __P((glibtop *));
extern void glibtop_get_proc_signal_p __P((glibtop *, glibtop_proc_signal *, pid_t)); extern void glibtop_get_proc_signal_p __P((glibtop *, glibtop_proc_signal *, pid_t));
#else #else
extern void glibtop_init_proc_signal_s __P((glibtop *));
extern void glibtop_get_proc_signal_s __P((glibtop *, glibtop_proc_signal *, pid_t)); extern void glibtop_get_proc_signal_s __P((glibtop *, glibtop_proc_signal *, pid_t));
#endif #endif

View File

@@ -65,8 +65,10 @@ struct _glibtop_proc_state
extern void glibtop_get_proc_state_l __P((glibtop *, glibtop_proc_state *, pid_t)); extern void glibtop_get_proc_state_l __P((glibtop *, glibtop_proc_state *, pid_t));
#if GLIBTOP_SUID_PROC_STATE #if GLIBTOP_SUID_PROC_STATE
extern void glibtop_init_proc_state_p __P((glibtop *));
extern void glibtop_get_proc_state_p __P((glibtop *, glibtop_proc_state *, pid_t)); extern void glibtop_get_proc_state_p __P((glibtop *, glibtop_proc_state *, pid_t));
#else #else
extern void glibtop_init_proc_state_s __P((glibtop *));
extern void glibtop_get_proc_state_s __P((glibtop *, glibtop_proc_state *, pid_t)); extern void glibtop_get_proc_state_s __P((glibtop *, glibtop_proc_state *, pid_t));
#endif #endif

View File

@@ -70,8 +70,10 @@ struct _glibtop_proc_time
extern void glibtop_get_proc_time_l __P((glibtop *, glibtop_proc_time *, pid_t)); extern void glibtop_get_proc_time_l __P((glibtop *, glibtop_proc_time *, pid_t));
#if GLIBTOP_SUID_PROC_TIME #if GLIBTOP_SUID_PROC_TIME
extern void glibtop_init_proc_time_p __P((glibtop *));
extern void glibtop_get_proc_time_p __P((glibtop *, glibtop_proc_time *, pid_t)); extern void glibtop_get_proc_time_p __P((glibtop *, glibtop_proc_time *, pid_t));
#else #else
extern void glibtop_init_proc_time_s __P((glibtop *));
extern void glibtop_get_proc_time_s __P((glibtop *, glibtop_proc_time *, pid_t)); extern void glibtop_get_proc_time_s __P((glibtop *, glibtop_proc_time *, pid_t));
#endif #endif

View File

@@ -74,8 +74,10 @@ struct _glibtop_proc_uid
extern void glibtop_get_proc_uid_l __P((glibtop *, glibtop_proc_uid *, pid_t)); extern void glibtop_get_proc_uid_l __P((glibtop *, glibtop_proc_uid *, pid_t));
#if GLIBTOP_SUID_PROC_UID #if GLIBTOP_SUID_PROC_UID
extern void glibtop_init_proc_uid_p __P((glibtop *));
extern void glibtop_get_proc_uid_p __P((glibtop *, glibtop_proc_uid *, pid_t)); extern void glibtop_get_proc_uid_p __P((glibtop *, glibtop_proc_uid *, pid_t));
#else #else
extern void glibtop_init_proc_uid_s __P((glibtop *));
extern void glibtop_get_proc_uid_s __P((glibtop *, glibtop_proc_uid *, pid_t)); extern void glibtop_get_proc_uid_s __P((glibtop *, glibtop_proc_uid *, pid_t));
#endif #endif

View File

@@ -68,8 +68,10 @@ struct _glibtop_sem_limits
extern void glibtop_get_sem_limits_l __P((glibtop *, glibtop_sem_limits *)); extern void glibtop_get_sem_limits_l __P((glibtop *, glibtop_sem_limits *));
#if GLIBTOP_SUID_SEM_LIMITS #if GLIBTOP_SUID_SEM_LIMITS
extern void glibtop_init_sem_limits_p __P((glibtop *));
extern void glibtop_get_sem_limits_p __P((glibtop *, glibtop_sem_limits *)); extern void glibtop_get_sem_limits_p __P((glibtop *, glibtop_sem_limits *));
#else #else
extern void glibtop_init_sem_limits_s __P((glibtop *));
extern void glibtop_get_sem_limits_s __P((glibtop *, glibtop_sem_limits *)); extern void glibtop_get_sem_limits_s __P((glibtop *, glibtop_sem_limits *));
#endif #endif

View File

@@ -58,8 +58,10 @@ struct _glibtop_shm_limits
extern void glibtop_get_shm_limits_l __P((glibtop *, glibtop_shm_limits *)); extern void glibtop_get_shm_limits_l __P((glibtop *, glibtop_shm_limits *));
#if GLIBTOP_SUID_SHM_LIMITS #if GLIBTOP_SUID_SHM_LIMITS
extern void glibtop_init_shm_limits_p __P((glibtop *));
extern void glibtop_get_shm_limits_p __P((glibtop *, glibtop_shm_limits *)); extern void glibtop_get_shm_limits_p __P((glibtop *, glibtop_shm_limits *));
#else #else
extern void glibtop_init_shm_limits_s __P((glibtop *));
extern void glibtop_get_shm_limits_s __P((glibtop *, glibtop_shm_limits *)); extern void glibtop_get_shm_limits_s __P((glibtop *, glibtop_shm_limits *));
#endif #endif

View File

@@ -58,8 +58,10 @@ struct _glibtop_swap
extern void glibtop_get_swap_l __P((glibtop *, glibtop_swap *)); extern void glibtop_get_swap_l __P((glibtop *, glibtop_swap *));
#if GLIBTOP_SUID_SWAP #if GLIBTOP_SUID_SWAP
extern void glibtop_init_swap_p __P((glibtop *));
extern void glibtop_get_swap_p __P((glibtop *, glibtop_swap *)); extern void glibtop_get_swap_p __P((glibtop *, glibtop_swap *));
#else #else
extern void glibtop_init_swap_s __P((glibtop *));
extern void glibtop_get_swap_s __P((glibtop *, glibtop_swap *)); extern void glibtop_get_swap_s __P((glibtop *, glibtop_swap *));
#endif #endif

View File

@@ -23,7 +23,6 @@
#define __GLIBTOP_SYSDEPS_H__ #define __GLIBTOP_SYSDEPS_H__
#include <glibtop.h> #include <glibtop.h>
#include <glibtop/union.h>
__BEGIN_DECLS __BEGIN_DECLS
@@ -51,6 +50,9 @@ __BEGIN_DECLS
#define GLIBTOP_SYSDEPS_ALL ((1 << GLIBTOP_MAX_SYSDEPS) - 1) #define GLIBTOP_SYSDEPS_ALL ((1 << GLIBTOP_MAX_SYSDEPS) - 1)
typedef void (*glibtop_init_func_t) (glibtop *);
extern glibtop_init_func_t _glibtop_init_hook_s [];
typedef struct _glibtop_sysdeps glibtop_sysdeps; typedef struct _glibtop_sysdeps glibtop_sysdeps;
struct _glibtop_sysdeps struct _glibtop_sysdeps

View File

@@ -52,8 +52,10 @@ struct _glibtop_uptime
extern void glibtop_get_uptime_l __P((glibtop *, glibtop_uptime *)); extern void glibtop_get_uptime_l __P((glibtop *, glibtop_uptime *));
#if GLIBTOP_SUID_UPTIME #if GLIBTOP_SUID_UPTIME
extern void glibtop_init_uptime_p __P((glibtop *));
extern void glibtop_get_uptime_p __P((glibtop *, glibtop_uptime *)); extern void glibtop_get_uptime_p __P((glibtop *, glibtop_uptime *));
#else #else
extern void glibtop_init_uptime_s __P((glibtop *));
extern void glibtop_get_uptime_s __P((glibtop *, glibtop_uptime *)); extern void glibtop_get_uptime_s __P((glibtop *, glibtop_uptime *));
#endif #endif

View File

@@ -21,6 +21,7 @@
#include <glibtop.h> #include <glibtop.h>
#include <glibtop/xmalloc.h> #include <glibtop/xmalloc.h>
#include <glibtop/sysdeps.h>
#include <glibtop/parameter.h> #include <glibtop/parameter.h>
#ifndef DEFAULT_PORT #ifndef DEFAULT_PORT
@@ -30,7 +31,6 @@
static glibtop _glibtop_global_server; static glibtop _glibtop_global_server;
glibtop *glibtop_global_server = &_glibtop_global_server; glibtop *glibtop_global_server = &_glibtop_global_server;
void void
_init_server (glibtop *server, const unsigned features) _init_server (glibtop *server, const unsigned features)
{ {
@@ -109,7 +109,7 @@ _init_server (glibtop *server, const unsigned features)
/* Override default. */ /* Override default. */
if (server->server_host) if (server->server_host)
glibtop_free_r (server, (char *) server->server_host); glibtop_free_r (server, server->server_host);
server->server_host = glibtop_strdup_r server->server_host = glibtop_strdup_r
(server, temp+1); (server, temp+1);
@@ -193,19 +193,35 @@ glibtop_init_r (glibtop **server_ptr, const unsigned long features,
} }
glibtop * glibtop *
glibtop_init_s (glibtop **server, const unsigned long features, glibtop_init_s (glibtop **server_ptr, const unsigned long features,
const unsigned flags) const unsigned flags)
{ {
if (*server != NULL) glibtop *server;
return *server; glibtop_init_func_t *init_fkt;
fprintf (stderr, "DEBUG: %s (%d)\n", __FILE__, __LINE__); if (server_ptr == NULL)
return NULL;
if (glibtop_global_server == NULL) { if (*server_ptr == NULL)
glibtop_global_server = &_glibtop_global_server; *server_ptr = glibtop_global_server;
glibtop_open_s (glibtop_global_server, "glibtop",
features, flags); server = *server_ptr;
/* Should we do the initialization? */
if (flags & GLIBTOP_INIT_NO_INIT)
return server;
/* Do the initialization, but only if not already initialized. */
if ((server->flags & _GLIBTOP_INIT_STATE_INIT) == 0) {
glibtop_open_s (server, "glibtop", features, flags);
for (init_fkt = _glibtop_init_hook_s; *init_fkt; init_fkt++)
(*init_fkt) (server);
server->flags |= _GLIBTOP_INIT_STATE_INIT;
} }
return *server = glibtop_global_server; return server;
} }

View File

@@ -5,10 +5,41 @@ BEGIN {
print "#include <glibtop.h>"; print "#include <glibtop.h>";
print "#include <glibtop/open.h>"; print "#include <glibtop/open.h>";
print "";
print "#include <glibtop/sysdeps.h>"; print "#include <glibtop/sysdeps.h>";
print "#include <glibtop/union.h>";
print "";
print "#include <glibtop/command.h>"; print "#include <glibtop/command.h>";
print ""; print "";
print "/* Some required fields are missing. */";
print "";
print "static void";
print "_glibtop_missing_feature (glibtop *server, const char *feature,";
print "\t\t\t const u_int64_t present, u_int64_t *required)";
print "{";
print "\tswitch (server->error_method) {";
print "\tcase GLIBTOP_ERROR_METHOD_WARN_ONCE:";
print "\t\t*required &= present;";
print "\tcase GLIBTOP_ERROR_METHOD_WARN:";
print "\t\tglibtop_warn_r (server,";
print "\t\t\t\t_(\"glibtop_get_%s (): Client requested \"";
print "\t\t\t\t \"field mask %05Lx, but only have %05Lx.\"),";
print "\t\t\t\t feature, required, present);";
print "\t\tbreak;";
print "\tcase GLIBTOP_ERROR_METHOD_ABORT:";
print "\t\tglibtop_error_r (server,";
print "\t\t\t\t _(\"glibtop_get_%s (): Client requested \"";
print "\t\t\t\t \"field mask %05x, but only have %05x.\"),";
print "\t\t\t\t feature, required, present);";
print "\t\tbreak;";
print "\t}";
print "}";
print "";
print "/* Library functions. */";
print "";
} }
function output(line) { function output(line) {
@@ -37,7 +68,7 @@ function output(line) {
print retval; print retval;
if (retval !~ /^void$/) { if (retval !~ /^void$/) {
prefix = "return "; prefix = "retval = ";
prefix_space = " "; prefix_space = " ";
} else { } else {
prefix = ""; prefix = "";
@@ -52,8 +83,15 @@ function output(line) {
} }
print "{"; print "{";
if (retval !~ /^void$/)
print "\t"retval" retval;\n";
print "\tglibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_"toupper(feature)"), 0);"; print "\tglibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_"toupper(feature)"), 0);";
print ""; print "";
print "\t/* If neccessary, we ask the server for the requested";
print "\t * feature. If not, we call the sysdeps function. */";
print "";
print "\tif ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&"; print "\tif ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&";
print "\t (server->features & (1 << GLIBTOP_SYSDEPS_"toupper(feature)")))"; print "\t (server->features & (1 << GLIBTOP_SYSDEPS_"toupper(feature)")))";
print "\t{"; print "\t{";
@@ -77,9 +115,9 @@ function output(line) {
print "#if (!GLIBTOP_SUID_"toupper(feature)")"; print "#if (!GLIBTOP_SUID_"toupper(feature)")";
if (param == "") if (param == "")
print "\t\t"prefix"glibtop_get_"feature"_r (server, buf);"; print "\t\t"prefix"glibtop_get_"feature"_s (server, buf);";
else else
print "\t\t"prefix"glibtop_get_"feature"_r (server, buf, "param");"; print "\t\t"prefix"glibtop_get_"feature"_s (server, buf, "param");";
if (orig !~ /^@/) { if (orig !~ /^@/) {
print "#else"; print "#else";
@@ -89,6 +127,20 @@ function output(line) {
} }
print "\t}"; print "\t}";
print "";
print "\t/* Make sure that all required fields are present. */";
print "";
print "\tif (buf->flags & server->required."feature")";
print "\t\t_glibtop_missing_feature (server, \""feature"\", buf->flags,";
print "\t\t\t\t\t &server->required."feature");";
if (retval !~ /^void$/) {
print "\n\t/* Now we can return. */";
print "\n\treturn retval;";
}
print "}"; print "}";
print ""; print "";
} }

View File

@@ -57,6 +57,8 @@ glibtop_open_l (glibtop *server, const char *program_name,
server->features = features; server->features = features;
server->error_method = GLIBTOP_ERROR_METHOD_DEFAULT;
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "SIZEOF: %u - %u - %u - %u - %u - %u\n", fprintf (stderr, "SIZEOF: %u - %u - %u - %u - %u - %u\n",
sizeof (glibtop_command), sizeof (glibtop_response), sizeof (glibtop_command), sizeof (glibtop_response),

View File

@@ -58,6 +58,9 @@ glibtop_get_parameter_l (glibtop *server, const unsigned parameter,
case GLIBTOP_PARAM_PORT: case GLIBTOP_PARAM_PORT:
_write_data (&server->server_port, _write_data (&server->server_port,
sizeof (server->server_port)); sizeof (server->server_port));
case GLIBTOP_PARAM_ERROR_METHOD:
_write_data (&server->error_method,
sizeof (server->error_method));
} }
return 0; return 0;
@@ -76,5 +79,9 @@ glibtop_set_parameter_l (glibtop *server, const unsigned parameter,
_check_data (sizeof (server->features)); _check_data (sizeof (server->features));
memcpy (&server->features, data_ptr, data_size); memcpy (&server->features, data_ptr, data_size);
break; break;
case GLIBTOP_PARAM_ERROR_METHOD:
_check_data (sizeof (server->error_method));
memcpy (&server->error_method, data_ptr, data_size);
break;
} }
} }

View File

@@ -39,62 +39,62 @@ GLIBTOP_SUID_PROC_SIGNAL +
GLIBTOP_SUID_PROC_KERNEL + GLIBTOP_SUID_PROC_KERNEL +
GLIBTOP_SUID_PROC_SEGMENT; GLIBTOP_SUID_PROC_SEGMENT;
glibtop_init_func_t _glibtop_init_hook_s [] = {
#if !GLIBTOP_SUID_CPU
glibtop_init_cpu_s,
#endif
#if !GLIBTOP_SUID_MEM
glibtop_init_mem_s,
#endif
#if !GLIBTOP_SUID_SWAP
glibtop_init_swap_s,
#endif
#if !GLIBTOP_SUID_UPTIME
glibtop_init_uptime_s,
#endif
#if !GLIBTOP_SUID_LOADAVG
glibtop_init_loadavg_s,
#endif
#if !GLIBTOP_SUID_SHM_LIMITS
glibtop_init_shm_limits_s,
#endif
#if !GLIBTOP_SUID_MSG_LIMITS
glibtop_init_msg_limits_s,
#endif
#if !GLIBTOP_SUID_SEM_LIMITS
glibtop_init_sem_limits_s,
#endif
#if !GLIBTOP_SUID_PROCLIST
glibtop_init_proclist_s,
#endif
#if !GLIBTOP_SUID_PROC_STATE
glibtop_init_proc_state_s,
#endif
#if !GLIBTOP_SUID_PROC_UID
glibtop_init_proc_uid_s,
#endif
#if !GLIBTOP_SUID_PROC_MEM
glibtop_init_proc_mem_s,
#endif
#if !GLIBTOP_SUID_PROC_TIME
glibtop_init_proc_time_s,
#endif
#if !GLIBTOP_SUID_PROC_SIGNAL
glibtop_init_proc_signal_s,
#endif
#if !GLIBTOP_SUID_PROC_KERNEL
glibtop_init_proc_kernel_s,
#endif
#if !GLIBTOP_SUID_PROC_SEGMENT
glibtop_init_proc_segment_s,
#endif
NULL
};
/* Checks which features are implemented. */ /* Checks which features are implemented. */
void void
glibtop_get_sysdeps_r (glibtop *server, glibtop_sysdeps *buf) glibtop_get_sysdeps_r (glibtop *server, glibtop_sysdeps *buf)
{ {
glibtop_union data; memcpy (buf, &server->sysdeps, sizeof (glibtop_sysdeps));
memset (buf, 0, sizeof (glibtop_sysdeps));
buf->features = glibtop_server_features;
/* Call all system dependent functions to check which values
* they return. */
glibtop_get_cpu_l (server, &data.cpu);
buf->cpu = data.cpu.flags;
glibtop_get_mem_l (server, &data.mem);
buf->mem = data.mem.flags;
glibtop_get_swap_l (server, &data.swap);
buf->swap = data.swap.flags;
glibtop_get_uptime_l (server, &data.uptime);
buf->uptime = data.uptime.flags;
glibtop_get_loadavg_l (server, &data.loadavg);
buf->loadavg = data.loadavg.flags;
glibtop_get_shm_limits_l (server, &data.shm_limits);
buf->shm_limits = data.shm_limits.flags;
glibtop_get_msg_limits_l (server, &data.msg_limits);
buf->msg_limits = data.msg_limits.flags;
glibtop_get_sem_limits_l (server, &data.sem_limits);
buf->sem_limits = data.sem_limits.flags;
glibtop_get_proclist_l (server, &data.proclist);
buf->proclist = data.proclist.flags;
glibtop_get_proc_state_l (server, &data.proc_state, 0);
buf->proc_state = data.proc_state.flags;
glibtop_get_proc_uid_l (server, &data.proc_uid, 0);
buf->proc_uid = data.proc_uid.flags;
glibtop_get_proc_mem_l (server, &data.proc_mem, 0);
buf->proc_mem = data.proc_mem.flags;
glibtop_get_proc_time_l (server, &data.proc_time, 0);
buf->proc_time = data.proc_time.flags;
glibtop_get_proc_kernel_l (server, &data.proc_kernel, 0);
buf->proc_kernel = data.proc_kernel.flags;
glibtop_get_proc_segment_l (server, &data.proc_segment, 0);
buf->proc_segment = data.proc_segment.flags;
} }

View File

@@ -6,6 +6,7 @@ BEGIN {
print "#include <glibtop.h>"; print "#include <glibtop.h>";
print "#include <glibtop/xmalloc.h>"; print "#include <glibtop/xmalloc.h>";
print "#include <glibtop/sysdeps.h>"; print "#include <glibtop/sysdeps.h>";
print "#include <glibtop/union.h>";
print ""; print "";
print "#include <guile/gh.h>"; print "#include <guile/gh.h>";

View File

@@ -5,6 +5,7 @@ BEGIN {
print "#include <glibtop.h>"; print "#include <glibtop.h>";
print "#include <glibtop/sysdeps.h>"; print "#include <glibtop/sysdeps.h>";
print "#include <glibtop/union.h>";
print ""; print "";
print "#include <guile/gh.h>"; print "#include <guile/gh.h>";

View File

@@ -30,6 +30,14 @@ static const unsigned long _glibtop_sysdeps_cpu =
(1 << GLIBTOP_CPU_NICE) + (1 << GLIBTOP_CPU_SYS) + (1 << GLIBTOP_CPU_NICE) + (1 << GLIBTOP_CPU_SYS) +
(1 << GLIBTOP_CPU_IDLE) + (1 << GLIBTOP_CPU_FREQUENCY); (1 << GLIBTOP_CPU_IDLE) + (1 << GLIBTOP_CPU_FREQUENCY);
/* Init function. */
void
glibtop_init_cpu_s (glibtop *server)
{
server->sysdeps.cpu = _glibtop_sysdeps_cpu;
}
/* Provides information about cpu usage. */ /* Provides information about cpu usage. */
void void

View File

@@ -28,6 +28,14 @@
static const unsigned long _glibtop_sysdeps_loadavg = static const unsigned long _glibtop_sysdeps_loadavg =
(1 << GLIBTOP_LOADAVG_LOADAVG); (1 << GLIBTOP_LOADAVG_LOADAVG);
/* Init function. */
void
glibtop_init_loadavg_s (glibtop *server)
{
server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
}
/* Provides load load averange. */ /* Provides load load averange. */
void void

View File

@@ -31,6 +31,14 @@ static const unsigned long _glibtop_sysdeps_mem =
(1 << GLIBTOP_MEM_BUFFER) + (1 << GLIBTOP_MEM_CACHED) + (1 << GLIBTOP_MEM_BUFFER) + (1 << GLIBTOP_MEM_CACHED) +
(1 << GLIBTOP_MEM_USER); (1 << GLIBTOP_MEM_USER);
/* Init function. */
void
glibtop_init_mem_s (glibtop *server)
{
server->sysdeps.mem = _glibtop_sysdeps_mem;
}
/* Provides information about memory usage. */ /* Provides information about memory usage. */
void void

View File

@@ -30,6 +30,14 @@ static const unsigned long _glibtop_sysdeps_msg_limits =
(1 << GLIBTOP_IPC_MSGMNI) + (1 << GLIBTOP_IPC_MSGSSZ) + (1 << GLIBTOP_IPC_MSGMNI) + (1 << GLIBTOP_IPC_MSGSSZ) +
(1 << GLIBTOP_IPC_MSGTQL); (1 << 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. */ /* Provides information about sysv ipc limits. */
void void

View File

@@ -31,6 +31,14 @@ static const unsigned long _glibtop_sysdeps_proc_kernel =
(1 << GLIBTOP_PROC_KERNEL_CMAJ_FLT) + (1 << GLIBTOP_PROC_KERNEL_KSTK_ESP) + (1 << GLIBTOP_PROC_KERNEL_CMAJ_FLT) + (1 << GLIBTOP_PROC_KERNEL_KSTK_ESP) +
(1 << GLIBTOP_PROC_KERNEL_KSTK_EIP) + (1 << GLIBTOP_PROC_KERNEL_WCHAN); (1 << GLIBTOP_PROC_KERNEL_KSTK_EIP) + (1 << 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. */ /* Provides detailed information about a process. */
void void
@@ -43,12 +51,6 @@ glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf,
memset (buf, 0, sizeof (glibtop_proc_kernel)); memset (buf, 0, sizeof (glibtop_proc_kernel));
if (pid == 0) {
/* Client is only interested in the flags. */
buf->flags = _glibtop_sysdeps_proc_kernel;
return;
}
if (table (TABLE_PROC_KERNEL, &tbl, &pid)) if (table (TABLE_PROC_KERNEL, &tbl, &pid))
glibtop_error_io_r (server, "table(TABLE_PROC_KERNEL)"); glibtop_error_io_r (server, "table(TABLE_PROC_KERNEL)");

View File

@@ -29,6 +29,14 @@ static const unsigned long _glibtop_sysdeps_proclist =
(1 << GLIBTOP_PROCLIST_TOTAL) + (1 << GLIBTOP_PROCLIST_NUMBER) + (1 << GLIBTOP_PROCLIST_TOTAL) + (1 << GLIBTOP_PROCLIST_NUMBER) +
(1 << GLIBTOP_PROCLIST_SIZE); (1 << GLIBTOP_PROCLIST_SIZE);
/* Init function. */
void
glibtop_init_proclist_s (glibtop *server)
{
server->sysdeps.proclist = _glibtop_sysdeps_proclist;
}
#define BLOCK_COUNT 256 #define BLOCK_COUNT 256
#define BLOCK_SIZE (BLOCK_COUNT * sizeof (unsigned)) #define BLOCK_SIZE (BLOCK_COUNT * sizeof (unsigned))

View File

@@ -30,6 +30,14 @@ static const unsigned long _glibtop_sysdeps_proc_mem =
(1 << GLIBTOP_PROC_MEM_RESIDENT) + (1 << GLIBTOP_PROC_MEM_SHARE) + (1 << GLIBTOP_PROC_MEM_RESIDENT) + (1 << GLIBTOP_PROC_MEM_SHARE) +
(1 << GLIBTOP_PROC_MEM_RSS) + (1 << GLIBTOP_PROC_MEM_RSS_RLIM); (1 << GLIBTOP_PROC_MEM_RSS) + (1 << GLIBTOP_PROC_MEM_RSS_RLIM);
/* Init function. */
void
glibtop_init_proc_mem_s (glibtop *server)
{
server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem;
}
/* Provides detailed information about a process. */ /* Provides detailed information about a process. */
void void
@@ -42,12 +50,6 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf,
memset (buf, 0, sizeof (glibtop_proc_mem)); memset (buf, 0, sizeof (glibtop_proc_mem));
if (pid == 0) {
/* Client is only interested in the flags. */
buf->flags = _glibtop_sysdeps_proc_mem;
return;
}
if (table (TABLE_PROC_MEM, &tbl, &pid)) if (table (TABLE_PROC_MEM, &tbl, &pid))
glibtop_error_io_r (server, "table(TABLE_PROC_MEM)"); glibtop_error_io_r (server, "table(TABLE_PROC_MEM)");

View File

@@ -31,6 +31,14 @@ static const unsigned long _glibtop_sysdeps_proc_segment =
(1 << GLIBTOP_PROC_SEGMENT_START_CODE) + (1 << GLIBTOP_PROC_SEGMENT_END_CODE) + (1 << GLIBTOP_PROC_SEGMENT_START_CODE) + (1 << GLIBTOP_PROC_SEGMENT_END_CODE) +
(1 << GLIBTOP_PROC_SEGMENT_START_STACK); (1 << GLIBTOP_PROC_SEGMENT_START_STACK);
/* Init function. */
void
glibtop_init_proc_segment_s (glibtop *server)
{
server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment;
}
/* Provides detailed information about a process. */ /* Provides detailed information about a process. */
void void
@@ -43,12 +51,6 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
memset (buf, 0, sizeof (glibtop_proc_segment)); memset (buf, 0, sizeof (glibtop_proc_segment));
if (pid == 0) {
/* Client is only interested in the flags. */
buf->flags = _glibtop_sysdeps_proc_segment;
return;
}
if (table (TABLE_PROC_MEM, &tbl, &pid)) if (table (TABLE_PROC_MEM, &tbl, &pid))
glibtop_error_io_r (server, "table(TABLE_PROC_MEM)"); glibtop_error_io_r (server, "table(TABLE_PROC_MEM)");

View File

@@ -29,6 +29,14 @@ static const unsigned long _glibtop_sysdeps_proc_signal =
(1 << GLIBTOP_PROC_SIGNAL_SIGNAL) + (1 << GLIBTOP_PROC_SIGNAL_BLOCKED) + (1 << GLIBTOP_PROC_SIGNAL_SIGNAL) + (1 << GLIBTOP_PROC_SIGNAL_BLOCKED) +
(1 << GLIBTOP_PROC_SIGNAL_SIGIGNORE) + (1 << GLIBTOP_PROC_SIGNAL_SIGCATCH); (1 << GLIBTOP_PROC_SIGNAL_SIGIGNORE) + (1 << 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. */ /* Provides detailed information about a process. */
void void
@@ -41,12 +49,6 @@ glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf,
memset (buf, 0, sizeof (glibtop_proc_signal)); memset (buf, 0, sizeof (glibtop_proc_signal));
if (pid == 0) {
/* Client is only interested in the flags. */
buf->flags = _glibtop_sysdeps_proc_signal;
return;
}
if (table (TABLE_PROC_SIGNAL, &tbl, &pid)) if (table (TABLE_PROC_SIGNAL, &tbl, &pid))
glibtop_error_io_r (server, "table(TABLE_PROC_SIGNAL)"); glibtop_error_io_r (server, "table(TABLE_PROC_SIGNAL)");

View File

@@ -28,6 +28,14 @@
static const unsigned long _glibtop_sysdeps_proc_state = static const unsigned long _glibtop_sysdeps_proc_state =
(1 << GLIBTOP_PROC_STATE_CMD) + (1 << GLIBTOP_PROC_STATE_STATE); (1 << GLIBTOP_PROC_STATE_CMD) + (1 << GLIBTOP_PROC_STATE_STATE);
/* Init function. */
void
glibtop_init_proc_state_s (glibtop *server)
{
server->sysdeps.proc_state = _glibtop_sysdeps_proc_state;
}
/* Provides detailed information about a process. */ /* Provides detailed information about a process. */
#define NR_STATES 7 #define NR_STATES 7
@@ -45,12 +53,6 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf,
memset (buf, 0, sizeof (glibtop_proc_state)); memset (buf, 0, sizeof (glibtop_proc_state));
if (pid == 0) {
/* Client is only interested in the flags. */
buf->flags = _glibtop_sysdeps_proc_state;
return;
}
if (table (TABLE_PROC_STATE, &tbl, &pid)) if (table (TABLE_PROC_STATE, &tbl, &pid))
glibtop_error_io_r (server, "table(TABLE_PROC_STATE)"); glibtop_error_io_r (server, "table(TABLE_PROC_STATE)");

View File

@@ -31,6 +31,14 @@ static const unsigned long _glibtop_sysdeps_proc_time =
(1 << GLIBTOP_PROC_TIME_TIMEOUT) + (1 << GLIBTOP_PROC_TIME_IT_REAL_VALUE) + (1 << GLIBTOP_PROC_TIME_TIMEOUT) + (1 << GLIBTOP_PROC_TIME_IT_REAL_VALUE) +
(1 << GLIBTOP_PROC_TIME_START_TIME); (1 << GLIBTOP_PROC_TIME_START_TIME);
/* Init function. */
void
glibtop_init_proc_time_s (glibtop *server)
{
server->sysdeps.proc_time = _glibtop_sysdeps_proc_time;
}
/* Provides detailed information about a process. */ /* Provides detailed information about a process. */
void void
@@ -43,12 +51,6 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf,
memset (buf, 0, sizeof (glibtop_proc_time)); memset (buf, 0, sizeof (glibtop_proc_time));
if (pid == 0) {
/* Client is only interested in the flags. */
buf->flags = _glibtop_sysdeps_proc_time;
return;
}
if (table (TABLE_PROC_TIME, &tbl, &pid)) if (table (TABLE_PROC_TIME, &tbl, &pid))
glibtop_error_io_r (server, "table(TABLE_PROC_TIME)"); glibtop_error_io_r (server, "table(TABLE_PROC_TIME)");

View File

@@ -33,6 +33,14 @@ static const unsigned long _glibtop_sysdeps_proc_uid =
(1 << GLIBTOP_PROC_UID_TTY) + (1 << GLIBTOP_PROC_UID_TPGID) + (1 << GLIBTOP_PROC_UID_TTY) + (1 << GLIBTOP_PROC_UID_TPGID) +
(1 << GLIBTOP_PROC_UID_PRIORITY) + (1 << GLIBTOP_PROC_UID_NICE); (1 << GLIBTOP_PROC_UID_PRIORITY) + (1 << GLIBTOP_PROC_UID_NICE);
/* Init function. */
void
glibtop_init_proc_uid_s (glibtop *server)
{
server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid;
}
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z) #define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
/* Provides detailed information about a process. */ /* Provides detailed information about a process. */
@@ -48,12 +56,6 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf,
memset (buf, 0, sizeof (glibtop_proc_uid)); memset (buf, 0, sizeof (glibtop_proc_uid));
if (pid == 0) {
/* Client is only interested in the flags. */
buf->flags = _glibtop_sysdeps_proc_uid;
return;
}
if (table (TABLE_PROC_UID, &tbl, &pid)) if (table (TABLE_PROC_UID, &tbl, &pid))
glibtop_error_io_r (server, "table(TABLE_PROC_UID)"); glibtop_error_io_r (server, "table(TABLE_PROC_UID)");

View File

@@ -24,6 +24,21 @@
#include <sys/ipc.h> #include <sys/ipc.h>
#include <sys/sem.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 = static unsigned long _glibtop_sysdeps_sem_limits =
(1 << GLIBTOP_IPC_SEMMAP) + (1 << GLIBTOP_IPC_SEMMNI) + (1 << GLIBTOP_IPC_SEMMAP) + (1 << GLIBTOP_IPC_SEMMNI) +
(1 << GLIBTOP_IPC_SEMMNS) + (1 << GLIBTOP_IPC_SEMMNU) + (1 << GLIBTOP_IPC_SEMMNS) + (1 << GLIBTOP_IPC_SEMMNU) +
@@ -31,6 +46,14 @@ static unsigned long _glibtop_sysdeps_sem_limits =
(1 << GLIBTOP_IPC_SEMUME) + (1 << GLIBTOP_IPC_SEMUSZ) + (1 << GLIBTOP_IPC_SEMUME) + (1 << GLIBTOP_IPC_SEMUSZ) +
(1 << GLIBTOP_IPC_SEMVMX) + (1 << GLIBTOP_IPC_SEMAEM); (1 << GLIBTOP_IPC_SEMVMX) + (1 << 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. */ /* Provides information about sysv ipc limits. */
void void

View File

@@ -29,6 +29,14 @@ static unsigned long _glibtop_sysdeps_shm_limits =
(1 << GLIBTOP_IPC_SHMMNI) + (1 << GLIBTOP_IPC_SHMSEG) + (1 << GLIBTOP_IPC_SHMMNI) + (1 << GLIBTOP_IPC_SHMSEG) +
(1 << GLIBTOP_IPC_SHMALL); (1 << 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. */ /* Provides information about sysv ipc limits. */
void void

View File

@@ -30,6 +30,14 @@ static unsigned long _glibtop_sysdeps_swap =
(1 << GLIBTOP_SWAP_FREE) + (1 << GLIBTOP_SWAP_PAGEIN) + (1 << GLIBTOP_SWAP_FREE) + (1 << GLIBTOP_SWAP_PAGEIN) +
(1 << GLIBTOP_SWAP_PAGEOUT); (1 << GLIBTOP_SWAP_PAGEOUT);
/* Init function. */
void
glibtop_init_swap_s (glibtop *server)
{
server->sysdeps.swap = _glibtop_sysdeps_swap;
}
/* Provides information about swap usage. */ /* Provides information about swap usage. */
void void

View File

@@ -28,6 +28,14 @@
static unsigned long _glibtop_sysdeps_uptime = static unsigned long _glibtop_sysdeps_uptime =
(1 << GLIBTOP_UPTIME_UPTIME) + (1 << GLIBTOP_UPTIME_IDLETIME); (1 << GLIBTOP_UPTIME_UPTIME) + (1 << GLIBTOP_UPTIME_IDLETIME);
/* Init function. */
void
glibtop_init_uptime_s (glibtop *server)
{
server->sysdeps.uptime = _glibtop_sysdeps_uptime;
}
/* Provides uptime and idle time. */ /* Provides uptime and idle time. */
void void

View File

@@ -28,6 +28,14 @@ static const unsigned long _glibtop_sysdeps_cpu =
(1 << GLIBTOP_CPU_NICE) + (1 << GLIBTOP_CPU_SYS) + (1 << GLIBTOP_CPU_NICE) + (1 << GLIBTOP_CPU_SYS) +
(1 << GLIBTOP_CPU_IDLE) + (1 << GLIBTOP_CPU_FREQUENCY); (1 << GLIBTOP_CPU_IDLE) + (1 << GLIBTOP_CPU_FREQUENCY);
/* Init function. */
void
glibtop_init_cpu_s (glibtop *server)
{
server->sysdeps.cpu = _glibtop_sysdeps_cpu;
}
/* Provides information about cpu usage. */ /* Provides information about cpu usage. */
#define FILENAME "/proc/stat" #define FILENAME "/proc/stat"
@@ -37,7 +45,7 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
{ {
FILE *f; FILE *f;
glibtop_init_s (&server, 0, 0); glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
memset (buf, 0, sizeof (glibtop_cpu)); memset (buf, 0, sizeof (glibtop_cpu));

View File

@@ -26,16 +26,24 @@
static const unsigned long _glibtop_sysdeps_loadavg = static const unsigned long _glibtop_sysdeps_loadavg =
(1 << GLIBTOP_LOADAVG_LOADAVG); (1 << GLIBTOP_LOADAVG_LOADAVG);
#define FILENAME "/proc/loadavg" /* Init function. */
void
glibtop_init_loadavg_s (glibtop *server)
{
server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
}
/* Provides load load averange. */ /* Provides load load averange. */
#define FILENAME "/proc/loadavg"
void void
glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf) glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
{ {
FILE *f; FILE *f;
glibtop_init_s (&server, 0, 0); glibtop_init_s (&server, GLIBTOP_SYSDEPS_LOADAVG, 0);
memset (buf, 0, sizeof (glibtop_loadavg)); memset (buf, 0, sizeof (glibtop_loadavg));

View File

@@ -29,16 +29,24 @@ static const unsigned long _glibtop_sysdeps_mem =
(1 << GLIBTOP_MEM_BUFFER) + (1 << GLIBTOP_MEM_CACHED) + (1 << GLIBTOP_MEM_BUFFER) + (1 << GLIBTOP_MEM_CACHED) +
(1 << GLIBTOP_MEM_USER); (1 << GLIBTOP_MEM_USER);
#define FILENAME "/proc/meminfo" /* Init function. */
void
glibtop_init_mem_s (glibtop *server)
{
server->sysdeps.mem = _glibtop_sysdeps_mem;
}
/* Provides information about memory usage. */ /* Provides information about memory usage. */
#define FILENAME "/proc/meminfo"
void void
glibtop_get_mem_s (glibtop *server, glibtop_mem *buf) glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
{ {
FILE *f; FILE *f;
glibtop_init_s (&server, 0, 0); glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);
memset (buf, 0, sizeof (glibtop_mem)); memset (buf, 0, sizeof (glibtop_mem));

View File

@@ -30,6 +30,14 @@ static const unsigned long _glibtop_sysdeps_msg_limits =
(1 << GLIBTOP_IPC_MSGMNI) + (1 << GLIBTOP_IPC_MSGSSZ) + (1 << GLIBTOP_IPC_MSGMNI) + (1 << GLIBTOP_IPC_MSGSSZ) +
(1 << GLIBTOP_IPC_MSGTQL); (1 << 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. */ /* Provides information about sysv ipc limits. */
void void
@@ -37,7 +45,7 @@ glibtop_get_msg_limits_s (glibtop *server, glibtop_msg_limits *buf)
{ {
struct msginfo msginfo; struct msginfo msginfo;
glibtop_init_s (&server, 0, 0); glibtop_init_s (&server, GLIBTOP_SYSDEPS_MSG_LIMITS, 0);
memset (buf, 0, sizeof (glibtop_msg_limits)); memset (buf, 0, sizeof (glibtop_msg_limits));

View File

@@ -29,6 +29,14 @@ static const unsigned long _glibtop_sysdeps_proc_kernel =
(1 << GLIBTOP_PROC_KERNEL_CMAJ_FLT) + (1 << GLIBTOP_PROC_KERNEL_KSTK_ESP) + (1 << GLIBTOP_PROC_KERNEL_CMAJ_FLT) + (1 << GLIBTOP_PROC_KERNEL_KSTK_ESP) +
(1 << GLIBTOP_PROC_KERNEL_KSTK_EIP) + (1 << GLIBTOP_PROC_KERNEL_WCHAN); (1 << GLIBTOP_PROC_KERNEL_KSTK_EIP) + (1 << 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. */ /* Provides detailed information about a process. */
void void
@@ -38,16 +46,10 @@ glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid)
int nread; int nread;
FILE *f; FILE *f;
glibtop_init_s (&server, 0, 0); glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_KERNEL, 0);
memset (buf, 0, sizeof (glibtop_proc_kernel)); memset (buf, 0, sizeof (glibtop_proc_kernel));
if (pid == 0) {
/* Client is only interested in the flags. */
buf->flags = _glibtop_sysdeps_proc_kernel;
return;
}
sprintf (input, "/proc/%d/stat", pid); sprintf (input, "/proc/%d/stat", pid);
f = fopen (input, "r"); f = fopen (input, "r");

View File

@@ -32,6 +32,14 @@ static const unsigned long _glibtop_sysdeps_proclist =
(1 << GLIBTOP_PROCLIST_TOTAL) + (1 << GLIBTOP_PROCLIST_NUMBER) + (1 << GLIBTOP_PROCLIST_TOTAL) + (1 << GLIBTOP_PROCLIST_NUMBER) +
(1 << GLIBTOP_PROCLIST_SIZE); (1 << GLIBTOP_PROCLIST_SIZE);
/* Init function. */
void
glibtop_init_proclist_s (glibtop *server)
{
server->sysdeps.proclist = _glibtop_sysdeps_proclist;
}
#define BLOCK_COUNT 256 #define BLOCK_COUNT 256
#define BLOCK_SIZE (BLOCK_COUNT * sizeof (unsigned)) #define BLOCK_SIZE (BLOCK_COUNT * sizeof (unsigned))
@@ -60,7 +68,7 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf)
struct stat statb; struct stat statb;
int len, i, ok; int len, i, ok;
glibtop_init_s (&server, 0, 0); glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROCLIST, 0);
memset (buf, 0, sizeof (glibtop_proclist)); memset (buf, 0, sizeof (glibtop_proclist));
@@ -69,7 +77,8 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf)
/* read every every entry in /proc */ /* read every every entry in /proc */
for (count = total = 0, entry = readdir (proc); entry; entry = readdir (proc)) { for (count = total = 0, entry = readdir (proc);
entry; entry = readdir (proc)) {
ok = 1; len = strlen (entry->d_name); ok = 1; len = strlen (entry->d_name);
/* does it consist entirely of digits? */ /* does it consist entirely of digits? */
@@ -94,14 +103,15 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf)
* full, we copy it to the pids_chain. */ * full, we copy it to the pids_chain. */
if (count >= BLOCK_COUNT) { if (count >= BLOCK_COUNT) {
/* The following call to glibtop_realloc will be equivalent to /* The following call to glibtop_realloc will be
* glibtop_malloc if pids_chain is NULL. We just calculate the * equivalent to glibtop_malloc () if `pids_chain' is
* new size and copy pids to the beginning of the newly allocated * NULL. We just calculate the new size and copy `pids'
* block. */ * to the beginning of the newly allocated block. */
new_size = pids_size + BLOCK_SIZE; new_size = pids_size + BLOCK_SIZE;
pids_chain = glibtop_realloc_r (server, pids_chain, new_size); pids_chain = glibtop_realloc_r
(server, pids_chain, new_size);
memcpy (pids_chain + pids_offset, pids, BLOCK_SIZE); memcpy (pids_chain + pids_offset, pids, BLOCK_SIZE);
@@ -121,8 +131,8 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf)
closedir (proc); closedir (proc);
/* count is only zero if an error occured (one a running Linux system, we /* count is only zero if an error occured (one a running Linux system,
* only have at least one single process). */ * we have at least one single process). */
if (!count) return NULL; if (!count) return NULL;
@@ -141,8 +151,8 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf)
pids_offset += BLOCK_COUNT; pids_offset += BLOCK_COUNT;
/* Since everything is ok now, we can set buf->flags, fill in the remaining fields /* Since everything is ok now, we can set buf->flags, fill in the
and return pids_chain. */ * remaining fields and return the `pids_chain'. */
buf->flags = _glibtop_sysdeps_proclist; buf->flags = _glibtop_sysdeps_proclist;

View File

@@ -28,6 +28,14 @@ static const unsigned long _glibtop_sysdeps_proc_mem =
(1 << GLIBTOP_PROC_MEM_RESIDENT) + (1 << GLIBTOP_PROC_MEM_SHARE) + (1 << GLIBTOP_PROC_MEM_RESIDENT) + (1 << GLIBTOP_PROC_MEM_SHARE) +
(1 << GLIBTOP_PROC_MEM_RSS) + (1 << GLIBTOP_PROC_MEM_RSS_RLIM); (1 << GLIBTOP_PROC_MEM_RSS) + (1 << GLIBTOP_PROC_MEM_RSS_RLIM);
/* Init function. */
void
glibtop_init_proc_mem_s (glibtop *server)
{
server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem;
}
/* Provides detailed information about a process. */ /* Provides detailed information about a process. */
void void
@@ -37,16 +45,10 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
int nread; int nread;
FILE *f; FILE *f;
glibtop_init_s (&server, 0, 0); glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);
memset (buf, 0, sizeof (glibtop_proc_mem)); memset (buf, 0, sizeof (glibtop_proc_mem));
if (pid == 0) {
/* Client is only interested in the flags. */
buf->flags = _glibtop_sysdeps_proc_mem;
return;
}
sprintf (input, "/proc/%d/stat", pid); sprintf (input, "/proc/%d/stat", pid);
f = fopen (input, "r"); f = fopen (input, "r");

View File

@@ -29,6 +29,14 @@ static const unsigned long _glibtop_sysdeps_proc_segment =
(1 << GLIBTOP_PROC_SEGMENT_START_CODE) + (1 << GLIBTOP_PROC_SEGMENT_END_CODE) + (1 << GLIBTOP_PROC_SEGMENT_START_CODE) + (1 << GLIBTOP_PROC_SEGMENT_END_CODE) +
(1 << GLIBTOP_PROC_SEGMENT_START_STACK); (1 << GLIBTOP_PROC_SEGMENT_START_STACK);
/* Init function. */
void
glibtop_init_proc_segment_s (glibtop *server)
{
server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment;
}
/* Provides detailed information about a process. */ /* Provides detailed information about a process. */
void void
@@ -39,16 +47,10 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
int nread; int nread;
FILE *f; FILE *f;
glibtop_init_s (&server, 0, 0); glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_SEGMENT, 0);
memset (buf, 0, sizeof (glibtop_proc_segment)); memset (buf, 0, sizeof (glibtop_proc_segment));
if (pid == 0) {
/* Client is only interested in the flags. */
buf->flags = _glibtop_sysdeps_proc_segment;
return;
}
sprintf (input, "/proc/%d/stat", pid); sprintf (input, "/proc/%d/stat", pid);
f = fopen (input, "r"); f = fopen (input, "r");

View File

@@ -27,6 +27,14 @@ static const unsigned long _glibtop_sysdeps_proc_signal =
(1 << GLIBTOP_PROC_SIGNAL_SIGNAL) + (1 << GLIBTOP_PROC_SIGNAL_BLOCKED) + (1 << GLIBTOP_PROC_SIGNAL_SIGNAL) + (1 << GLIBTOP_PROC_SIGNAL_BLOCKED) +
(1 << GLIBTOP_PROC_SIGNAL_SIGIGNORE) + (1 << GLIBTOP_PROC_SIGNAL_SIGCATCH); (1 << GLIBTOP_PROC_SIGNAL_SIGIGNORE) + (1 << 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. */ /* Provides detailed information about a process. */
void void
@@ -36,16 +44,10 @@ glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid)
int nread; int nread;
FILE *f; FILE *f;
glibtop_init_s (&server, 0, 0); glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_SIGNAL, 0);
memset (buf, 0, sizeof (glibtop_proc_signal)); memset (buf, 0, sizeof (glibtop_proc_signal));
if (pid == 0) {
/* Client is only interested in the flags. */
buf->flags = _glibtop_sysdeps_proc_signal;
return;
}
sprintf (input, "/proc/%d/stat", pid); sprintf (input, "/proc/%d/stat", pid);
f = fopen (input, "r"); f = fopen (input, "r");

View File

@@ -29,6 +29,14 @@ static const unsigned long _glibtop_sysdeps_proc_state =
(1 << GLIBTOP_PROC_STATE_CMD) + (1 << GLIBTOP_PROC_STATE_STATE) + (1 << GLIBTOP_PROC_STATE_CMD) + (1 << GLIBTOP_PROC_STATE_STATE) +
(1 << GLIBTOP_PROC_STATE_UID) + (1 << GLIBTOP_PROC_STATE_GID); (1 << GLIBTOP_PROC_STATE_UID) + (1 << GLIBTOP_PROC_STATE_GID);
/* Init function. */
void
glibtop_init_proc_state_s (glibtop *server)
{
server->sysdeps.proc_state = _glibtop_sysdeps_proc_state;
}
/* Provides detailed information about a process. */ /* Provides detailed information about a process. */
void void
@@ -39,16 +47,10 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
int nread; int nread;
FILE *f; FILE *f;
glibtop_init_s (&server, 0, 0); glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_STATE, 0);
memset (buf, 0, sizeof (glibtop_proc_state)); memset (buf, 0, sizeof (glibtop_proc_state));
if (pid == 0) {
/* Client is only interested in the flags. */
buf->flags = _glibtop_sysdeps_proc_state;
return;
}
sprintf (input, "/proc/%d/stat", pid); sprintf (input, "/proc/%d/stat", pid);
/* IMPORTANT NOTICE: For security reasons it is extremely important /* IMPORTANT NOTICE: For security reasons it is extremely important

View File

@@ -29,6 +29,14 @@ static const unsigned long _glibtop_sysdeps_proc_time =
(1 << GLIBTOP_PROC_TIME_CSTIME) + (1 << GLIBTOP_PROC_TIME_TIMEOUT) + (1 << GLIBTOP_PROC_TIME_CSTIME) + (1 << GLIBTOP_PROC_TIME_TIMEOUT) +
(1 << GLIBTOP_PROC_TIME_IT_REAL_VALUE); (1 << GLIBTOP_PROC_TIME_IT_REAL_VALUE);
/* Init function. */
void
glibtop_init_proc_time_s (glibtop *server)
{
server->sysdeps.proc_time = _glibtop_sysdeps_proc_time;
}
/* Provides detailed information about a process. */ /* Provides detailed information about a process. */
void void
@@ -38,16 +46,10 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
int nread; int nread;
FILE *f; FILE *f;
glibtop_init_s (&server, 0, 0); glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_TIME, 0);
memset (buf, 0, sizeof (glibtop_proc_time)); memset (buf, 0, sizeof (glibtop_proc_time));
if (pid == 0) {
/* Client is only interested in the flags. */
buf->flags = _glibtop_sysdeps_proc_time;
return;
}
sprintf (input, "/proc/%d/stat", pid); sprintf (input, "/proc/%d/stat", pid);
f = fopen (input, "r"); f = fopen (input, "r");

View File

@@ -33,6 +33,14 @@ static const unsigned long _glibtop_sysdeps_proc_uid =
#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z) #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;
}
/* Provides detailed information about a process. */ /* Provides detailed information about a process. */
void void
@@ -42,16 +50,10 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
int nread; int nread;
FILE *f; FILE *f;
glibtop_init_s (&server, 0, 0); glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_UID, 0);
memset (buf, 0, sizeof (glibtop_proc_uid)); memset (buf, 0, sizeof (glibtop_proc_uid));
if (pid == 0) {
/* Client is only interested in the flags. */
buf->flags = _glibtop_sysdeps_proc_uid;
return;
}
sprintf (input, "/proc/%d/status", pid); sprintf (input, "/proc/%d/status", pid);
f = fopen (input, "r"); f = fopen (input, "r");

View File

@@ -25,6 +25,11 @@
#include <sys/sem.h> #include <sys/sem.h>
#ifdef _SEM_SEMUN_UNDEFINED #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 union semun
{ {
int val; int val;
@@ -41,6 +46,14 @@ static unsigned long _glibtop_sysdeps_sem_limits =
(1 << GLIBTOP_IPC_SEMUME) + (1 << GLIBTOP_IPC_SEMUSZ) + (1 << GLIBTOP_IPC_SEMUME) + (1 << GLIBTOP_IPC_SEMUSZ) +
(1 << GLIBTOP_IPC_SEMVMX) + (1 << GLIBTOP_IPC_SEMAEM); (1 << GLIBTOP_IPC_SEMVMX) + (1 << 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. */ /* Provides information about sysv ipc limits. */
void void
@@ -49,7 +62,7 @@ glibtop_get_sem_limits_s (glibtop *server, glibtop_sem_limits *buf)
struct seminfo seminfo; struct seminfo seminfo;
union semun arg; union semun arg;
glibtop_init_s (&server, 0, 0); glibtop_init_s (&server, GLIBTOP_SYSDEPS_SEM_LIMITS, 0);
memset (buf, 0, sizeof (glibtop_sem_limits)); memset (buf, 0, sizeof (glibtop_sem_limits));

View File

@@ -29,6 +29,14 @@ static unsigned long _glibtop_sysdeps_shm_limits =
(1 << GLIBTOP_IPC_SHMMNI) + (1 << GLIBTOP_IPC_SHMSEG) + (1 << GLIBTOP_IPC_SHMMNI) + (1 << GLIBTOP_IPC_SHMSEG) +
(1 << GLIBTOP_IPC_SHMALL); (1 << 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. */ /* Provides information about sysv ipc limits. */
void void
@@ -36,7 +44,7 @@ glibtop_get_shm_limits_s (glibtop *server, glibtop_shm_limits *buf)
{ {
struct shminfo shminfo; struct shminfo shminfo;
glibtop_init_s (&server, 0, 0); glibtop_init_s (&server, GLIBTOP_SYSDEPS_SHM_LIMITS, 0);
memset (buf, 0, sizeof (glibtop_shm_limits)); memset (buf, 0, sizeof (glibtop_shm_limits));

View File

@@ -30,10 +30,18 @@ static unsigned long _glibtop_sysdeps_swap =
(1 << GLIBTOP_SWAP_FREE) + (1 << GLIBTOP_SWAP_PAGEIN) + (1 << GLIBTOP_SWAP_FREE) + (1 << GLIBTOP_SWAP_PAGEIN) +
(1 << GLIBTOP_SWAP_PAGEOUT); (1 << GLIBTOP_SWAP_PAGEOUT);
#define FILENAME "/proc/meminfo" /* Init function. */
void
glibtop_init_swap_s (glibtop *server)
{
server->sysdeps.swap = _glibtop_sysdeps_swap;
}
/* Provides information about swap usage. */ /* Provides information about swap usage. */
#define FILENAME "/proc/meminfo"
void void
glibtop_get_swap_s (glibtop *server, glibtop_swap *buf) glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
{ {
@@ -41,7 +49,7 @@ glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
int fd, len; int fd, len;
FILE *f; FILE *f;
glibtop_init_s (&server, 0, 0); glibtop_init_s (&server, GLIBTOP_SYSDEPS_SWAP, 0);
memset (buf, 0, sizeof (glibtop_swap)); memset (buf, 0, sizeof (glibtop_swap));

View File

@@ -26,16 +26,24 @@
static unsigned long _glibtop_sysdeps_uptime = static unsigned long _glibtop_sysdeps_uptime =
(1 << GLIBTOP_UPTIME_UPTIME) + (1 << GLIBTOP_UPTIME_IDLETIME); (1 << GLIBTOP_UPTIME_UPTIME) + (1 << GLIBTOP_UPTIME_IDLETIME);
#define FILENAME "/proc/uptime" /* Init function. */
void
glibtop_init_uptime_s (glibtop *server)
{
server->sysdeps.uptime = _glibtop_sysdeps_uptime;
}
/* Provides uptime and idle time. */ /* Provides uptime and idle time. */
#define FILENAME "/proc/uptime"
void void
glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf) glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
{ {
FILE *f; FILE *f;
glibtop_init_s (&server, 0, 0); glibtop_init_s (&server, GLIBTOP_SYSDEPS_UPTIME, 0);
memset (buf, 0, sizeof (glibtop_uptime)); memset (buf, 0, sizeof (glibtop_uptime));