update Sun May 9 18:37:00 PDT 2010
[pkgsrc.git] / sysutils / xosview / patches / patch-aa
1 $NetBSD: patch-aa,v 1.19 2007/12/17 22:08:12 veego Exp $
2
3 --- bsd/kernel.cc.orig  2006-02-18 08:36:06.000000000 +0100
4 +++ bsd/kernel.cc       2007-12-17 21:23:26.000000000 +0100
5 @@ -115,8 +115,16 @@
6  // in __NetBSD_Version__ for us if needed.
7  #if defined(XOSVIEW_NETBSD) && defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 106010000)
8  #define NETBSD_1_6A
9 +#ifdef HW_DISKSTATS
10 +static int dmib[3] = {CTL_HW, HW_DISKSTATS, sizeof(struct disk_sysctl)};
11 +#endif
12 +#ifdef HW_IOSTATS
13 +static int dmib[3] = {CTL_HW, HW_IOSTATS, sizeof(struct io_sysctl)};
14 +#include <sys/iostat.h>
15 +#endif
16  #endif
17  
18 +#include "netmeter.h"          /*  For netIface_  */
19  #include "general.h"
20  #include "kernel.h"            /*  To grab CVSID stuff.  */
21  
22 @@ -303,9 +311,11 @@
23  
24  void
25  OpenKDIfNeeded() {
26 +  static int initialized = 0;
27    char unusederrorstring[_POSIX2_LINE_MAX];
28  
29 -  if (kd) return; //  kd is non-NULL, so it has been initialized.  BCG
30 +  if (initialized) return;
31 +  initialized = 1;
32  
33      /*  Open it read-only, for a little added safety.  */
34      /*  If the first character of kernelFileName is not '\0', then use
35 @@ -313,8 +323,10 @@
36         specifying NULL.  */
37    if ((kd = kvm_openfiles ((kernelFileName[0]) ? kernelFileName : NULL,
38                             NULL, NULL, O_RDONLY, unusederrorstring))
39 -      == NULL)
40 -         err (-1, "OpenKDIfNeeded():kvm-open()");
41 +      == NULL) {
42 +         warn ("OpenKDIfNeeded():kvm-open()");
43 +         return;
44 +  }
45    // Parenthetical note:  FreeBSD kvm_openfiles() uses getbootfile() to get
46    // the correct kernel file if the 1st arg is NULL.  As far as I can see,
47    // one should always use NULL in FreeBSD, but I suppose control is never a
48 @@ -400,6 +412,8 @@
49    static int mib[] = { CTL_KERN, KERN_CPUSTATS };
50  #endif
51  #if defined(XOSVIEW_NETBSD) && (__NetBSD_Version__ >= 104260000)
52 +  uint64_t cp_time[CPUSTATES];
53 +  size_t size = sizeof(cp_time[0]) * CPUSTATES;
54    static int mib[] = { CTL_KERN, KERN_CP_TIME };
55  #endif
56  
57 @@ -407,14 +421,11 @@
58    if (CPUSTATES != 5)
59      errx (-1, "Error:  xosview for *BSD expects 5 cpu states!\n");
60  #if defined(__NetBSD_Version__) && __NetBSD_Version__ > 104260000 /* > 1.4Z */
61 -  struct schedstate_percpu ssp;
62 -  size_t size = sizeof(ssp.spc_cp_time);
63 -  if (sysctl(mib, 2, ssp.spc_cp_time, &size, NULL, 0) < 0) {
64 -    fprintf(stderr, "can't get schedstate_percpu: %s\n", strerror(errno));
65 -    memset(&ssp, 0, sizeof(ssp));
66 +  if (sysctl(mib, 2, cp_time, &size, NULL, 0) < 0) {
67 +    fprintf(stderr, "xosview: sysctl kern.cp_time failed: %s\n", strerror(errno));
68 +    bzero(&cp_time, size);
69    }
70 -  for (size = 0; size < CPUSTATES; size++)
71 -    timeArray[size] = (long) ssp.spc_cp_time[size];
72 +  bcopy (cp_time, timeArray, size);
73  #else
74  #ifdef XOSVIEW_BSDI
75    if (sysctl(mib, 2, &cpu, &size, NULL, 0) < 0) {
76 @@ -441,7 +452,7 @@
77  }
78  
79  void
80 -BSDGetNetInOut (long long * inbytes, long long * outbytes) {
81 +NetMeter::BSDGetNetInOut (long long * inbytes, long long * outbytes) {
82  
83  
84    struct ifnet * ifnetp;
85 @@ -466,7 +477,8 @@
86    while (ifnetp) {
87      //  Now, dereference the pointer to get the ifnet struct.
88      safe_kvm_read ((u_long) ifnetp, &ifnet, sizeof(ifnet));
89 -#ifdef NET_DEBUG
90 +#ifdef XOSVIEW_NETBSD
91 +    if (netIface_ != "False" ) {
92      char ifname[256];
93  #ifdef NETBSD_OLD_IFACE
94      //  In pre-1.2A, getting the interface name was more complicated.
95 @@ -476,15 +488,21 @@
96      safe_kvm_read ((u_long) (((char*)ifnetp) + (&ifnet.if_xname[0] - (char*)&ifnet)), ifname, 256);
97      snprintf (ifname, 256, "%s", ifname);
98  #endif
99 +#ifdef NET_DEBUG
100      printf ("Interface name is %s\n", ifname);
101      printf ("Ibytes: %8llu Obytes %8llu\n",
102         (unsigned long long) ifnet.if_ibytes,
103         (unsigned long long) ifnet.if_obytes);
104      printf ("Ipackets:  %8llu\n", (unsigned long long) ifnet.if_ipackets);
105 -#endif
106 +#endif /* NET_DEBUG */
107 +      if (ifname != netIface_)
108 +       goto skipif;
109 +    }
110 +#endif /* XOSVIEW_NETBSD */
111      *inbytes  += ifnet.if_ibytes;
112      *outbytes += ifnet.if_obytes;
113  
114 +    skipif:
115      //  Linked-list step taken from if.c in netstat source, line 120.
116  #ifdef XOSVIEW_FREEBSD
117  #if (__FreeBSD_version >= 300000) 
118 @@ -773,13 +791,12 @@
119  #ifdef NETBSD_1_6A
120    // Do a sysctl with a NULL data pointer to get the size that would
121    // have been returned, and use that to figure out # drives.
122 -  int mib[3] = {CTL_HW, HW_DISKSTATS, sizeof(struct disk_sysctl)};
123    size_t size;
124 -  if (sysctl(mib, 3, NULL, &size, NULL, 0) < 0) {
125 +  if (sysctl(dmib, 3, NULL, &size, NULL, 0) < 0) {
126      warnx("!!! The DiskMeter sysctl failed.  Disabling DiskMeter.");
127      return 0;
128    }
129 -  NetBSD_N_Drives = size / sizeof(struct disk_sysctl);
130 +  NetBSD_N_Drives = size / dmib[2];
131    return 1;
132  #endif
133    return ValidSymbol(DISKLIST_SYM_INDEX);
134 @@ -816,19 +833,29 @@
135  #else
136  #if defined(NETBSD_1_6A)
137    // Use the new sysctl to do this for us.
138 -  int mib[3] = {CTL_HW, HW_DISKSTATS, sizeof(struct disk_sysctl)};
139 -  size_t sysctl_sz = NetBSD_N_Drives * sizeof(struct disk_sysctl);
140 +  size_t sysctl_sz = NetBSD_N_Drives * dmib[2];
141 +#ifdef HW_DISKSTATS
142    struct disk_sysctl drive_stats[NetBSD_N_Drives];
143 +#endif
144 +#ifdef HW_IOSTATS
145 +  struct io_sysctl drive_stats[NetBSD_N_Drives];
146 +#endif
147  
148    // Do the sysctl.
149 -  if (sysctl(mib, 3, drive_stats, &sysctl_sz, NULL, 0) < 0) {
150 +  if (sysctl(dmib, 3, drive_stats, &sysctl_sz, NULL, 0) < 0) {
151      err(1, "sysctl hw.diskstats failed");
152    }
153  
154    // Now accumulate the total.
155    unsigned long long xferred = 0;
156    for (unsigned int i = 0; i < NetBSD_N_Drives; i++) {
157 +#ifdef HW_DISKSTATS
158      xferred += drive_stats[i].dk_rbytes + drive_stats[i].dk_wbytes;
159 +#endif
160 +#ifdef HW_IOSTATS
161 +    if (drive_stats[i].type == IOSTAT_DISK)
162 +       xferred += drive_stats[i].rbytes + drive_stats[i].wbytes;
163 +#endif
164    }
165    *bytesXferred = xferred;
166  #else
167 @@ -1016,7 +1043,7 @@
168  
169      while (evptr && i < NUM_INTR) {
170  
171 -      safe_kvm_read((unsigned int)evptr, &evcnt, sizeof(evcnt));
172 +      safe_kvm_read((u_long)evptr, &evcnt, sizeof(evcnt));
173  
174        evptr = evcnt.ev_list.tqe_next;
175  
176 @@ -1024,7 +1051,7 @@
177        if (evcnt.ev_type != EVCNT_TYPE_INTR)
178         continue;
179  
180 -      safe_kvm_read((unsigned int)evcnt.ev_name, evname, evcnt.ev_namelen);
181 +      safe_kvm_read((u_long)evcnt.ev_name, evname, evcnt.ev_namelen);
182        // If it's a soft interrupt (has a name that starts with "soft"), skip it.
183        if (!strncmp(evname, "soft", 4))
184         continue;