summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog25
-rw-r--r--glibtop.h5
-rw-r--r--include/glibtop/command.h1
-rw-r--r--include/glibtop/cpu.h2
-rw-r--r--include/glibtop/loadavg.h2
-rw-r--r--include/glibtop/mem.h2
-rw-r--r--include/glibtop/msg_limits.h2
-rw-r--r--include/glibtop/open.h7
-rw-r--r--include/glibtop/parameter.h11
-rw-r--r--include/glibtop/prockernel.h2
-rw-r--r--include/glibtop/proclist.h2
-rw-r--r--include/glibtop/procmem.h2
-rw-r--r--include/glibtop/procsegment.h2
-rw-r--r--include/glibtop/procsignal.h2
-rw-r--r--include/glibtop/procstate.h2
-rw-r--r--include/glibtop/proctime.h2
-rw-r--r--include/glibtop/procuid.h2
-rw-r--r--include/glibtop/sem_limits.h2
-rw-r--r--include/glibtop/shm_limits.h2
-rw-r--r--include/glibtop/swap.h2
-rw-r--r--include/glibtop/sysdeps.h4
-rw-r--r--include/glibtop/uptime.h2
-rw-r--r--lib/init.c40
-rw-r--r--lib/lib.awk60
-rw-r--r--lib/open.c2
-rw-r--r--lib/parameter.c7
-rw-r--r--lib/sysdeps.c106
-rw-r--r--sysdeps/guile/guile.awk1
-rw-r--r--sysdeps/guile/names/guile-names.awk1
-rw-r--r--sysdeps/kernel/cpu.c8
-rw-r--r--sysdeps/kernel/loadavg.c8
-rw-r--r--sysdeps/kernel/mem.c8
-rw-r--r--sysdeps/kernel/msg_limits.c8
-rw-r--r--sysdeps/kernel/prockernel.c14
-rw-r--r--sysdeps/kernel/proclist.c8
-rw-r--r--sysdeps/kernel/procmem.c14
-rw-r--r--sysdeps/kernel/procsegment.c14
-rw-r--r--sysdeps/kernel/procsignal.c14
-rw-r--r--sysdeps/kernel/procstate.c14
-rw-r--r--sysdeps/kernel/proctime.c14
-rw-r--r--sysdeps/kernel/procuid.c14
-rw-r--r--sysdeps/kernel/sem_limits.c23
-rw-r--r--sysdeps/kernel/shm_limits.c8
-rw-r--r--sysdeps/kernel/swap.c8
-rw-r--r--sysdeps/kernel/uptime.c8
-rw-r--r--sysdeps/linux/cpu.c10
-rw-r--r--sysdeps/linux/loadavg.c12
-rw-r--r--sysdeps/linux/mem.c12
-rw-r--r--sysdeps/linux/msg_limits.c10
-rw-r--r--sysdeps/linux/prockernel.c16
-rw-r--r--sysdeps/linux/proclist.c32
-rw-r--r--sysdeps/linux/procmem.c16
-rw-r--r--sysdeps/linux/procsegment.c16
-rw-r--r--sysdeps/linux/procsignal.c16
-rw-r--r--sysdeps/linux/procstate.c16
-rw-r--r--sysdeps/linux/proctime.c16
-rw-r--r--sysdeps/linux/procuid.c16
-rw-r--r--sysdeps/linux/sem_limits.c15
-rw-r--r--sysdeps/linux/shm_limits.c10
-rw-r--r--sysdeps/linux/swap.c12
-rw-r--r--sysdeps/linux/uptime.c12
61 files changed, 535 insertions, 189 deletions
diff --git a/ChangeLog b/ChangeLog
index ee790463..7d386c9d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
* configure.in (HAVE_SOCKETS, HAVE_SOCKADDR_SUN_LEN): New checks.
diff --git a/glibtop.h b/glibtop.h
index 810d9419..6d82f299 100644
--- a/glibtop.h
+++ b/glibtop.h
@@ -33,10 +33,13 @@
typedef struct _glibtop glibtop;
+#include <glibtop/sysdeps.h>
+
struct _glibtop
{
unsigned flags;
unsigned method; /* Server Method */
+ unsigned error_method; /* Error Method */
#ifdef HAVE_GLIBTOP_MACHINE_H
glibtop_machine machine; /* Machine dependent data */
#endif
@@ -51,6 +54,8 @@ struct _glibtop
const char *server_rsh; /* Command used to connect to the target host */
unsigned long features; /* Server is required for this features */
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 */
};
diff --git a/include/glibtop/command.h b/include/glibtop/command.h
index d70a08bb..afbb0237 100644
--- a/include/glibtop/command.h
+++ b/include/glibtop/command.h
@@ -24,6 +24,7 @@
#include <glibtop.h>
#include <glibtop/sysdeps.h>
+#include <glibtop/union.h>
__BEGIN_DECLS
diff --git a/include/glibtop/cpu.h b/include/glibtop/cpu.h
index daec3187..7c1fcbbd 100644
--- a/include/glibtop/cpu.h
+++ b/include/glibtop/cpu.h
@@ -60,8 +60,10 @@ struct _glibtop_cpu
extern void glibtop_get_cpu_l __P((glibtop *, glibtop_cpu *));
#if GLIBTOP_SUID_CPU
+extern void glibtop_init_cpu_p __P((glibtop *));
extern void glibtop_get_cpu_p __P((glibtop *, glibtop_cpu *));
#else
+extern void glibtop_init_cpu_s __P((glibtop *));
extern void glibtop_get_cpu_s __P((glibtop *, glibtop_cpu *));
#endif
diff --git a/include/glibtop/loadavg.h b/include/glibtop/loadavg.h
index dedf0f16..f799fe40 100644
--- a/include/glibtop/loadavg.h
+++ b/include/glibtop/loadavg.h
@@ -50,8 +50,10 @@ struct _glibtop_loadavg
extern void glibtop_get_loadavg_l __P((glibtop *, glibtop_loadavg *));
#if GLIBTOP_SUID_LOADAVG
+extern void glibtop_init_loadavg_p __P((glibtop *));
extern void glibtop_get_loadavg_p __P((glibtop *, glibtop_loadavg *));
#else
+extern void glibtop_init_loadavg_s __P((glibtop *));
extern void glibtop_get_loadavg_s __P((glibtop *, glibtop_loadavg *));
#endif
diff --git a/include/glibtop/mem.h b/include/glibtop/mem.h
index 366c4f7c..74c936d8 100644
--- a/include/glibtop/mem.h
+++ b/include/glibtop/mem.h
@@ -64,8 +64,10 @@ struct _glibtop_mem
extern void glibtop_get_mem_l __P((glibtop *, glibtop_mem *));
#if GLIBTOP_SUID_MEM
+extern void glibtop_init_mem_p __P((glibtop *));
extern void glibtop_get_mem_p __P((glibtop *, glibtop_mem *));
#else
+extern void glibtop_init_mem_s __P((glibtop *));
extern void glibtop_get_mem_s __P((glibtop *, glibtop_mem *));
#endif
diff --git a/include/glibtop/msg_limits.h b/include/glibtop/msg_limits.h
index fb0f2561..5941b533 100644
--- a/include/glibtop/msg_limits.h
+++ b/include/glibtop/msg_limits.h
@@ -62,8 +62,10 @@ struct _glibtop_msg_limits
extern void glibtop_get_msg_limits_l __P((glibtop *, glibtop_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 *));
#else
+extern void glibtop_init_msg_limits_s __P((glibtop *));
extern void glibtop_get_msg_limits_s __P((glibtop *, glibtop_msg_limits *));
#endif
diff --git a/include/glibtop/open.h b/include/glibtop/open.h
index ff7b6125..013aa826 100644
--- a/include/glibtop/open.h
+++ b/include/glibtop/open.h
@@ -41,6 +41,13 @@ __BEGIN_DECLS
#define GLIBTOP_METHOD_INET 3
#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_p __P((glibtop *, const char *, const unsigned long, const unsigned));
diff --git a/include/glibtop/parameter.h b/include/glibtop/parameter.h
index 7614d3e5..013deaf9 100644
--- a/include/glibtop/parameter.h
+++ b/include/glibtop/parameter.h
@@ -25,11 +25,12 @@
__BEGIN_DECLS
-#define GLIBTOP_PARAM_METHOD 1
-#define GLIBTOP_PARAM_FEATURES 2
-#define GLIBTOP_PARAM_COMMAND 3
-#define GLIBTOP_PARAM_HOST 4
-#define GLIBTOP_PARAM_PORT 5
+#define GLIBTOP_PARAM_METHOD 1
+#define GLIBTOP_PARAM_FEATURES 2
+#define GLIBTOP_PARAM_COMMAND 3
+#define GLIBTOP_PARAM_HOST 4
+#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_set_parameter(p1,p2,p3) glibtop_set_parameter_l(glibtop_global_server,p1,p2,p3)
diff --git a/include/glibtop/prockernel.h b/include/glibtop/prockernel.h
index 15b68990..c589b2f0 100644
--- a/include/glibtop/prockernel.h
+++ b/include/glibtop/prockernel.h
@@ -71,8 +71,10 @@ struct _glibtop_proc_kernel
extern void glibtop_get_proc_kernel_l __P((glibtop *, glibtop_proc_kernel *, pid_t));
#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));
#else
+extern void glibtop_init_proc_kernel_s __P((glibtop *));
extern void glibtop_get_proc_kernel_s __P((glibtop *, glibtop_proc_kernel *, pid_t));
#endif
diff --git a/include/glibtop/proclist.h b/include/glibtop/proclist.h
index 1d8d3c70..38132eb6 100644
--- a/include/glibtop/proclist.h
+++ b/include/glibtop/proclist.h
@@ -54,8 +54,10 @@ struct _glibtop_proclist
extern unsigned *glibtop_get_proclist_l __P((glibtop *, glibtop_proclist *));
#if GLIBTOP_SUID_PROCLIST
+extern void glibtop_init_proclist_p __P((glibtop *));
extern unsigned *glibtop_get_proclist_p __P((glibtop *, glibtop_proclist *));
#else
+extern void glibtop_init_proclist_s __P((glibtop *));
extern unsigned *glibtop_get_proclist_s __P((glibtop *, glibtop_proclist *));
#endif
diff --git a/include/glibtop/procmem.h b/include/glibtop/procmem.h
index 1cd9e9e4..b2ef2482 100644
--- a/include/glibtop/procmem.h
+++ b/include/glibtop/procmem.h
@@ -64,8 +64,10 @@ struct _glibtop_proc_mem
extern void glibtop_get_proc_mem_l __P((glibtop *, glibtop_proc_mem *, pid_t));
#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));
#else
+extern void glibtop_init_proc_mem_s __P((glibtop *));
extern void glibtop_get_proc_mem_s __P((glibtop *, glibtop_proc_mem *, pid_t));
#endif
diff --git a/include/glibtop/procsegment.h b/include/glibtop/procsegment.h
index b123c4e2..b140f63f 100644
--- a/include/glibtop/procsegment.h
+++ b/include/glibtop/procsegment.h
@@ -65,8 +65,10 @@ struct _glibtop_proc_segment
extern void glibtop_get_proc_segment_l __P((glibtop *, glibtop_proc_segment *, pid_t));
#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));
#else
+extern void glibtop_init_proc_segment_s __P((glibtop *));
extern void glibtop_get_proc_segment_s __P((glibtop *, glibtop_proc_segment *, pid_t));
#endif
diff --git a/include/glibtop/procsignal.h b/include/glibtop/procsignal.h
index 8e919d89..0f8f62f5 100644
--- a/include/glibtop/procsignal.h
+++ b/include/glibtop/procsignal.h
@@ -58,8 +58,10 @@ struct _glibtop_proc_signal
extern void glibtop_get_proc_signal_l __P((glibtop *, glibtop_proc_signal *, pid_t));
#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));
#else
+extern void glibtop_init_proc_signal_s __P((glibtop *));
extern void glibtop_get_proc_signal_s __P((glibtop *, glibtop_proc_signal *, pid_t));
#endif
diff --git a/include/glibtop/procstate.h b/include/glibtop/procstate.h
index 933b70c0..e5d2ae1a 100644
--- a/include/glibtop/procstate.h
+++ b/include/glibtop/procstate.h
@@ -65,8 +65,10 @@ struct _glibtop_proc_state
extern void glibtop_get_proc_state_l __P((glibtop *, glibtop_proc_state *, pid_t));
#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));
#else
+extern void glibtop_init_proc_state_s __P((glibtop *));
extern void glibtop_get_proc_state_s __P((glibtop *, glibtop_proc_state *, pid_t));
#endif
diff --git a/include/glibtop/proctime.h b/include/glibtop/proctime.h
index 1a5fc7ab..c9dc3776 100644
--- a/include/glibtop/proctime.h
+++ b/include/glibtop/proctime.h
@@ -70,8 +70,10 @@ struct _glibtop_proc_time
extern void glibtop_get_proc_time_l __P((glibtop *, glibtop_proc_time *, pid_t));
#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));
#else
+extern void glibtop_init_proc_time_s __P((glibtop *));
extern void glibtop_get_proc_time_s __P((glibtop *, glibtop_proc_time *, pid_t));
#endif
diff --git a/include/glibtop/procuid.h b/include/glibtop/procuid.h
index 15643923..e4315174 100644
--- a/include/glibtop/procuid.h
+++ b/include/glibtop/procuid.h
@@ -74,8 +74,10 @@ struct _glibtop_proc_uid
extern void glibtop_get_proc_uid_l __P((glibtop *, glibtop_proc_uid *, pid_t));
#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));
#else
+extern void glibtop_init_proc_uid_s __P((glibtop *));
extern void glibtop_get_proc_uid_s __P((glibtop *, glibtop_proc_uid *, pid_t));
#endif
diff --git a/include/glibtop/sem_limits.h b/include/glibtop/sem_limits.h
index d4d69d40..4e868f09 100644
--- a/include/glibtop/sem_limits.h
+++ b/include/glibtop/sem_limits.h
@@ -68,8 +68,10 @@ struct _glibtop_sem_limits
extern void glibtop_get_sem_limits_l __P((glibtop *, glibtop_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 *));
#else
+extern void glibtop_init_sem_limits_s __P((glibtop *));
extern void glibtop_get_sem_limits_s __P((glibtop *, glibtop_sem_limits *));
#endif
diff --git a/include/glibtop/shm_limits.h b/include/glibtop/shm_limits.h
index 03858852..da74d894 100644
--- a/include/glibtop/shm_limits.h
+++ b/include/glibtop/shm_limits.h
@@ -58,8 +58,10 @@ struct _glibtop_shm_limits
extern void glibtop_get_shm_limits_l __P((glibtop *, glibtop_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 *));
#else
+extern void glibtop_init_shm_limits_s __P((glibtop *));
extern void glibtop_get_shm_limits_s __P((glibtop *, glibtop_shm_limits *));
#endif
diff --git a/include/glibtop/swap.h b/include/glibtop/swap.h
index ce620bf6..a6e67d43 100644
--- a/include/glibtop/swap.h
+++ b/include/glibtop/swap.h
@@ -58,8 +58,10 @@ struct _glibtop_swap
extern void glibtop_get_swap_l __P((glibtop *, glibtop_swap *));
#if GLIBTOP_SUID_SWAP
+extern void glibtop_init_swap_p __P((glibtop *));
extern void glibtop_get_swap_p __P((glibtop *, glibtop_swap *));
#else
+extern void glibtop_init_swap_s __P((glibtop *));
extern void glibtop_get_swap_s __P((glibtop *, glibtop_swap *));
#endif
diff --git a/include/glibtop/sysdeps.h b/include/glibtop/sysdeps.h
index dce97d7c..e3b9551b 100644
--- a/include/glibtop/sysdeps.h
+++ b/include/glibtop/sysdeps.h
@@ -23,7 +23,6 @@
#define __GLIBTOP_SYSDEPS_H__
#include <glibtop.h>
-#include <glibtop/union.h>
__BEGIN_DECLS
@@ -51,6 +50,9 @@ __BEGIN_DECLS
#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;
struct _glibtop_sysdeps
diff --git a/include/glibtop/uptime.h b/include/glibtop/uptime.h
index 63e828ce..0d2acd78 100644
--- a/include/glibtop/uptime.h
+++ b/include/glibtop/uptime.h
@@ -52,8 +52,10 @@ struct _glibtop_uptime
extern void glibtop_get_uptime_l __P((glibtop *, glibtop_uptime *));
#if GLIBTOP_SUID_UPTIME
+extern void glibtop_init_uptime_p __P((glibtop *));
extern void glibtop_get_uptime_p __P((glibtop *, glibtop_uptime *));
#else
+extern void glibtop_init_uptime_s __P((glibtop *));
extern void glibtop_get_uptime_s __P((glibtop *, glibtop_uptime *));
#endif
diff --git a/lib/init.c b/lib/init.c
index 6776ecd7..72210cd4 100644
--- a/lib/init.c
+++ b/lib/init.c
@@ -21,6 +21,7 @@
#include <glibtop.h>
#include <glibtop/xmalloc.h>
+#include <glibtop/sysdeps.h>
#include <glibtop/parameter.h>
#ifndef DEFAULT_PORT
@@ -30,7 +31,6 @@
static glibtop _glibtop_global_server;
glibtop *glibtop_global_server = &_glibtop_global_server;
-
void
_init_server (glibtop *server, const unsigned features)
{
@@ -109,7 +109,7 @@ _init_server (glibtop *server, const unsigned features)
/* Override default. */
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, temp+1);
@@ -193,19 +193,35 @@ glibtop_init_r (glibtop **server_ptr, const unsigned long features,
}
glibtop *
-glibtop_init_s (glibtop **server, const unsigned long features,
+glibtop_init_s (glibtop **server_ptr, const unsigned long features,
const unsigned flags)
{
- if (*server != NULL)
- return *server;
+ glibtop *server;
+ glibtop_init_func_t *init_fkt;
+
+ if (server_ptr == NULL)
+ return NULL;
+
+ if (*server_ptr == NULL)
+ *server_ptr = glibtop_global_server;
+
+ server = *server_ptr;
- fprintf (stderr, "DEBUG: %s (%d)\n", __FILE__, __LINE__);
+ /* Should we do the initialization? */
- if (glibtop_global_server == NULL) {
- glibtop_global_server = &_glibtop_global_server;
- glibtop_open_s (glibtop_global_server, "glibtop",
- features, flags);
+ 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;
}
diff --git a/lib/lib.awk b/lib/lib.awk
index d2972a33..5f5ed18d 100644
--- a/lib/lib.awk
+++ b/lib/lib.awk
@@ -5,10 +5,41 @@ BEGIN {
print "#include <glibtop.h>";
print "#include <glibtop/open.h>";
+ print "";
print "#include <glibtop/sysdeps.h>";
+ print "#include <glibtop/union.h>";
+ print "";
print "#include <glibtop/command.h>";
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) {
@@ -37,8 +68,8 @@ function output(line) {
print retval;
if (retval !~ /^void$/) {
- prefix = "return ";
- prefix_space = " ";
+ prefix = "retval = ";
+ prefix_space = " ";
} else {
prefix = "";
prefix_space = "";
@@ -52,8 +83,15 @@ function output(line) {
}
print "{";
+ if (retval !~ /^void$/)
+ print "\t"retval" retval;\n";
print "\tglibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_"toupper(feature)"), 0);";
+
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 "\t (server->features & (1 << GLIBTOP_SYSDEPS_"toupper(feature)")))";
print "\t{";
@@ -77,9 +115,9 @@ function output(line) {
print "#if (!GLIBTOP_SUID_"toupper(feature)")";
if (param == "")
- print "\t\t"prefix"glibtop_get_"feature"_r (server, buf);";
+ print "\t\t"prefix"glibtop_get_"feature"_s (server, buf);";
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 !~ /^@/) {
print "#else";
@@ -89,6 +127,20 @@ function output(line) {
}
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 "";
}
diff --git a/lib/open.c b/lib/open.c
index 168b6a74..9d2d5f81 100644
--- a/lib/open.c
+++ b/lib/open.c
@@ -57,6 +57,8 @@ glibtop_open_l (glibtop *server, const char *program_name,
server->features = features;
+ server->error_method = GLIBTOP_ERROR_METHOD_DEFAULT;
+
#ifdef DEBUG
fprintf (stderr, "SIZEOF: %u - %u - %u - %u - %u - %u\n",
sizeof (glibtop_command), sizeof (glibtop_response),
diff --git a/lib/parameter.c b/lib/parameter.c
index 8d6403e3..9b96e415 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -58,6 +58,9 @@ glibtop_get_parameter_l (glibtop *server, const unsigned parameter,
case GLIBTOP_PARAM_PORT:
_write_data (&server->server_port,
sizeof (server->server_port));
+ case GLIBTOP_PARAM_ERROR_METHOD:
+ _write_data (&server->error_method,
+ sizeof (server->error_method));
}
return 0;
@@ -76,5 +79,9 @@ glibtop_set_parameter_l (glibtop *server, const unsigned parameter,
_check_data (sizeof (server->features));
memcpy (&server->features, data_ptr, data_size);
break;
+ case GLIBTOP_PARAM_ERROR_METHOD:
+ _check_data (sizeof (server->error_method));
+ memcpy (&server->error_method, data_ptr, data_size);
+ break;
}
}
diff --git a/lib/sysdeps.c b/lib/sysdeps.c
index dce28c11..17227665 100644
--- a/lib/sysdeps.c
+++ b/lib/sysdeps.c
@@ -39,62 +39,62 @@ GLIBTOP_SUID_PROC_SIGNAL +
GLIBTOP_SUID_PROC_KERNEL +
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. */
void
glibtop_get_sysdeps_r (glibtop *server, glibtop_sysdeps *buf)
{
- glibtop_union data;
-
- 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;
+ memcpy (buf, &server->sysdeps, sizeof (glibtop_sysdeps));
}
diff --git a/sysdeps/guile/guile.awk b/sysdeps/guile/guile.awk
index 5d9c1118..710c698f 100644
--- a/sysdeps/guile/guile.awk
+++ b/sysdeps/guile/guile.awk
@@ -6,6 +6,7 @@ BEGIN {
print "#include <glibtop.h>";
print "#include <glibtop/xmalloc.h>";
print "#include <glibtop/sysdeps.h>";
+ print "#include <glibtop/union.h>";
print "";
print "#include <guile/gh.h>";
diff --git a/sysdeps/guile/names/guile-names.awk b/sysdeps/guile/names/guile-names.awk
index 3c062aaa..3572c001 100644
--- a/sysdeps/guile/names/guile-names.awk
+++ b/sysdeps/guile/names/guile-names.awk
@@ -5,6 +5,7 @@ BEGIN {
print "#include <glibtop.h>";
print "#include <glibtop/sysdeps.h>";
+ print "#include <glibtop/union.h>";
print "";
print "#include <guile/gh.h>";
diff --git a/sysdeps/kernel/cpu.c b/sysdeps/kernel/cpu.c
index 6e348b1d..bea66d2b 100644
--- a/sysdeps/kernel/cpu.c
+++ b/sysdeps/kernel/cpu.c
@@ -30,6 +30,14 @@ static const unsigned long _glibtop_sysdeps_cpu =
(1 << GLIBTOP_CPU_NICE) + (1 << GLIBTOP_CPU_SYS) +
(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. */
void
diff --git a/sysdeps/kernel/loadavg.c b/sysdeps/kernel/loadavg.c
index fc1718f5..be740186 100644
--- a/sysdeps/kernel/loadavg.c
+++ b/sysdeps/kernel/loadavg.c
@@ -28,6 +28,14 @@
static const unsigned long _glibtop_sysdeps_loadavg =
(1 << GLIBTOP_LOADAVG_LOADAVG);
+/* Init function. */
+
+void
+glibtop_init_loadavg_s (glibtop *server)
+{
+ server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
+}
+
/* Provides load load averange. */
void
diff --git a/sysdeps/kernel/mem.c b/sysdeps/kernel/mem.c
index b0bf598e..88b152a3 100644
--- a/sysdeps/kernel/mem.c
+++ b/sysdeps/kernel/mem.c
@@ -31,6 +31,14 @@ static const unsigned long _glibtop_sysdeps_mem =
(1 << GLIBTOP_MEM_BUFFER) + (1 << GLIBTOP_MEM_CACHED) +
(1 << GLIBTOP_MEM_USER);
+/* Init function. */
+
+void
+glibtop_init_mem_s (glibtop *server)
+{
+ server->sysdeps.mem = _glibtop_sysdeps_mem;
+}
+
/* Provides information about memory usage. */
void
diff --git a/sysdeps/kernel/msg_limits.c b/sysdeps/kernel/msg_limits.c
index 08fdc8e8..561e4697 100644
--- a/sysdeps/kernel/msg_limits.c
+++ b/sysdeps/kernel/msg_limits.c
@@ -30,6 +30,14 @@ static const unsigned long _glibtop_sysdeps_msg_limits =
(1 << GLIBTOP_IPC_MSGMNI) + (1 << GLIBTOP_IPC_MSGSSZ) +
(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. */
void
diff --git a/sysdeps/kernel/prockernel.c b/sysdeps/kernel/prockernel.c
index f987b35d..b46e114f 100644
--- a/sysdeps/kernel/prockernel.c
+++ b/sysdeps/kernel/prockernel.c
@@ -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_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. */
void
@@ -43,12 +51,6 @@ glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf,
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))
glibtop_error_io_r (server, "table(TABLE_PROC_KERNEL)");
diff --git a/sysdeps/kernel/proclist.c b/sysdeps/kernel/proclist.c
index f812e915..34badeed 100644
--- a/sysdeps/kernel/proclist.c
+++ b/sysdeps/kernel/proclist.c
@@ -29,6 +29,14 @@ static const unsigned long _glibtop_sysdeps_proclist =
(1 << GLIBTOP_PROCLIST_TOTAL) + (1 << GLIBTOP_PROCLIST_NUMBER) +
(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_SIZE (BLOCK_COUNT * sizeof (unsigned))
diff --git a/sysdeps/kernel/procmem.c b/sysdeps/kernel/procmem.c
index 71a34cc5..50f0001f 100644
--- a/sysdeps/kernel/procmem.c
+++ b/sysdeps/kernel/procmem.c
@@ -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_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. */
void
@@ -42,12 +50,6 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf,
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))
glibtop_error_io_r (server, "table(TABLE_PROC_MEM)");
diff --git a/sysdeps/kernel/procsegment.c b/sysdeps/kernel/procsegment.c
index 86b06854..2682c817 100644
--- a/sysdeps/kernel/procsegment.c
+++ b/sysdeps/kernel/procsegment.c
@@ -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_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. */
void
@@ -43,12 +51,6 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
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))
glibtop_error_io_r (server, "table(TABLE_PROC_MEM)");
diff --git a/sysdeps/kernel/procsignal.c b/sysdeps/kernel/procsignal.c
index ac4012d7..eaa49628 100644
--- a/sysdeps/kernel/procsignal.c
+++ b/sysdeps/kernel/procsignal.c
@@ -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_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. */
void
@@ -41,12 +49,6 @@ glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf,
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))
glibtop_error_io_r (server, "table(TABLE_PROC_SIGNAL)");
diff --git a/sysdeps/kernel/procstate.c b/sysdeps/kernel/procstate.c
index 2fa471f4..daad3955 100644
--- a/sysdeps/kernel/procstate.c
+++ b/sysdeps/kernel/procstate.c
@@ -28,6 +28,14 @@
static const unsigned long _glibtop_sysdeps_proc_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. */
#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));
- if (pid == 0) {
- /* Client is only interested in the flags. */
- buf->flags = _glibtop_sysdeps_proc_state;
- return;
- }
-
if (table (TABLE_PROC_STATE, &tbl, &pid))
glibtop_error_io_r (server, "table(TABLE_PROC_STATE)");
diff --git a/sysdeps/kernel/proctime.c b/sysdeps/kernel/proctime.c
index 3b8d2fb8..3189e3e9 100644
--- a/sysdeps/kernel/proctime.c
+++ b/sysdeps/kernel/proctime.c
@@ -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_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. */
void
@@ -43,12 +51,6 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf,
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))
glibtop_error_io_r (server, "table(TABLE_PROC_TIME)");
diff --git a/sysdeps/kernel/procuid.c b/sysdeps/kernel/procuid.c
index 0fb298ac..fe3396a1 100644
--- a/sysdeps/kernel/procuid.c
+++ b/sysdeps/kernel/procuid.c
@@ -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_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)
/* 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));
- if (pid == 0) {
- /* Client is only interested in the flags. */
- buf->flags = _glibtop_sysdeps_proc_uid;
- return;
- }
-
if (table (TABLE_PROC_UID, &tbl, &pid))
glibtop_error_io_r (server, "table(TABLE_PROC_UID)");
diff --git a/sysdeps/kernel/sem_limits.c b/sysdeps/kernel/sem_limits.c
index 778567f5..48831940 100644
--- a/sysdeps/kernel/sem_limits.c
+++ b/sysdeps/kernel/sem_limits.c
@@ -24,6 +24,21 @@
#include <sys/ipc.h>
#include <sys/sem.h>
+#ifdef _SEM_SEMUN_UNDEFINED
+
+/* glibc 2.1 will no longer defines semun, instead it defines
+ * _SEM_SEMUN_UNDEFINED so users can define semun on their own.
+ * Thanks to Albert K T Hui <avatar@deva.net>. */
+
+union semun
+{
+ int val;
+ struct semid_ds *buf;
+ unsigned short int *array;
+ struct seminfo *__buf;
+};
+#endif
+
static unsigned long _glibtop_sysdeps_sem_limits =
(1 << GLIBTOP_IPC_SEMMAP) + (1 << GLIBTOP_IPC_SEMMNI) +
(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_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. */
void
diff --git a/sysdeps/kernel/shm_limits.c b/sysdeps/kernel/shm_limits.c
index 1f595a58..24eda143 100644
--- a/sysdeps/kernel/shm_limits.c
+++ b/sysdeps/kernel/shm_limits.c
@@ -29,6 +29,14 @@ static unsigned long _glibtop_sysdeps_shm_limits =
(1 << GLIBTOP_IPC_SHMMNI) + (1 << GLIBTOP_IPC_SHMSEG) +
(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. */
void
diff --git a/sysdeps/kernel/swap.c b/sysdeps/kernel/swap.c
index 818994dd..8e1488b9 100644
--- a/sysdeps/kernel/swap.c
+++ b/sysdeps/kernel/swap.c
@@ -30,6 +30,14 @@ static unsigned long _glibtop_sysdeps_swap =
(1 << GLIBTOP_SWAP_FREE) + (1 << GLIBTOP_SWAP_PAGEIN) +
(1 << GLIBTOP_SWAP_PAGEOUT);
+/* Init function. */
+
+void
+glibtop_init_swap_s (glibtop *server)
+{
+ server->sysdeps.swap = _glibtop_sysdeps_swap;
+}
+
/* Provides information about swap usage. */
void
diff --git a/sysdeps/kernel/uptime.c b/sysdeps/kernel/uptime.c
index 7d91c255..fdbd6177 100644
--- a/sysdeps/kernel/uptime.c
+++ b/sysdeps/kernel/uptime.c
@@ -28,6 +28,14 @@
static unsigned long _glibtop_sysdeps_uptime =
(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. */
void
diff --git a/sysdeps/linux/cpu.c b/sysdeps/linux/cpu.c
index a0e600cd..8a740e92 100644
--- a/sysdeps/linux/cpu.c
+++ b/sysdeps/linux/cpu.c
@@ -28,6 +28,14 @@ static const unsigned long _glibtop_sysdeps_cpu =
(1 << GLIBTOP_CPU_NICE) + (1 << GLIBTOP_CPU_SYS) +
(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. */
#define FILENAME "/proc/stat"
@@ -37,7 +45,7 @@ glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
{
FILE *f;
- glibtop_init_s (&server, 0, 0);
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
memset (buf, 0, sizeof (glibtop_cpu));
diff --git a/sysdeps/linux/loadavg.c b/sysdeps/linux/loadavg.c
index a4b308e9..73adf0f7 100644
--- a/sysdeps/linux/loadavg.c
+++ b/sysdeps/linux/loadavg.c
@@ -26,16 +26,24 @@
static const unsigned long _glibtop_sysdeps_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. */
+#define FILENAME "/proc/loadavg"
+
void
glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
{
FILE *f;
- glibtop_init_s (&server, 0, 0);
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_LOADAVG, 0);
memset (buf, 0, sizeof (glibtop_loadavg));
diff --git a/sysdeps/linux/mem.c b/sysdeps/linux/mem.c
index c9e46607..b2f8e27c 100644
--- a/sysdeps/linux/mem.c
+++ b/sysdeps/linux/mem.c
@@ -29,16 +29,24 @@ static const unsigned long _glibtop_sysdeps_mem =
(1 << GLIBTOP_MEM_BUFFER) + (1 << GLIBTOP_MEM_CACHED) +
(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. */
+#define FILENAME "/proc/meminfo"
+
void
glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
{
FILE *f;
- glibtop_init_s (&server, 0, 0);
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);
memset (buf, 0, sizeof (glibtop_mem));
diff --git a/sysdeps/linux/msg_limits.c b/sysdeps/linux/msg_limits.c
index 08fdc8e8..0ff822d0 100644
--- a/sysdeps/linux/msg_limits.c
+++ b/sysdeps/linux/msg_limits.c
@@ -30,6 +30,14 @@ static const unsigned long _glibtop_sysdeps_msg_limits =
(1 << GLIBTOP_IPC_MSGMNI) + (1 << GLIBTOP_IPC_MSGSSZ) +
(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. */
void
@@ -37,7 +45,7 @@ glibtop_get_msg_limits_s (glibtop *server, glibtop_msg_limits *buf)
{
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));
diff --git a/sysdeps/linux/prockernel.c b/sysdeps/linux/prockernel.c
index a68862a0..2ea12ddd 100644
--- a/sysdeps/linux/prockernel.c
+++ b/sysdeps/linux/prockernel.c
@@ -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_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. */
void
@@ -38,16 +46,10 @@ glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid)
int nread;
FILE *f;
- glibtop_init_s (&server, 0, 0);
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_KERNEL, 0);
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);
f = fopen (input, "r");
diff --git a/sysdeps/linux/proclist.c b/sysdeps/linux/proclist.c
index f1f73a8c..6ed9384f 100644
--- a/sysdeps/linux/proclist.c
+++ b/sysdeps/linux/proclist.c
@@ -32,6 +32,14 @@ static const unsigned long _glibtop_sysdeps_proclist =
(1 << GLIBTOP_PROCLIST_TOTAL) + (1 << GLIBTOP_PROCLIST_NUMBER) +
(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_SIZE (BLOCK_COUNT * sizeof (unsigned))
@@ -60,7 +68,7 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf)
struct stat statb;
int len, i, ok;
- glibtop_init_s (&server, 0, 0);
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROCLIST, 0);
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 */
- 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);
/* 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. */
if (count >= BLOCK_COUNT) {
- /* The following call to glibtop_realloc will be equivalent to
- * glibtop_malloc if pids_chain is NULL. We just calculate the
- * new size and copy pids to the beginning of the newly allocated
- * block. */
+ /* The following call to glibtop_realloc will be
+ * equivalent to glibtop_malloc () if `pids_chain' is
+ * NULL. We just calculate the new size and copy `pids'
+ * to the beginning of the newly allocated block. */
new_size = pids_size + BLOCK_SIZE;
- pids_chain = glibtop_realloc_r (server, pids_chain, new_size);
+ pids_chain = glibtop_realloc_r
+ (server, pids_chain, new_size);
memcpy (pids_chain + pids_offset, pids, BLOCK_SIZE);
@@ -121,8 +131,8 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf)
closedir (proc);
- /* count is only zero if an error occured (one a running Linux system, we
- * only have at least one single process). */
+ /* count is only zero if an error occured (one a running Linux system,
+ * we have at least one single process). */
if (!count) return NULL;
@@ -141,8 +151,8 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf)
pids_offset += BLOCK_COUNT;
- /* Since everything is ok now, we can set buf->flags, fill in the remaining fields
- and return pids_chain. */
+ /* Since everything is ok now, we can set buf->flags, fill in the
+ * remaining fields and return the `pids_chain'. */
buf->flags = _glibtop_sysdeps_proclist;
diff --git a/sysdeps/linux/procmem.c b/sysdeps/linux/procmem.c
index 98a86fce..2cd84a37 100644
--- a/sysdeps/linux/procmem.c
+++ b/sysdeps/linux/procmem.c
@@ -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_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. */
void
@@ -37,16 +45,10 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
int nread;
FILE *f;
- glibtop_init_s (&server, 0, 0);
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_MEM, 0);
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);
f = fopen (input, "r");
diff --git a/sysdeps/linux/procsegment.c b/sysdeps/linux/procsegment.c
index 00ab96ec..375a16f7 100644
--- a/sysdeps/linux/procsegment.c
+++ b/sysdeps/linux/procsegment.c
@@ -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_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. */
void
@@ -39,16 +47,10 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
int nread;
FILE *f;
- glibtop_init_s (&server, 0, 0);
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_SEGMENT, 0);
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);
f = fopen (input, "r");
diff --git a/sysdeps/linux/procsignal.c b/sysdeps/linux/procsignal.c
index b4009bdb..67763a15 100644
--- a/sysdeps/linux/procsignal.c
+++ b/sysdeps/linux/procsignal.c
@@ -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_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. */
void
@@ -36,16 +44,10 @@ glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid)
int nread;
FILE *f;
- glibtop_init_s (&server, 0, 0);
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_SIGNAL, 0);
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);
f = fopen (input, "r");
diff --git a/sysdeps/linux/procstate.c b/sysdeps/linux/procstate.c
index 47138325..006dd026 100644
--- a/sysdeps/linux/procstate.c
+++ b/sysdeps/linux/procstate.c
@@ -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_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. */
void
@@ -39,16 +47,10 @@ glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
int nread;
FILE *f;
- glibtop_init_s (&server, 0, 0);
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_STATE, 0);
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);
/* IMPORTANT NOTICE: For security reasons it is extremely important
diff --git a/sysdeps/linux/proctime.c b/sysdeps/linux/proctime.c
index b37a4aa9..86e2bd73 100644
--- a/sysdeps/linux/proctime.c
+++ b/sysdeps/linux/proctime.c
@@ -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_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. */
void
@@ -38,16 +46,10 @@ glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
int nread;
FILE *f;
- glibtop_init_s (&server, 0, 0);
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_TIME, 0);
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);
f = fopen (input, "r");
diff --git a/sysdeps/linux/procuid.c b/sysdeps/linux/procuid.c
index 901060f2..5551fbf8 100644
--- a/sysdeps/linux/procuid.c
+++ b/sysdeps/linux/procuid.c
@@ -33,6 +33,14 @@ static const unsigned long _glibtop_sysdeps_proc_uid =
#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. */
void
@@ -42,16 +50,10 @@ glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
int nread;
FILE *f;
- glibtop_init_s (&server, 0, 0);
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_UID, 0);
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);
f = fopen (input, "r");
diff --git a/sysdeps/linux/sem_limits.c b/sysdeps/linux/sem_limits.c
index f56c093c..5eb6eab2 100644
--- a/sysdeps/linux/sem_limits.c
+++ b/sysdeps/linux/sem_limits.c
@@ -25,6 +25,11 @@
#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;
@@ -41,6 +46,14 @@ static unsigned long _glibtop_sysdeps_sem_limits =
(1 << GLIBTOP_IPC_SEMUME) + (1 << GLIBTOP_IPC_SEMUSZ) +
(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. */
void
@@ -49,7 +62,7 @@ glibtop_get_sem_limits_s (glibtop *server, glibtop_sem_limits *buf)
struct seminfo seminfo;
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));
diff --git a/sysdeps/linux/shm_limits.c b/sysdeps/linux/shm_limits.c
index 1f595a58..6d40c63e 100644
--- a/sysdeps/linux/shm_limits.c
+++ b/sysdeps/linux/shm_limits.c
@@ -29,6 +29,14 @@ static unsigned long _glibtop_sysdeps_shm_limits =
(1 << GLIBTOP_IPC_SHMMNI) + (1 << GLIBTOP_IPC_SHMSEG) +
(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. */
void
@@ -36,7 +44,7 @@ glibtop_get_shm_limits_s (glibtop *server, glibtop_shm_limits *buf)
{
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));
diff --git a/sysdeps/linux/swap.c b/sysdeps/linux/swap.c
index abcfbed3..ebc310e7 100644
--- a/sysdeps/linux/swap.c
+++ b/sysdeps/linux/swap.c
@@ -30,10 +30,18 @@ static unsigned long _glibtop_sysdeps_swap =
(1 << GLIBTOP_SWAP_FREE) + (1 << GLIBTOP_SWAP_PAGEIN) +
(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. */
+#define FILENAME "/proc/meminfo"
+
void
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;
FILE *f;
- glibtop_init_s (&server, 0, 0);
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_SWAP, 0);
memset (buf, 0, sizeof (glibtop_swap));
diff --git a/sysdeps/linux/uptime.c b/sysdeps/linux/uptime.c
index 67f3d159..553e5896 100644
--- a/sysdeps/linux/uptime.c
+++ b/sysdeps/linux/uptime.c
@@ -26,16 +26,24 @@
static unsigned long _glibtop_sysdeps_uptime =
(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. */
+#define FILENAME "/proc/uptime"
+
void
glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
{
FILE *f;
- glibtop_init_s (&server, 0, 0);
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_UPTIME, 0);
memset (buf, 0, sizeof (glibtop_uptime));