From owner-freebsd-ports Fri Jun 29 14: 0:36 2001 Delivered-To: freebsd-ports@hub.freebsd.org Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 1046537B405 for ; Fri, 29 Jun 2001 14:00:09 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.3/8.11.3) id f5TL09T43610; Fri, 29 Jun 2001 14:00:09 -0700 (PDT) (envelope-from gnats) Received: from smtp1.cluster.oleane.net (smtp1.cluster.oleane.net [195.25.12.16]) by hub.freebsd.org (Postfix) with ESMTP id 5B38B37B406; Fri, 29 Jun 2001 13:50:17 -0700 (PDT) (envelope-from rguyom@pobox.com) Received: from diabolic-cow.chatgris.net (dyn-1-1-006.Orl.dialup.oleane.fr [195.25.26.6]) by smtp1.cluster.oleane.net with ESMTP id f5TKoCr67579; Fri, 29 Jun 2001 22:50:12 +0200 (CEST) Received: by diabolic-cow.chatgris.net (Postfix, from userid 1000) id 12764380; Fri, 29 Jun 2001 22:49:12 +0200 (CEST) Message-Id: <20010629204912.12764380@diabolic-cow.chatgris.net> Date: Fri, 29 Jun 2001 22:49:12 +0200 (CEST) From: rguyom@pobox.com Reply-To: rguyom@pobox.com To: FreeBSD-gnats-submit@freebsd.org, nakai@freebsd.org, Marko.Macek@gmx.net X-Send-Pr-Version: 3.113 Subject: ports/28526: x11-wm/icewm can't show the CPU status window (TaskBarShowCPUStatus=1) Sender: owner-freebsd-ports@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 28526 >Category: ports >Synopsis: x11-wm/icewm can't show the CPU status window (TaskBarShowCPUStatus=1) >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Fri Jun 29 14:00:08 PDT 2001 >Closed-Date: >Last-Modified: >Originator: Rémi Guyomarch >Release: FreeBSD 4.3-STABLE i386 >Organization: >Environment: System: FreeBSD diabolic-cow.chatgris.net 4.3-STABLE FreeBSD 4.3-STABLE #7: Sun Apr 22 21:57:27 CEST 2001 root@diabolic-cow.chatgris.net:/usr/obj/usr/src/sys/DIABOLIC-COW i386 Port: icewm-1.0.8 XFree: 3.3.6 >Description: icewm doesn't have any FreeBSD code for the option TaskBarShowCPUStatus. >How-To-Repeat: Put TaskBarShowCPUStatus=1 in your .icewm/preferences and restart icewm. >Fix: This code requires icewm to be setgid(kmem) which probably isn't very secure. YMMV. If someone can tell me how to retreive CPU activity information without reading /dev/kmem, I would be very happy to rewrite this code ! --- Makefile~ Mon May 14 11:58:19 2001 +++ Makefile Mon May 14 11:59:15 2001 @@ -70,6 +70,8 @@ @for app in $(BINFILES) ; do \ $(INSTALLBIN) "$$app" $(BINDIR); \ done + @chown root.kmem $(BINDIR)/icewm + @chmod 2555 $(BINDIR)/icewm @echo Installing defaults, icons and themes in $(LIBDIR) @$(INSTALLDIR) $(LIBDIR) @$(INSTALLDIR) $(CFGDIR) --- src/Makefile~ Fri Apr 27 03:32:22 2001 +++ src/Makefile Mon May 14 12:10:26 2001 @@ -34,7 +34,7 @@ genpref.o icewm_LIBS = \ - $(CORE_LIBS) $(IMAGE_LIBS) $(GNOME_LIBS) + $(CORE_LIBS) $(IMAGE_LIBS) $(GNOME_LIBS) -lkvm icewm_OBJS = \ ymsgbox.o ydialog.o yurl.o \ wmsession.o wmwinlist.o wmtaskbar.o wmwinmenu.o \ --- src/acpustatus.cc.orig Sun Jan 14 22:49:39 2001 +++ src/acpustatus.cc Sat Feb 10 09:31:38 2001 @@ -26,7 +26,15 @@ #include "intl.h" -#if (defined(linux) || defined(HAVE_KSTAT_H)) +#ifdef __CPUSTATUS_FreeBSD__ +#include +#include +#include +#include +#include +#endif + +#if (defined(linux) || defined(__CPUSTATUS_FreeBSD__) || defined(HAVE_KSTAT_H)) #define UPDATE_INTERVAL 500 @@ -45,12 +53,43 @@ color[IWM_NICE] = new YColor(clrCpuNice); color[IWM_SYS] = new YColor(clrCpuSys); color[IWM_IDLE] = new YColor(clrCpuIdle); +#ifdef __CPUSTATUS_FreeBSD__ + color[IWM_INTR] = new YColor(clrCpuIntr); + for (unsigned int i = 0; i < taskBarCPUSamples; i++) { + cpu[i][IWM_USER] = cpu[i][IWM_NICE] = + cpu[i][IWM_SYS] = cpu[i][IWM_INTR] = 0; + cpu[i][IWM_IDLE] = 1; + } + setSize(taskBarCPUSamples, 20); + last_cpu[IWM_USER] = last_cpu[IWM_NICE] = last_cpu[IWM_SYS] = + last_cpu[IWM_IDLE] = last_cpu[IWM_INTR] = 0; + if( setegid( 2 ) == 0 ) { + char errbuf[_POSIX2_LINE_MAX]; + kd = kvm_openfiles( NULL, NULL, NULL, O_RDONLY, errbuf ); + setegid( getgid() ); + if( kd == NULL ) + fprintf( stderr, "kvm_openfiles: %s\n", errbuf ); + else { + memset( namelist, 0, sizeof(namelist) ); + namelist[0].n_name = (char*)("_cp_time"); + if( kvm_nlist( kd, namelist ) != 0 ) { + kvm_close( kd ); + kd = NULL; + } + } + } else { + fprintf( stderr, "can't setegid(2), I'm not a setgid exec ?\n" ); + kd = NULL; + } +#else for (unsigned int i = 0; i < taskBarCPUSamples; i++) { cpu[i][IWM_USER] = cpu[i][IWM_NICE] = cpu[i][IWM_SYS] = 0; cpu[i][IWM_IDLE] = 1; } setSize(taskBarCPUSamples, 20); last_cpu[IWM_USER] = last_cpu[IWM_NICE] = last_cpu[IWM_SYS] = last_cpu[IWM_IDLE] = 0; +#endif + getStatus(); updateStatus(); updateToolTip(); @@ -65,6 +104,13 @@ delete color[IWM_NICE]; color[IWM_NICE] = 0; delete color[IWM_SYS]; color[IWM_SYS] = 0; delete color[IWM_IDLE]; color[IWM_IDLE] = 0; +#ifdef __CPUSTATUS_FreeBSD__ + delete color[IWM_INTR]; color[IWM_INTR] = 0; + if( kd != NULL ) { + kvm_close( kd ); + kd = NULL; + } +#endif } void CPUStatus::paint(Graphics &g, int /*x*/, int /*y*/, unsigned int /*width*/, unsigned int /*height*/) { @@ -75,13 +121,30 @@ int nice = cpu[i][IWM_NICE]; int sys = cpu[i][IWM_SYS]; int idle = cpu[i][IWM_IDLE]; +#ifdef __CPUSTATUS_FreeBSD__ + int intr = cpu[i][IWM_INTR]; + int total = user + sys + intr + nice + idle; +#else int total = user + sys + nice + idle; +#endif + int totald = total; int y = height() - 1; if (total > 0) { +#ifdef __CPUSTATUS_FreeBSD__ + if (intr) { + totald -= intr; + n = (h * totald) / total; // check rounding + if (n >= y) n = y; + g.setColor(color[IWM_INTR]); + g.drawLine(i, y, i, n); + y = n - 1; + } +#endif if (sys) { - n = (h * (total - sys)) / total; // check rounding + totald -= sys; + n = (h * totald) / total; // check rounding if (n >= y) n = y; g.setColor(color[IWM_SYS]); g.drawLine(i, y, i, n); @@ -89,7 +152,8 @@ } if (nice) { - n = (h * (total - sys - nice))/ total; + totald -= nice; + n = (h * totald)/ total; if (n >= y) n = y; g.setColor(color[IWM_NICE]); g.drawLine(i, y, i, n); @@ -97,7 +161,8 @@ } if (user) { - n = (h * (total - sys - nice - user))/ total; + totald -= user; + n = (h * totald)/ total; if (n >= y) n = y; g.setColor(color[IWM_USER]); g.drawLine(i, y, i, n); @@ -133,6 +198,14 @@ sprintf(load, _("CPU Load: %3.2f %3.2f %3.2f, %d processes."), l1, l5, l15, sys.procs); setToolTip(load); +#elif defined(__CPUSTATUS_FreeBSD__) + char load[31]; // enough for "CPU Load: 999.99 999.99 999.99\0" + double loadavg[3]; + if( kd != NULL && kvm_getloadavg( kd, loadavg, 3 ) != 3 ) + return; + snprintf(load, sizeof(load), "CPU Load: %3.2f %3.2f %3.2f", + loadavg[0], loadavg[1], loadavg[2]); + setToolTip(load); #endif } @@ -151,13 +224,43 @@ cpu[i - 1][IWM_NICE] = cpu[i][IWM_NICE]; cpu[i - 1][IWM_SYS] = cpu[i][IWM_SYS]; cpu[i - 1][IWM_IDLE] = cpu[i][IWM_IDLE]; +#ifdef __CPUSTATUS_FreeBSD__ + cpu[i - 1][IWM_INTR] = cpu[i][IWM_INTR]; +#endif } getStatus(), repaint(); } void CPUStatus::getStatus() { -#ifdef linux +#ifdef __CPUSTATUS_FreeBSD__ + + cpu[taskBarCPUSamples-1][IWM_USER] = 0; + cpu[taskBarCPUSamples-1][IWM_NICE] = 0; + cpu[taskBarCPUSamples-1][IWM_SYS] = 0; + cpu[taskBarCPUSamples-1][IWM_INTR] = 0; + cpu[taskBarCPUSamples-1][IWM_IDLE] = 0; + + if( kd == NULL ) return; + + long cp_time[CPUSTATES]; + int c = sizeof( cp_time ); + if (kvm_read(kd, namelist[0].n_value, &cp_time, c) != c) + return; + + long cur[IWM_STATES]; + cur[IWM_USER] = cp_time[CP_USER]; + cur[IWM_NICE] = cp_time[CP_NICE]; + cur[IWM_SYS] = cp_time[CP_SYS]; + cur[IWM_INTR] = cp_time[CP_INTR]; + cur[IWM_IDLE] = cp_time[CP_IDLE]; + + for (int i = 0; i < IWM_STATES; i++) { + cpu[taskBarCPUSamples-1][i] = cur[i] - last_cpu[i]; + last_cpu[i] = cur[i]; + } + +#elif defined(linux) char *p, buf[128]; long cur[IWM_STATES]; int len, fd = open("/proc/stat", O_RDONLY); @@ -191,8 +294,8 @@ cpu[taskBarCPUSamples-1][IWM_USER], cpu[taskBarCPUSamples-1][IWM_NICE], cpu[taskBarCPUSamples-1][IWM_SYS], cpu[taskBarCPUSamples-1][IDLE]); #endif -#endif /* linux */ -#ifdef HAVE_KSTAT_H + +#elif defined(HAVE_KSTAT_H) #ifdef HAVE_OLD_KSTAT #define ui32 ul #endif --- src/acpustatus.h Sun Dec 5 17:50:57 1999 +++ src/acpustatus.h Wed Mar 15 02:40:12 2000 @@ -1,19 +1,33 @@ #ifndef __CPUSTATUS_H #define __CPUSTATUS_H -#if (defined(linux) || defined(HAVE_KSTAT_H)) +#if defined(__FreeBSD__) && (__FreeBSD__ >= 3) + #define __CPUSTATUS_FreeBSD__ 1 +#endif + +#if (defined(linux) || defined(__CPUSTATUS_FreeBSD__) || defined(HAVE_KSTAT_H)) #ifdef HAVE_KSTAT_H #include #include #endif /* have_kstat_h */ +#ifdef __CPUSTATUS_FreeBSD__ +#include +#include +#endif #define IWM_USER (0) #define IWM_NICE (1) #define IWM_SYS (2) +#ifdef __CPUSTATUS_FreeBSD__ +#define IWM_INTR (3) +#define IWM_IDLE (4) +#define IWM_STATES (5) +#else #define IWM_IDLE (3) #define IWM_STATES (4) +#endif #include "ywindow.h" #include "ytimer.h" @@ -39,6 +53,10 @@ YColor *color[IWM_STATES]; YTimer *fUpdateTimer; const char * fCPUCommand; +#ifdef __CPUSTATUS_FreeBSD__ + struct nlist namelist[2]; + kvm_t *kd; +#endif }; #endif --- src/default.h Sun Feb 13 16:27:46 2000 +++ src/default.h Wed Mar 15 02:49:02 2000 @@ -288,6 +288,7 @@ XSV(const char *, clrLabelText , "rgb:00/00/00") XSV(const char *, clrCpuUser , "rgb:00/FF/00") XSV(const char *, clrCpuSys , "rgb:FF/00/00") +XSV(const char *, clrCpuIntr , "rgb:FF/FF/00") XSV(const char *, clrCpuNice , "rgb:00/00/FF") XSV(const char *, clrCpuIdle , "rgb:00/00/00") XSV(const char *, clrNetSend , "rgb:FF/FF/00") @@ -550,6 +551,7 @@ OSV("DesktopBackgroundImage", &DesktopBackgroundPixmap, ""), OSV("ColorCPUStatusUser", &clrCpuUser, ""), OSV("ColorCPUStatusSystem", &clrCpuSys, ""), + OSV("ColorCPUStatusInterrupts", &clrCpuIntr, ""), OSV("ColorCPUStatusNice", &clrCpuNice, ""), OSV("ColorCPUStatusIdle", &clrCpuIdle, ""), OSV("ColorNetSend", &clrNetSend, ""), --- src/wmapp.cc Sun Feb 13 16:41:54 2000 +++ src/wmapp.cc Wed Mar 15 02:56:48 2000 @@ -816,6 +816,9 @@ } int main(int argc, char **argv) { +#if defined(CONFIG_APPLET_CPU_STATUS) && defined(__CPUSTATUS_FreeBSD__) + setegid( getgid() ); +#endif #ifndef NO_CONFIGURE char *configFile = 0; #endif --- src/wmtaskbar.cc.orig Fri Feb 9 21:20:04 2001 +++ src/wmtaskbar.cc Fri Feb 9 21:26:08 2001 @@ -241,7 +241,7 @@ fAddressBar = 0; #ifdef CONFIG_APPLET_CPU_STATUS -#if (defined(linux) || defined(HAVE_KSTAT_H)) +#if (defined(linux) || defined(__CPUSTATUS_FreeBSD__) || defined(HAVE_KSTAT_H)) if (taskBarShowCPUStatus) fCPUStatus = new CPUStatus(cpuCommand, this); else @@ -342,7 +342,7 @@ } #endif #ifdef CONFIG_APPLET_CPU_STATUS -#if (defined(linux) || defined(HAVE_KSTAT_H)) +#if (defined(linux) || defined(__CPUSTATUS_FreeBSD__) || defined(HAVE_KSTAT_H)) if (fCPUStatus) { fCPUStatus->setPosition(rightX - fCPUStatus->width() - 1, BASE1 + (ht - ADD1 - fCPUStatus->height()) / 2); @@ -434,7 +434,7 @@ } #endif #ifdef CONFIG_APPLET_CPU_STATUS -#if (defined(linux) || defined(HAVE_KSTAT_H)) +#if (defined(linux) || defined(__CPUSTATUS_FreeBSD__) || defined(HAVE_KSTAT_H)) if (fCPUStatus) { fCPUStatus->setPosition(rightX - fCPUStatus->width() - 1, BASE1 + (ht - ADD1 - fCPUStatus->height()) / 2); @@ -533,6 +533,11 @@ fAutoHideTimer->setTimerListener(0); delete fAutoHideTimer; fAutoHideTimer = 0; } +#ifdef CONFIG_APPLET_CPU_STATUS +#if (defined(linux) || defined(__CPUSTATUS_FreeBSD__) || defined(HAVE_KSTAT_H)) + delete fCPUStatus; fCPUStatus = 0; +#endif +#endif #ifdef CONFIG_APPLET_CLOCK delete fClock; fClock = 0; #endif --- src/wmtaskbar.h.orig Sun Jan 14 22:49:41 2001 +++ src/wmtaskbar.h Fri Feb 9 21:31:12 2001 @@ -15,7 +15,8 @@ #define ADD2 5 class ObjectBar; -#if (defined(linux)||defined(HAVE_KSTAT_H)) +#if (defined(linux) || defined(HAVE_KSTAT_H)) || \ + (defined(__FreeBSD__) && __FreeBSD__ >= 3) class CPUStatus; #endif #ifdef HAVE_NET_STATUS @@ -79,7 +80,7 @@ MailBoxStatus *fMailBoxStatus; #endif #ifdef CONFIG_APPLET_CPU_STATUS -#if (defined(linux)||defined(HAVE_KSTAT_H)) +#if (defined(linux) || defined(HAVE_KSTAT_H)) || (defined(__FreeBSD__) && __FreeBSD__ >= 3) CPUStatus *fCPUStatus; #endif #endif >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-ports" in the body of the message