From 00b13f37b7f07aad96ac2ca823d0116311caab5f Mon Sep 17 00:00:00 2001 From: Dmitry Sivachenko Date: Wed, 23 Dec 2009 09:42:39 +0000 Subject: Fix for 8.0. (patch-sec01 was merged into patch-ascpu_x.c). PR: 119923 Submitted by: KOIE Hidetaka --- sysutils/ascpu/Makefile | 2 +- sysutils/ascpu/files/patch-ascpu_x.c | 109 +++++++++++++++++++++++++++++++++++ sysutils/ascpu/files/patch-sec01 | 23 -------- 3 files changed, 110 insertions(+), 24 deletions(-) create mode 100644 sysutils/ascpu/files/patch-ascpu_x.c delete mode 100644 sysutils/ascpu/files/patch-sec01 (limited to 'sysutils/ascpu') diff --git a/sysutils/ascpu/Makefile b/sysutils/ascpu/Makefile index ad0dbf9d1b42..24d00c128cf2 100644 --- a/sysutils/ascpu/Makefile +++ b/sysutils/ascpu/Makefile @@ -7,7 +7,7 @@ PORTNAME= ascpu PORTVERSION= 1.11 -PORTREVISION= 3 +PORTREVISION= 4 CATEGORIES= sysutils afterstep MASTER_SITES= http://www.tigr.net/afterstep/download/ascpu/ diff --git a/sysutils/ascpu/files/patch-ascpu_x.c b/sysutils/ascpu/files/patch-ascpu_x.c new file mode 100644 index 000000000000..11365eb02340 --- /dev/null +++ b/sysutils/ascpu/files/patch-ascpu_x.c @@ -0,0 +1,109 @@ +--- ascpu_x.c.orig 2009-12-23 12:38:21.000000000 +0300 ++++ ascpu_x.c 2009-12-23 12:38:35.000000000 +0300 +@@ -18,6 +18,12 @@ + #include + #include + #include ++#include ++#include ++#include ++#include ++#include ++#include + #endif + + #ifdef __hpux__ +@@ -81,6 +87,8 @@ time_t last_time = 0; + int update_request = 0; + + #ifdef __FreeBSD__ ++static int cp_time_mib[2]; ++static int cp_times_mib[2]; + static kvm_t *kd; + static struct nlist nlst[] = { + {"_cp_time"}, {0} +@@ -554,12 +562,45 @@ void read_stat() + memcpy(&last, &fresh, sizeof(last)); + + #ifdef __FreeBSD__ +- if (kvm_read(kd, nlst[0].n_value, &fresh, sizeof(fresh)) != sizeof(fresh)) { +- printf("ascpu : cannot read kvm\n"); +- exit(1); ++ if (state.cpu_number >= 0 && cp_times_mib[0] != 0) { ++ long cp_times[MAX_CPU][CPUSTATES]; ++ size_t cp_times_len = sizeof(cp_times); ++ int error = sysctl(cp_times_mib, 2, cp_times, &cp_times_len, NULL, 0); ++ if (error) { ++ printf("ascpu: cannot sysctl cp_times\n"); ++ exit(1); ++ } ++ ++ long *cp_time = cp_times[state.cpu_number]; ++ fresh.load[0] = cp_time[CP_USER]; ++ fresh.load[1] = cp_time[CP_NICE]; ++ fresh.load[2] = cp_time[CP_SYS] + cp_time[CP_INTR]; ++ fresh.load[3] = cp_time[CP_IDLE]; ++ } else if (state.cpu_number == -1 && cp_time_mib[0] != 0) { ++ long cp_time[CPUSTATES]; ++ size_t cp_time_len = sizeof(cp_time); ++ int error = sysctl(cp_time_mib, 2, cp_time, &cp_time_len, NULL, 0); ++ if (error) { ++ printf("ascpu: cannot sysctl cp_time\n"); ++ exit(1); ++ } ++ ++ fresh.load[0] = cp_time[CP_USER]; ++ fresh.load[1] = cp_time[CP_NICE]; ++ fresh.load[2] = cp_time[CP_SYS] + cp_time[CP_INTR]; ++ fresh.load[3] = cp_time[CP_IDLE]; ++ } else { ++ if (nlst[0].n_type == 0) { ++ printf("ascpu : cannot get nlist\n"); ++ exit(1); ++ } ++ if (kvm_read(kd, nlst[0].n_value, &fresh, sizeof(fresh)) != sizeof(fresh)) { ++ printf("ascpu : cannot read kvm\n"); ++ exit(1); ++ } ++ /* compatible with Linux(overwrite 'interrupt' with 'idle' field) */ ++ fresh.load[3] = fresh.load[4]; + } +- /* compatible with Linux(overwrite 'interrupt' with 'idle' field) */ +- fresh.load[3] = fresh.load[4]; + #endif + + #ifdef __hpux__ +@@ -677,6 +718,12 @@ void ExecuteExternal() + #ifdef DEBUG + printf("ascpu: system(%s)\n",Command); + #endif ++ ++ if (setgid(getgid()) != 0) ++ err(1, "Can't drop setgid privileges"); ++ if (setuid(getuid()) != 0) ++ err(1, "Can't drop setuid privileges"); ++ + if( ! Command ) { + return; + } +@@ -1087,14 +1134,12 @@ void ascpu_initialize( + ascpu_cleanup(); + } + #ifdef __FreeBSD__ +- if ((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) == NULL) { +- printf("ascpu : cannot open kvm\n"); +- exit(1); +- } +- kvm_nlist(kd, nlst); +- if (nlst[0].n_type == 0) { +- printf("ascpu : cannot get nlist\n"); +- exit(1); ++ size_t len = 2; ++ sysctlnametomib("kern.cp_times", cp_times_mib, &len); ++ len = 2; ++ sysctlnametomib("kern.cp_time", cp_time_mib, &len); ++ if ((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) != NULL) { ++ kvm_nlist(kd, nlst); + } + #endif + diff --git a/sysutils/ascpu/files/patch-sec01 b/sysutils/ascpu/files/patch-sec01 deleted file mode 100644 index 6f981eb660c6..000000000000 --- a/sysutils/ascpu/files/patch-sec01 +++ /dev/null @@ -1,23 +0,0 @@ ---- ascpu_x.c.orig Mon Jul 3 21:39:16 2000 -+++ ascpu_x.c Mon Jul 3 21:39:19 2000 -@@ -18,6 +18,7 @@ - #include - #include - #include -+#include - #endif - - #ifdef __hpux__ -@@ -626,6 +627,12 @@ - #ifdef DEBUG - printf("ascpu: system(%s)\n",Command); - #endif -+ -+ if (setgid(getgid()) != 0) -+ err(1, "Can't drop setgid privileges"); -+ if (setuid(getuid()) != 0) -+ err(1, "Can't drop setuid privileges"); -+ - if( ! Command ) { - return; - } -- cgit v1.2.3