system-load-plugin-0.2.0
Benedikt Meurer
Benedikt.Meurer at unix-ag.uni-siegen.de
Wed Jul 2 21:47:29 CEST 2003
On Wed, 02, Jul 2003, Benedikt Meurer wrote:
> > I'd like to announce second release of system-load-plugin.
> > I've tried to port it to many *nix flavours as possible
> > (bsd included)...
> > So please if you're not running linux, i need you to
> > test it and give some feedback...
>
> Now on the plugin:
>
> It fails with:
>
> ** (xfce4-panel:20863): WARNING **: Cannot get nlist.
>
> The problem is in cpu.c:134: nlst[0].n_type == 0 fails.
> I'll try to figure out whats wrong.
Ok, the exact problem with kvm_nlist is:
EBADF - Bad file descriptor
(Don't ask me what that means in this context)
Anyway I hacked together a simple patch for NetBSD (it should work on
OpenBSD aswell, I think, since its only a fork of NetBSD). See the
attached file.
> > Regards,
> > riccardo
HTH,
Benedikt
--
NetBSD Operating system: http://www.NetBSD.org/
pkgsrc "Work in progress": http://pkgsrc-wip.sf.net/
XFce desktop environment: http://www.xfce.org/
German Unix-AG Association: http://www.unix-ag.org/
-------------- next part --------------
--- cpu.c.old Wed Jul 2 21:42:51 2003
+++ cpu.c Wed Jul 2 21:42:04 2003
@@ -71,7 +71,13 @@
#define MAX_CPU 16
#endif
-#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+#include <sys/param.h>
+#include <sys/sched.h>
+#include <sys/sysctl.h>
+#endif
+
+#if defined(__FreeBSD__)
static kvm_t *kd;
static struct nlist nlst[] = {
{"_cp_time"}, {0}
@@ -98,7 +104,7 @@
* user
* nice
* system
- * interrupt(FreeBSD specific)
+ * interrupt(BSD specific)
* idle
*/
struct cpu_load_struct {
@@ -125,20 +131,38 @@
struct sysinfo sysinfo;
#endif
-#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+ static int mib[] = { CTL_KERN, KERN_CP_TIME };
+ u_int64_t cp_time[CPUSTATES];
+ int len = sizeof(cp_time);
+
+ if (sysctl(mib, 2, cp_time, &len, NULL, 0) < 0) {
+ g_warning("Cannot get kern.cp_time");
+ return(0);
+ }
+
+ /* compatible with Linux(overwrite 'interrupt' with 'idle' field) */
+ fresh.load[0] = cp_time[CP_USER];
+ fresh.load[1] = cp_time[CP_NICE];
+ fresh.load[2] = cp_time[CP_SYS];
+ fresh.load[3] = cp_time[CP_IDLE];
+ fresh.load[4] = cp_time[CP_IDLE];
+#endif
+
+#if defined(__FreeBSD__)
if ((kd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, "kvm_open")) == NULL) {
g_warning(_("Cannot open kvm."));
exit(1);
}
kvm_nlist(kd, nlst);
if (nlst[0].n_type == 0) {
- g_warning(_("Cannot get nlist."));
- exit(1);
+ g_warning(_("Cannot get nlist. (1)"));
+ exit(1);
}
if (kvm_read(kd, nlst[0].n_value, &fresh, sizeof(fresh)) != sizeof(fresh)) {
- g_warning(_("Cannot read nlist."));
- exit(1);
+ g_warning(_("Cannot read nlist. (2)"));
+ exit(1);
}
kvm_close(kd);
More information about the Xfce4-dev
mailing list