summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Baulig <martin@home-of-linux.org>1998-07-14 23:30:36 +0000
committerMartin Baulig <martin@src.gnome.org>1998-07-14 23:30:36 +0000
commit5f4131f248253a7cd10b0bbcf4d49c79f4fd38a5 (patch)
tree600f5f3ec71f20669fb38d42e30b04bf5169d7ac
parent4bfef8c2544392ab9471d36b2f4bb23fc0660b83 (diff)
downloadlibgtop-5f4131f248253a7cd10b0bbcf4d49c79f4fd38a5.tar.gz
New file. Imported from top 3.4.
1998-07-15 Martin Baulig <martin@home-of-linux.org> * sysdeps/sun4/loadavg.h: New file. Imported from top 3.4. * sysdeps/sun4/uptime.c (glibtop_get_uptime_p): Added implementation of that function using glibtop_get_cpu (). * sysdeps/sun4/loadavg.c (glibtop_get_loadavg_p): Added implementation of that feature. * sysdeps/sun4/{shm_limits.c, msg_limits.c, shm_limits.c}: Added implementation of this features.
-rw-r--r--ChangeLog13
-rw-r--r--sysdeps/sun4/cpu.c2
-rw-r--r--sysdeps/sun4/glibtop_machine.h9
-rw-r--r--sysdeps/sun4/loadavg.c63
-rw-r--r--sysdeps/sun4/mem.c2
-rw-r--r--sysdeps/sun4/msg_limits.c39
-rw-r--r--sysdeps/sun4/open.c6
-rw-r--r--sysdeps/sun4/sem_limits.c45
-rw-r--r--sysdeps/sun4/shm_limits.c38
-rw-r--r--sysdeps/sun4/swap.c2
-rw-r--r--sysdeps/sun4/uptime.c28
11 files changed, 240 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index a679b801..6108cd01 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+1998-07-15 Martin Baulig <martin@home-of-linux.org>
+
+ * sysdeps/sun4/loadavg.h: New file. Imported from top 3.4.
+
+ * sysdeps/sun4/uptime.c (glibtop_get_uptime_p): Added
+ implementation of that function using glibtop_get_cpu ().
+
+ * sysdeps/sun4/loadavg.c (glibtop_get_loadavg_p): Added
+ implementation of that feature.
+
+ * sysdeps/sun4/{shm_limits.c, msg_limits.c, shm_limits.c}:
+ Added implementation of this features.
+
1998-07-14 Martin Baulig <baulig@Stud.Informatik.uni-trier.de>
* src/daemon/server_config.h.in: Added some comments.
diff --git a/sysdeps/sun4/cpu.c b/sysdeps/sun4/cpu.c
index 68cf0003..7fd278c5 100644
--- a/sysdeps/sun4/cpu.c
+++ b/sysdeps/sun4/cpu.c
@@ -19,7 +19,7 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
#include <glibtop/cpu.h>
static const unsigned long _glibtop_sysdeps_cpu =
diff --git a/sysdeps/sun4/glibtop_machine.h b/sysdeps/sun4/glibtop_machine.h
index 8fb3d133..55ec3cd6 100644
--- a/sysdeps/sun4/glibtop_machine.h
+++ b/sysdeps/sun4/glibtop_machine.h
@@ -44,6 +44,8 @@
#include <sys/syscall.h>
#endif
+#include "loadavg.h"
+
__BEGIN_DECLS
/* Older versions of SunOS don't have a typedef for pid_t.
@@ -63,10 +65,13 @@ typedef int pid_t;
#define X_CP_TIME 6
#define X_PAGES 7
#define X_EPAGES 8
+#define X_SHMINFO 9
+#define X_MSGINFO 10
+#define X_SEMINFO 11
#ifdef MULTIPROCESSOR
-#define X_NCPU 9
-#define X_MP_TIME 10
+#define X_NCPU 12
+#define X_MP_TIME 13
#endif
/* Log base 2 of 1024 is 10 (2^10 == 1024) */
diff --git a/sysdeps/sun4/loadavg.c b/sysdeps/sun4/loadavg.c
new file mode 100644
index 00000000..df1a0dc6
--- /dev/null
+++ b/sysdeps/sun4/loadavg.c
@@ -0,0 +1,63 @@
+/* $Id$ */
+
+/* Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+ This file is part of the Gnome Top Library.
+ Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
+
+ The Gnome Top Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Top Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <glibtop.h>
+#include <glibtop/loadavg.h>
+
+static const unsigned long _glibtop_sysdeps_loadavg =
+(1 << GLIBTOP_LOADAVG_LOADAVG);
+
+/* Provides load averange. */
+
+void
+glibtop_get_loadavg_p (glibtop *server, glibtop_loadavg *buf)
+{
+ load_avg avenrun [3];
+ int i;
+
+ glibtop_init_r (&server, 0, 0);
+
+ memset (buf, 0, sizeof (glibtop_loadavg));
+
+ /* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */
+
+ setregid (server->machine.gid, server->machine.egid);
+
+ /* get the load average array */
+
+ (void) _glibtop_getkval (server, _glibtop_nlist [X_AVENRUN].n_value,
+ (int *) avenrun, sizeof (avenrun),
+ _glibtop_nlist [X_AVENRUN].n_name);
+
+ if (setregid (server->machine.egid, server->machine.gid))
+ _exit (1);
+
+ /* !!! END OF SGID KMEM PART !!! */
+
+ for (i = 0; i < 3; i++) {
+ /* Calculate loadavg values from avenrun. */
+ buf->loadavg [i] = loaddouble (avenrun [i]);
+ }
+
+ /* Now we can set the flags. */
+
+ buf->flags = _glibtop_sysdeps_loadavg;
+}
diff --git a/sysdeps/sun4/mem.c b/sysdeps/sun4/mem.c
index 6f3b74c2..0eb195b5 100644
--- a/sysdeps/sun4/mem.c
+++ b/sysdeps/sun4/mem.c
@@ -19,7 +19,7 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
#include <glibtop/mem.h>
static const unsigned long _glibtop_sysdeps_mem =
diff --git a/sysdeps/sun4/msg_limits.c b/sysdeps/sun4/msg_limits.c
index 5a8fff58..504cc389 100644
--- a/sysdeps/sun4/msg_limits.c
+++ b/sysdeps/sun4/msg_limits.c
@@ -19,14 +19,53 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
+#include <glibtop.h>
#include <glibtop/msg_limits.h>
+/* #define KERNEL to get declaration of `struct msginfo'. */
+
+#define KERNEL
+
+#include <sys/ipc.h>
+#include <sys/msg.h>
+
+static const unsigned long _glibtop_sysdeps_msg_limits =
+(1 << GLIBTOP_IPC_MSGMAP) + (1 << GLIBTOP_IPC_MSGMAX) +
+(1 << GLIBTOP_IPC_MSGMNB) + (1 << GLIBTOP_IPC_MSGMNI) +
+(1 << GLIBTOP_IPC_MSGSSZ) + (1 << GLIBTOP_IPC_MSGTQL);
+
/* Provides information about sysv ipc limits. */
void
glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
{
+ struct msginfo msginfo;
+
glibtop_init_r (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_msg_limits));
+
+ /* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */
+
+ setregid (server->machine.gid, server->machine.egid);
+
+ /* get the load average array */
+
+ (void) _glibtop_getkval (server, _glibtop_nlist [X_MSGINFO].n_value,
+ (int *) &msginfo, sizeof (msginfo),
+ _glibtop_nlist [X_MSGINFO].n_name);
+
+ if (setregid (server->machine.egid, server->machine.gid))
+ _exit (1);
+
+ /* !!! END OF SGID KMEM PART !!! */
+
+ buf->msgmap = msginfo.msgmap;
+ buf->msgmax = msginfo.msgmax;
+ buf->msgmnb = msginfo.msgmnb;
+ buf->msgmni = msginfo.msgmni;
+ buf->msgssz = msginfo.msgssz;
+ buf->msgtql = msginfo.msgtql;
+
+ buf->flags = _glibtop_sysdeps_msg_limits;
}
diff --git a/sysdeps/sun4/open.c b/sysdeps/sun4/open.c
index 7f68913c..60f3c64b 100644
--- a/sysdeps/sun4/open.c
+++ b/sysdeps/sun4/open.c
@@ -34,6 +34,9 @@ struct nlist _glibtop_nlist[] = {
{ "cp_time" }, /* 6 */
{ "pages" }, /* 7 */
{ "epages" }, /* 8 */
+ { "shminfo" }, /* 9 */
+ { "msginfo" }, /* 10 */
+ { "seminfo" }, /* 11 */
#else
{ "_avenrun" }, /* 0 */
{ "_ccpu" }, /* 1 */
@@ -44,6 +47,9 @@ struct nlist _glibtop_nlist[] = {
{ "_cp_time" }, /* 6 */
{ "_pages" }, /* 7 */
{ "_epages" }, /* 8 */
+ { "_shminfo" }, /* 9 */
+ { "_msginfo" }, /* 10 */
+ { "_seminfo" }, /* 11 */
#ifdef MULTIPROCESSOR
{ "_ncpu" },
{ "_mp_time" },
diff --git a/sysdeps/sun4/sem_limits.c b/sysdeps/sun4/sem_limits.c
index 1e7eaa0f..ef8aa1e8 100644
--- a/sysdeps/sun4/sem_limits.c
+++ b/sysdeps/sun4/sem_limits.c
@@ -19,14 +19,59 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
+#include <glibtop.h>
#include <glibtop/sem_limits.h>
+/* #define KERNEL to get declaration of `struct seminfo'. */
+
+#define KERNEL
+
+#include <sys/ipc.h>
+#include <sys/sem.h>
+
+static unsigned long _glibtop_sysdeps_sem_limits =
+(1 << GLIBTOP_IPC_SEMMAP) + (1 << GLIBTOP_IPC_SEMMNI) +
+(1 << GLIBTOP_IPC_SEMMNS) + (1 << GLIBTOP_IPC_SEMMNU) +
+(1 << GLIBTOP_IPC_SEMMSL) + (1 << GLIBTOP_IPC_SEMOPM) +
+(1 << GLIBTOP_IPC_SEMUME) + (1 << GLIBTOP_IPC_SEMUSZ) +
+(1 << GLIBTOP_IPC_SEMVMX) + (1 << GLIBTOP_IPC_SEMAEM);
+
/* Provides information about sysv sem limits. */
void
glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
{
+ struct seminfo seminfo;
+
glibtop_init_r (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_sem_limits));
+
+ /* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */
+
+ setregid (server->machine.gid, server->machine.egid);
+
+ /* get the load average array */
+
+ (void) _glibtop_getkval (server, _glibtop_nlist [X_SEMINFO].n_value,
+ (int *) &seminfo, sizeof (seminfo),
+ _glibtop_nlist [X_SEMINFO].n_name);
+
+ if (setregid (server->machine.egid, server->machine.gid))
+ _exit (1);
+
+ /* !!! END OF SGID KMEM PART !!! */
+
+ buf->semmap = seminfo.semmap;
+ buf->semmni = seminfo.semmni;
+ buf->semmns = seminfo.semmns;
+ buf->semmnu = seminfo.semmnu;
+ buf->semmsl = seminfo.semmsl;
+ buf->semopm = seminfo.semopm;
+ buf->semume = seminfo.semume;
+ buf->semusz = seminfo.semusz;
+ buf->semvmx = seminfo.semvmx;
+ buf->semaem = seminfo.semaem;
+
+ buf->flags = _glibtop_sysdeps_sem_limits;
}
diff --git a/sysdeps/sun4/shm_limits.c b/sysdeps/sun4/shm_limits.c
index bb7facb7..f43cef8b 100644
--- a/sysdeps/sun4/shm_limits.c
+++ b/sysdeps/sun4/shm_limits.c
@@ -19,14 +19,52 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
+#include <glibtop.h>
#include <glibtop/shm_limits.h>
+/* #define KERNEL to get declaration of `struct shminfo'. */
+
+#define KERNEL
+
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+static unsigned long _glibtop_sysdeps_shm_limits =
+(1 << GLIBTOP_IPC_SHMMAX) + (1 << GLIBTOP_IPC_SHMMIN) +
+(1 << GLIBTOP_IPC_SHMMNI) + (1 << GLIBTOP_IPC_SHMSEG) +
+(1 << GLIBTOP_IPC_SHMALL);
+
/* Provides information about sysv ipc limits. */
void
glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
{
+ struct shminfo shminfo;
+
glibtop_init_r (&server, 0, 0);
memset (buf, 0, sizeof (glibtop_shm_limits));
+
+ /* !!! THE FOLLOWING CODE RUNS SGID KMEM - CHANGE WITH CAUTION !!! */
+
+ setregid (server->machine.gid, server->machine.egid);
+
+ /* get the load average array */
+
+ (void) _glibtop_getkval (server, _glibtop_nlist [X_SHMINFO].n_value,
+ (int *) &shminfo, sizeof (shminfo),
+ _glibtop_nlist [X_SHMINFO].n_name);
+
+ if (setregid (server->machine.egid, server->machine.gid))
+ _exit (1);
+
+ /* !!! END OF SGID KMEM PART !!! */
+
+ buf->shmmax = shminfo.shmmax;
+ buf->shmmin = shminfo.shmmin;
+ buf->shmmni = shminfo.shmmni;
+ buf->shmseg = shminfo.shmseg;
+ buf->shmall = shminfo.shmall;
+
+ buf->flags = _glibtop_sysdeps_shm_limits;
}
diff --git a/sysdeps/sun4/swap.c b/sysdeps/sun4/swap.c
index d6a402fc..853e9477 100644
--- a/sysdeps/sun4/swap.c
+++ b/sysdeps/sun4/swap.c
@@ -19,7 +19,7 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
#include <glibtop/swap.h>
/* Provides information about swap usage. */
diff --git a/sysdeps/sun4/uptime.c b/sysdeps/sun4/uptime.c
index e1a6cc51..db0d4a52 100644
--- a/sysdeps/sun4/uptime.c
+++ b/sysdeps/sun4/uptime.c
@@ -19,15 +19,39 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <config.h>
+#include <glibtop.h>
+#include <glibtop/cpu.h>
#include <glibtop/uptime.h>
+static const unsigned long _glibtop_sysdeps_uptime =
+(1 << GLIBTOP_UPTIME_UPTIME) + (1 << GLIBTOP_UPTIME_IDLETIME);
+
/* Provides uptime and idle time. */
void
glibtop_get_uptime_p (glibtop *server, glibtop_uptime *buf)
{
+ glibtop_cpu cpu;
+
glibtop_init_r (&server, 0, 0);
- memset (buf, 0, sizeof (glibtop_uptime));
+ /* Get currect cpu usage. */
+
+ glibtop_get_cpu_p (server, &cpu);
+
+ /* Make sure all required fields are present. */
+
+ if (((cpu.flags & GLIBTOP_CPU_TOTAL) == 0) ||
+ ((cpu.flags & GLIBTOP_CPU_IDLE) == 0) ||
+ ((cpu.flags & GLIBTOP_CPU_FREQUENCY) == 0) ||
+ (cpu.frequency == 0))
+ return;
+
+ /* Simply calculate uptime and idle time from
+ * cpu usage. */
+
+ buf->uptime = (double) cpu.total / (double) cpu.frequency;
+ buf->idletime = (double) cpu.idle / (double) cpu.frequency;
+
+ buf->flags = _glibtop_sysdeps_uptime;
}