1 diff -urN libgtop-2.25.91/include/glibtop/procstate.h ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/include/glibtop/procstate.h 2 --- libgtop-2.25.91/include/glibtop/procstate.h 2008-05-23 22:13:20.000000000 +0000 3 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/include/glibtop/procstate.h 2009-02-25 17:16:38.052247000 +0000 4 @@ -69,6 +69,13 @@ 5 int has_cpu; 6 int processor; 7 int last_processor; 8 + 9 + gint32 nice; /*zhua: used to store nice */ 10 + guint64 start_time; /* start time of process -- */ 11 + guint64 vsize; /* number of pages of virtual memory ... */ 12 + guint64 resident; /* number of resident set */ 13 + guint load; /* cpu load for process */ 14 + gint32 ppid; /* pid of parent process */ 15 }; 16 17 void glibtop_get_proc_state(glibtop_proc_state *buf, pid_t pid); 18 diff -urN libgtop-2.25.91/procmap.c ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/procmap.c 19 --- libgtop-2.25.91/procmap.c 1970-01-01 00:00:00.000000000 +0000 20 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/procmap.c 2009-02-25 17:16:38.053079000 +0000 21 @@ -0,0 +1,252 @@ 22 +/* Copyright (C) 1998-99 Martin Baulig 23 + This file is part of LibGTop 1.0. 24 + 25 + Contributed by Martin Baulig <martin (a] home-of-linux.org>, April 1998. 26 + 27 + LibGTop is free software; you can redistribute it and/or modify it 28 + under the terms of the GNU General Public License as published by 29 + the Free Software Foundation; either version 2 of the License, 30 + or (at your option) any later version. 31 + 32 + LibGTop is distributed in the hope that it will be useful, but WITHOUT 33 + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 34 + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 35 + for more details. 36 + 37 + You should have received a copy of the GNU General Public License 38 + along with LibGTop; see the file COPYING. If not, write to the 39 + Free Software Foundation, Inc., 59 Temple Place - Suite 330, 40 + Boston, MA 02111-1307, USA. 41 +*/ 42 + 43 + 44 +#include <config.h> 45 +#include <glibtop.h> 46 +#include <glibtop/error.h> 47 +#include <glibtop/procmap.h> 48 + 49 +#include <errno.h> 50 + 51 +#include "safeio.h" 52 + 53 + 54 +static const unsigned long _glibtop_sysdeps_proc_map = 55 +(1L << GLIBTOP_PROC_MAP_NUMBER) + (1L << GLIBTOP_PROC_MAP_TOTAL) + 56 +(1L << GLIBTOP_PROC_MAP_SIZE); 57 +static const unsigned long _glibtop_sysdeps_map_entry = 58 +(1L << GLIBTOP_MAP_ENTRY_START) + (1L << GLIBTOP_MAP_ENTRY_END) + 59 +(1L << GLIBTOP_MAP_ENTRY_OFFSET) + (1L << GLIBTOP_MAP_ENTRY_PERM); 60 +static const unsigned long _glibtop_sysdeps_map_device = 61 +(1L << GLIBTOP_MAP_ENTRY_DEVICE) + (1L << GLIBTOP_MAP_ENTRY_INODE); 62 + 63 + 64 +/* Init function. */ 65 + 66 +void 67 +_glibtop_init_proc_map_s (glibtop *server) 68 +{ 69 + server->sysdeps.proc_map = _glibtop_sysdeps_proc_map; 70 +} 71 + 72 +/* Provides detailed information about a process. */ 73 + 74 +glibtop_map_entry * 75 +glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid) 76 +{ 77 + int fd, i, nmaps, pr_err, heap; 78 + 79 + char filename [BUFSIZ]; 80 + /* use flags as a check condition, if it is 1, check, or, not check... zhua */ 81 + int check = buf->flags; 82 + /* set flags back to 0 */ 83 + buf->flags = 0; 84 + 85 +#if GLIBTOP_SOLARIS_RELEASE >= 50600 86 + prxmap_t *maps; 87 +// struct ps_prochandle *Pr = NULL; 88 +#else 89 + prmap_t *maps; 90 +#endif 91 + 92 + /* A few defines, to make it shorter down there */ 93 + 94 +#ifdef HAVE_PROCFS_H 95 +# define OFFSET pr_offset 96 +#else 97 +# define OFFSET pr_off 98 +#endif 99 + 100 + glibtop_map_entry *entry; 101 + struct stat inode; 102 + char buffer[BUFSIZ]; 103 + 104 + memset (buf, 0, sizeof (glibtop_proc_map)); 105 + 106 +#ifdef HAVE_PROCFS_H 107 + sprintf(buffer, "/proc/%d/xmap", (int)pid); 108 +#else 109 + sprintf(buffer, "/proc/%d", (int)pid); 110 +#endif 111 + if((fd = s_open(buffer, O_RDONLY)) < 0) 112 + { 113 + if (errno != EPERM && errno != EACCES) 114 + glibtop_warn_io_r(server, "open (%s)", buffer); 115 + return NULL; 116 + } 117 +#ifdef HAVE_PROCFS_H 118 + if(fstat(fd, &inode) < 0) 119 + { 120 + if(errno != EOVERFLOW) 121 + glibtop_warn_io_r(server, "fstat (%s)", buffer); 122 + /* else call daemon for 64-bit support */ 123 + s_close(fd); 124 + return NULL; 125 + } 126 + maps = g_alloca(inode.st_size); 127 + nmaps = inode.st_size / sizeof(prxmap_t); 128 + if(s_pread(fd, maps, inode.st_size, 0) != inode.st_size) 129 + { 130 + glibtop_warn_io_r(server, "pread (%s)", buffer); 131 + s_close(fd); 132 + return NULL; 133 + } 134 +#else 135 + if(ioctl(fd, PIOCNMAP, &nmaps) < 0) 136 + { 137 + glibtop_warn_io_r(server, "ioctl(%s, PIOCNMAP)", buffer); 138 + s_close(fd); 139 + return NULL; 140 + } 141 + maps = g_alloca((nmaps + 1) * sizeof(prmap_t)); 142 + if(ioctl(fd, PIOCMAP, maps) < 0) 143 + { 144 + glibtop_warn_io_r(server, "ioctl(%s, PIOCMAP)", buffer); 145 + s_close(fd); 146 + return NULL; 147 + } 148 +#endif 149 + buf->number = nmaps; 150 + buf->size = sizeof(glibtop_map_entry); 151 + buf->total = nmaps * sizeof(glibtop_map_entry); 152 + entry = g_malloc0(buf->total); 153 + 154 +//#if GLIBTOP_SOLARIS_RELEASE >= 50600 155 + 156 +// if(server->machine.objname && server->machine.pgrab && 157 +// server->machine.pfree) 158 +// Pr = (server->machine.pgrab)(pid, 1, &pr_err); 159 +//#endif 160 + for(heap = 0,i = 0; i < nmaps; ++i) 161 + { 162 + int len; 163 + 164 + /* take a check to see if we need all information, if not, just get what we need.. 165 + Also please see comments in get_process_memory_writable() of gnome-system-monitor zhua */ 166 + if (check == 1) 167 + { 168 + if(maps[i].pr_mflags & MA_WRITE){ 169 + entry[i].perm |= GLIBTOP_MAP_PERM_WRITE; 170 + entry[i].size = maps[i].pr_size; 171 + } 172 + if(maps[i].pr_mflags & MA_SHARED){ 173 + entry[i].perm |= GLIBTOP_MAP_PERM_SHARED; 174 + /* here use shared_clean to store Shared Memory */ 175 + entry[i].shared_clean = maps[i].pr_size; 176 + } 177 + } 178 + else 179 + if (check == 2) 180 + { 181 + if(maps[i].pr_mflags & MA_SHARED){ 182 + entry[i].perm |= GLIBTOP_MAP_PERM_SHARED; 183 + /* here use shared_clean to store Shared Memory */ 184 + entry[i].shared_clean = maps[i].pr_size; 185 + } 186 + } 187 + else { 188 + 189 + int len, rv; 190 + 191 + 192 + entry[i].start = maps[i].pr_vaddr; 193 + entry[i].end = maps[i].pr_vaddr + maps[i].pr_size; 194 + 195 +#if GLIBTOP_SOLARIS_RELEASE >= 50600 196 + 197 + if(maps[i].pr_dev != PRNODEV) 198 + { 199 + entry[i].device = maps[i].pr_dev; 200 + entry[i].inode = maps[i].pr_ino; 201 + entry[i].flags |= _glibtop_sysdeps_map_device; 202 + } 203 +#endif 204 + entry[i].offset = maps[i].OFFSET; 205 + if(maps[i].pr_mflags & MA_READ) 206 + entry[i].perm |= GLIBTOP_MAP_PERM_READ; 207 + if(maps[i].pr_mflags & MA_WRITE){ 208 + entry[i].perm |= GLIBTOP_MAP_PERM_WRITE; 209 + entry[i].size = maps[i].pr_size; 210 + } 211 + if(maps[i].pr_mflags & MA_EXEC) 212 + entry[i].perm |= GLIBTOP_MAP_PERM_EXECUTE; 213 + if(maps[i].pr_mflags & MA_SHARED) 214 + entry[i].perm |= GLIBTOP_MAP_PERM_SHARED; 215 + else 216 + entry[i].perm |= GLIBTOP_MAP_PERM_PRIVATE; 217 + entry[i].flags = _glibtop_sysdeps_map_entry; 218 + 219 +#if GLIBTOP_SOLARIS_RELEASE >= 50600 220 + 221 + if(maps[i].pr_mflags & MA_ANON) 222 + { 223 + if(!heap) 224 + { 225 + ++heap; 226 + strcpy(entry[i].filename, "[ heap ]"); 227 + } 228 + else 229 + if(i == nmaps - 1) 230 + strcpy(entry[i].filename, "[ stack ]"); 231 + else 232 + strcpy(entry[i].filename, "[ anon ]"); 233 + entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME); 234 + } 235 + else 236 +// if(Pr) 237 +// { 238 +// server->machine.objname(Pr, maps[i].pr_vaddr, buffer, 239 +// BUFSIZ); 240 +// if((len = resolvepath(buffer, entry[i].filename, 241 +// GLIBTOP_MAP_FILENAME_LEN)) > 0) 242 +// { 243 +// entry[i].filename[len] = 0; 244 +// entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME); 245 +// } 246 +// } 247 + { 248 + g_strlcpy(buffer, maps[i].pr_mapname, sizeof buffer); 249 + /* from /path get file name */ 250 + g_snprintf(filename, sizeof filename, "/proc/%d/path/%s", 251 + pid, buffer); 252 + 253 + rv = readlink(filename, entry[i].filename, sizeof(entry[i].filename) - 1); 254 + /* read object, if have not, set it as NULL */ 255 + if(rv < 0) 256 + rv = 0; 257 + entry[i].filename[rv] = '\0'; 258 + /* now set the flags */ 259 + entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME); 260 + } 261 +#endif 262 + } 263 + } 264 + 265 +//#if GLIBTOP_SOLARIS_RELEASE >= 50600 266 + 267 +// if(Pr) 268 +// server->machine.pfree(Pr); 269 +//#endif 270 + buf->flags = _glibtop_sysdeps_proc_map; 271 + s_close(fd); 272 + return entry; 273 +} 274 diff -urN libgtop-2.25.91/sysdeps/common/fsusage.c ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/common/fsusage.c 275 --- libgtop-2.25.91/sysdeps/common/fsusage.c 2008-05-23 22:13:22.000000000 +0000 276 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/common/fsusage.c 2009-02-25 17:25:57.183257000 +0000 277 @@ -149,6 +149,15 @@ 278 #define _glibtop_get_fsusage_read_write(S, B, P) \ 279 _glibtop_freebsd_get_fsusage_read_write(S, B, P) 280 281 +#elif (defined(sun) || defined(__sun)) 282 +G_GNUC_INTERNAL void 283 +_glibtop_sun_get_fsusage_read_write(glibtop *server, 284 + glibtop_fsusage *buf, 285 + const char *path); 286 + 287 +#define _glibtop_get_fsusage_read_write(S, B, P) \ 288 + _glibtop_sun_get_fsusage_read_write(S, B, P) 289 + 290 #else /* default fallback */ 291 #warning glibtop_get_fsusage .read .write are not implemented. 292 static inline void 293 diff -urN libgtop-2.25.91/sysdeps/common/mountlist.c ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/common/mountlist.c 294 --- libgtop-2.25.91/sysdeps/common/mountlist.c 2008-05-23 22:13:22.000000000 +0000 295 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/common/mountlist.c 2009-02-25 17:16:38.053543000 +0000 296 @@ -591,6 +591,17 @@ 297 298 for (cur = &entries[0]; cur != NULL; cur = next) { 299 300 + /*zhua: delete these 2 type of fs: objfs,ctfs */ 301 + if (!strcmp(cur->me_type, "objfs") || !strcmp(cur->me_type,"ctfs")){ 302 + /* free current mount_entry and move to the next */ 303 + next = cur->me_next; 304 + g_free(cur->me_devname); 305 + g_free(cur->me_mountdir); 306 + g_free(cur->me_type); 307 + g_free(cur); 308 + continue; 309 + } 310 + 311 if(all_fs || !ignore_mount_entry(cur)) { 312 /* add a new glibtop_mountentry */ 313 glibtop_mountentry e; 314 diff -urN libgtop-2.25.91/sysdeps/solaris/Makefile.am ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/Makefile.am 315 --- libgtop-2.25.91/sysdeps/solaris/Makefile.am 2008-05-23 22:13:24.000000000 +0000 316 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/Makefile.am 2009-02-25 17:27:23.462319000 +0000 317 @@ -8,7 +8,8 @@ 318 proclist.c procstate.c procuid.c \ 319 proctime.c procmem.c procsignal.c \ 320 prockernel.c procsegment.c procargs.c \ 321 - procopenfiles.c \ 322 + procopenfiles.c sysinfo.c fsusage.c procwd.c \ 323 + glibtop_private.c procaffinity.c \ 324 procmap.c netload.c ppp.c procdata.c netlist.c 325 326 libgtop_sysdeps_2_0_la_LDFLAGS = $(LT_VERSION_INFO) 327 diff -urN libgtop-2.25.91/sysdeps/solaris/cpu.c ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/cpu.c 328 --- libgtop-2.25.91/sysdeps/solaris/cpu.c 2008-05-23 22:13:24.000000000 +0000 329 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/cpu.c 2009-02-25 17:16:38.055204000 +0000 330 @@ -34,6 +34,7 @@ 331 332 static const unsigned long _glibtop_sysdeps_cpu_all = 333 (1L << GLIBTOP_CPU_TOTAL) + (1L << GLIBTOP_CPU_USER) + 334 +(1L << GLIBTOP_CPU_NICE) + /* this value is needed by multiload */ 335 (1L << GLIBTOP_CPU_SYS) + (1L << GLIBTOP_CPU_IDLE) + 336 (1L << GLIBTOP_XCPU_TOTAL) + (1L << GLIBTOP_XCPU_USER) + 337 (1L << GLIBTOP_XCPU_SYS) + (1L << GLIBTOP_XCPU_IDLE) + 338 diff -urN libgtop-2.25.91/sysdeps/solaris/fsusage.c ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/fsusage.c 339 --- libgtop-2.25.91/sysdeps/solaris/fsusage.c 1970-01-01 00:00:00.000000000 +0000 340 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/fsusage.c 2009-02-25 17:20:33.608888000 +0000 341 @@ -0,0 +1,99 @@ 342 +#include <config.h> 343 +#include <glibtop.h> 344 +#include <glibtop/error.h> 345 +#include <glibtop/fsusage.h> 346 +#include <glibtop/union.h> 347 + 348 +#include "glibtop_private.h" 349 + 350 +#include <glib.h> 351 + 352 +#include <unistd.h> 353 +#include <kstat.h> 354 +#include <sys/types.h> 355 +#include <sys/stat.h> 356 +#include <sys/statvfs.h> 357 + 358 +#include <stdio.h> 359 +#include <string.h> 360 +#include <stdlib.h> 361 + 362 +G_GNUC_INTERNAL void 363 +_glibtop_sun_get_fsusage_read_write(glibtop *server, 364 + glibtop_fsusage *buf, 365 + const char *path) 366 +{ 367 + struct statvfs64 statvfsbuf; 368 + char ksname[KSTAT_STRLEN + 1]; 369 + kstat_ctl_t * const kctl = server->machine.kc; 370 + kstat_t *ksp; 371 + kstat_io_t kio; 372 + kstat_named_t *kread, *kwrite; 373 + int i; 374 + 375 + /* 376 + * get a kstat handle and update the user's kstat chain 377 + */ 378 + if( kctl == NULL ){ 379 + glibtop_warn_io_r (server, "kstat_open ()"); 380 + return; 381 + } 382 + 383 + /* make sure we have current data */ 384 + while( kstat_chain_update( kctl ) != 0 ) 385 + ; 386 + 387 + for (ksp = kctl->kc_chain, i =0; ksp != NULL; ksp = ksp->ks_next, i++) { 388 + if (ksp->ks_type == KSTAT_TYPE_IO && strcmp(ksp->ks_class,"disk") == 0) { 389 + kstat_read(kctl, ksp, &kio); 390 + buf->read += kio.nread; 391 + buf->write += kio.nwritten; 392 + } 393 + } 394 +#if 0 395 + /* these codes keep here, because they are a good way to get the 396 + fsusage information, but at the moment, the interfaces used 397 + are not public or stable. so let's use them when public... 398 + */ 399 + /* 400 + * get a kstat handle and update the user's kstat chain 401 + */ 402 + if( kctl == NULL ){ 403 + glibtop_warn_io_r (server, "kstat_open ()"); 404 + return; 405 + } 406 + 407 + while( kstat_chain_update( kctl ) != 0 ) 408 + ; 409 + 410 + if (statvfs64(path, &statvfsbuf) != 0) { 411 + glibtop_warn_io_r (server, "kstat_open ()"); 412 + return; 413 + } 414 + snprintf(ksname, KSTAT_STRLEN, "%s%lx", VOPSTATS_STR, 415 + statvfsbuf.f_fsid); 416 + 417 + /* 418 + * traverse the kstat chain 419 + * to find the appropriate statistics 420 + */ 421 + if( (ksp = kstat_lookup( kctl, 422 + "unix", 0, ksname )) == NULL ) { 423 + return; 424 + } 425 + if( kstat_read( kctl, ksp, NULL ) == -1 ) { 426 + return; 427 + } 428 + 429 + kread = (kstat_named_t *)kstat_data_lookup(ksp,"read_bytes"); 430 + if( kread != NULL ) { 431 + buf->read = kread->value.ull; 432 + } 433 + 434 + kwrite = (kstat_named_t *)kstat_data_lookup(ksp,"write_bytes"); 435 + if( kwrite != NULL ) { 436 + buf->write = kwrite->value.ull; 437 + } 438 +#endif 439 + buf->flags |= (1 << GLIBTOP_FSUSAGE_READ) | (1 << GLIBTOP_FSUSAGE_WRITE); 440 +} 441 diff -urN libgtop-2.25.91/sysdeps/solaris/glibtop_machine.h ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/glibtop_machine.h 442 --- libgtop-2.25.91/sysdeps/solaris/glibtop_machine.h 2008-05-23 22:13:24.000000000 +0000 443 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/glibtop_machine.h 2009-02-25 17:16:38.055426000 +0000 444 @@ -61,14 +61,14 @@ 445 int pagesize; /* in bits to shift, ie. 2^pagesize gives Kb */ 446 int ticks; /* clock ticks, as returned by sysconf() */ 447 unsigned long long boot; /* boot time, although it's ui32 in kstat */ 448 - void *libproc; /* libproc handle */ 449 -#if GLIBTOP_SOLARIS_RELEASE >= 50600 450 - void (*objname)(void *, uintptr_t, const char *, size_t); 451 - struct ps_prochandle *(*pgrab)(pid_t, int, int *); 452 - void (*pfree)(void *); 453 -#else 454 +// void *libproc; /* libproc handle */ 455 +//#if GLIBTOP_SOLARIS_RELEASE >= 50600 456 +// void (*objname)(void *, uintptr_t, const char *, size_t); 457 +// struct ps_prochandle *(*pgrab)(pid_t, int, int *); 458 +// void (*pfree)(void *); 459 +//#else 460 void *filler[3]; 461 -#endif 462 +//#endif 463 }; 464 465 G_END_DECLS 466 diff -urN libgtop-2.25.91/sysdeps/solaris/glibtop_private.c ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/glibtop_private.c 467 --- libgtop-2.25.91/sysdeps/solaris/glibtop_private.c 1970-01-01 00:00:00.000000000 +0000 468 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/glibtop_private.c 2009-02-25 17:16:38.055744000 +0000 469 @@ -0,0 +1,203 @@ 470 +#include <config.h> 471 +#include <glibtop.h> 472 +#include <glibtop/error.h> 473 + 474 +#include "glibtop_private.h" 475 + 476 +#include <glib.h> 477 + 478 +#include <string.h> 479 +#include <stdlib.h> 480 +#include <stdarg.h> 481 + 482 +#include <fcntl.h> 483 +#include <unistd.h> 484 + 485 +#if 0 486 +unsigned long long 487 +get_scaled(const char *buffer, const char *key) 488 +{ 489 + const char *ptr; 490 + char *next; 491 + unsigned long long value = 0; 492 + 493 + if (G_LIKELY((ptr = strstr(buffer, key)))) 494 + { 495 + ptr += strlen(key); 496 + value = strtoull(ptr, &next, 0); 497 + 498 + for ( ; *next; ++next) { 499 + if (*next == 'k') { 500 + value *= 1024; 501 + break; 502 + } else if (*next == 'M') { 503 + value *= 1024 * 1024; 504 + break; 505 + } 506 + } 507 + } else 508 + g_warning("Could not read key '%s' in buffer '%s'", 509 + key, buffer); 510 + 511 + return value; 512 +} 513 + 514 + 515 +char * 516 +skip_token (const char *p) 517 +{ 518 + p = next_token(p); 519 + while (*p && !isspace(*p)) p++; 520 + p = next_token(p); 521 + return (char *)p; 522 +} 523 + 524 + 525 +/* 526 + * Read functions 527 + */ 528 +enum TRY_FILE_TO_BUFFER 529 +{ 530 + TRY_FILE_TO_BUFFER_OK = 0, 531 + TRY_FILE_TO_BUFFER_OPEN = -1, 532 + TRY_FILE_TO_BUFFER_READ = -2 533 +}; 534 + 535 +int try_file_to_buffer(char *buffer, const char *format, ...) 536 +{ 537 + char path[4096]; 538 + int fd; 539 + ssize_t len; 540 + va_list pa; 541 + 542 + va_start(pa, format); 543 + 544 + /* C99 also provides vsnprintf */ 545 + g_vsnprintf(path, sizeof path, format, pa); 546 + 547 + va_end(pa); 548 + 549 + buffer [0] = '\0'; 550 + 551 + if((fd = open (path, O_RDONLY)) < 0) 552 + return TRY_FILE_TO_BUFFER_OPEN; 553 + 554 + len = read (fd, buffer, BUFSIZ-1); 555 + close (fd); 556 + 557 + if (len < 0) 558 + return TRY_FILE_TO_BUFFER_READ; 559 + 560 + buffer [len] = '\0'; 561 + 562 + return TRY_FILE_TO_BUFFER_OK; 563 +} 564 + 565 + 566 +void 567 +file_to_buffer(glibtop *server, char *buffer, const char *filename) 568 +{ 569 + switch(try_file_to_buffer(buffer, filename)) 570 + { 571 + case TRY_FILE_TO_BUFFER_OPEN: 572 + glibtop_error_io_r (server, "open (%s)", filename); 573 + case TRY_FILE_TO_BUFFER_READ: 574 + glibtop_error_io_r (server, "read (%s)", filename); 575 + } 576 +} 577 + 578 + 579 + 580 + 581 +static unsigned long 582 +read_boot_time(glibtop *server) 583 +{ 584 + char buffer[BUFSIZ]; 585 + char *btime; 586 + 587 + file_to_buffer(server, buffer, "/proc/stat"); 588 + 589 + btime = strstr(buffer, "btime"); 590 + 591 + if (!btime) { 592 + glibtop_warn_io_r(server, "cannot find btime in /proc/stat"); 593 + return 0UL; 594 + } 595 + 596 + btime = skip_token(btime); 597 + return strtoul(btime, NULL, 10); 598 +} 599 + 600 + 601 + 602 +unsigned long 603 +get_boot_time(glibtop *server) 604 +{ 605 + static unsigned long boot_time = 0UL; 606 + 607 + if(G_UNLIKELY(!boot_time)) 608 + { 609 + boot_time = read_boot_time(server); 610 + } 611 + 612 + return boot_time; 613 +} 614 + 615 + 616 +size_t 617 +get_page_size(void) 618 +{ 619 + static size_t pagesize = 0; 620 + 621 + if(G_UNLIKELY(!pagesize)) 622 + { 623 + pagesize = getpagesize(); 624 + } 625 + 626 + return pagesize; 627 +} 628 + 629 + 630 + 631 +gboolean 632 +check_cpu_line(glibtop *server, const char *line, unsigned i) 633 +{ 634 + char start[10]; 635 + 636 + g_snprintf(start, sizeof start, "cpu%u", i); 637 + 638 + return g_str_has_prefix(line, start); 639 +} 640 + 641 + 642 + 643 +gboolean 644 +has_sysfs(void) 645 +{ 646 + static gboolean init; 647 + static gboolean sysfs; 648 + 649 + if (G_UNLIKELY(!init)) { 650 + sysfs = g_file_test("/sys", G_FILE_TEST_IS_DIR); 651 + init = TRUE; 652 + } 653 + 654 + return sysfs; 655 +} 656 +#endif 657 + 658 + 659 +gboolean safe_readlink(const char *path, char *buf, size_t bufsiz) 660 +{ 661 + ssize_t ret; 662 + 663 + ret = readlink(path, buf, bufsiz - 1); 664 + 665 + if (ret == -1) { 666 + g_warning("Could not read link %s : %s", path, strerror(errno)); 667 + return FALSE; 668 + } 669 + 670 + buf[ret] = '\0'; 671 + return TRUE; 672 +} 673 diff -urN libgtop-2.25.91/sysdeps/solaris/glibtop_private.h ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/glibtop_private.h 674 --- libgtop-2.25.91/sysdeps/solaris/glibtop_private.h 2008-05-23 22:13:24.000000000 +0000 675 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/glibtop_private.h 2009-02-25 17:16:38.057019000 +0000 676 @@ -60,6 +60,8 @@ 677 /* Reread kstat chains */ 678 void glibtop_get_kstats(glibtop *); 679 680 +gboolean safe_readlink(const char *path, char *buf, size_t bufsiz); 681 + 682 G_END_DECLS 683 684 #endif /* __GLIBTOP_PRIVATE_H__ */ 685 diff -urN libgtop-2.25.91/sysdeps/solaris/glibtop_server.h ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/glibtop_server.h 686 --- libgtop-2.25.91/sysdeps/solaris/glibtop_server.h 2008-05-23 22:13:24.000000000 +0000 687 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/glibtop_server.h 2009-02-25 17:16:38.057265000 +0000 688 @@ -29,9 +29,15 @@ 689 #define GLIBTOP_SUID_SWAP 0 690 #define GLIBTOP_SUID_UPTIME 0 691 #define GLIBTOP_SUID_LOADAVG 0 692 +#if GLIBTOP_SOLARIS_RELEASE < 51000 693 #define GLIBTOP_SUID_SHM_LIMITS (1L << GLIBTOP_SYSDEPS_SHM_LIMITS) 694 #define GLIBTOP_SUID_MSG_LIMITS (1L << GLIBTOP_SYSDEPS_MSG_LIMITS) 695 #define GLIBTOP_SUID_SEM_LIMITS (1L << GLIBTOP_SYSDEPS_SEM_LIMITS) 696 +#else 697 +#define GLIBTOP_SUID_SHM_LIMITS 0 698 +#define GLIBTOP_SUID_MSG_LIMITS 0 699 +#define GLIBTOP_SUID_SEM_LIMITS 0 700 +#endif 701 #define GLIBTOP_SUID_PROCLIST 0 702 #define GLIBTOP_SUID_PROC_STATE 0 703 #define GLIBTOP_SUID_PROC_UID 0 704 @@ -44,7 +50,10 @@ 705 #define GLIBTOP_SUID_PROC_MAP 0 706 #define GLIBTOP_SUID_NETLOAD 0 707 #define GLIBTOP_SUID_NETLIST 0 708 +#define GLIBTOP_SUID_PROC_WD 0 709 #define GLIBTOP_SUID_PPP 0 710 +#define GLIBTOP_SUID_PROC_AFFINITY 0 711 + 712 713 G_END_DECLS 714 715 diff -urN libgtop-2.25.91/sysdeps/solaris/msg_limits.c ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/msg_limits.c 716 --- libgtop-2.25.91/sysdeps/solaris/msg_limits.c 2008-05-23 22:13:24.000000000 +0000 717 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/msg_limits.c 2009-02-25 17:16:38.058081000 +0000 718 @@ -37,14 +37,24 @@ 719 (1L << GLIBTOP_IPC_MSGMNB) + (1L << GLIBTOP_IPC_MSGMNI) + 720 (1L << GLIBTOP_IPC_MSGTQL); 721 #else 722 -static const unsigned long _glibtop_sysdeps_msg_limits = 0; 723 +static const unsigned long _glibtop_sysdeps_msg_limits = 724 +(1L << GLIBTOP_IPC_MSGMNB) + 725 +(1L << GLIBTOP_IPC_MSGMNI) + 726 +(1L << GLIBTOP_IPC_MSGMAX) + 727 +(1L << GLIBTOP_IPC_MSGPOOL) + 728 +(1L << GLIBTOP_IPC_MSGTQL); 729 #endif 730 731 732 /* Init function. */ 733 734 +#if GLIBTOP_SUID_MSG_LIMITS 735 void 736 _glibtop_init_msg_limits_p (glibtop *server) 737 +#else 738 +void 739 +_glibtop_init_msg_limits_s (glibtop *server) 740 +#endif 741 { 742 #if GLIBTOP_SOLARIS_RELEASE < 51000 743 744 @@ -59,8 +69,13 @@ 745 746 /* Provides information about sysv ipc limits. */ 747 748 +#if GLIBTOP_SUID_MSG_LIMITS 749 void 750 glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf) 751 +#else 752 +void 753 +glibtop_get_msg_limits_s (glibtop *server, glibtop_msg_limits *buf) 754 +#endif 755 { 756 #if GLIBTOP_SOLARIS_RELEASE < 51000 757 758 diff -urN libgtop-2.25.91/sysdeps/solaris/netload.c ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/netload.c 759 --- libgtop-2.25.91/sysdeps/solaris/netload.c 2008-05-23 22:13:24.000000000 +0000 760 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/netload.c 2009-02-25 17:16:38.059013000 +0000 761 @@ -37,6 +37,17 @@ 762 763 #include <net/if.h> 764 765 +#ifdef HAVE_IFADDRS_H 766 +/* needed for IPV6 support */ 767 + 768 +#include <ifaddrs.h> 769 + 770 +#ifndef IN6_IS_ADDR_GLOBAL 771 +#define IN6_IS_ADDR_GLOBAL(a) \ 772 + (((((__const uint8_t *) (a))[0] & 0xff) == 0x3f \ 773 + || (((__const uint8_t *) (a))[0] & 0xff) == 0x20)) 774 +#endif 775 +#endif /* HAVE_IFADDRS_H */ 776 777 static const unsigned long _glibtop_sysdeps_netload = 778 (1L << GLIBTOP_NETLOAD_ERRORS_IN) + 779 @@ -89,6 +100,72 @@ 780 _glibtop_sysdeps_netload_packets; 781 } 782 783 +#ifdef HAVE_IFADDRS_H 784 + 785 +static void get_ipv6(glibtop *server, glibtop_netload *buf, 786 + const char *interface) 787 +{ 788 +/* 789 + * remove this code, because they are not available at Solaris, but keep them here for reference. 790 + * in fact, the function will not be called at Solaris, because HAVE_IFADDRS_H don't def. 791 + * 792 +*/ 793 +#if 0 794 + struct ifaddrs *ifa0, *ifr6; 795 + 796 + if(getifaddrs (&ifa0) != 0) 797 + { 798 + glibtop_warn_r(server, "getifaddrs failed : %s", g_strerror(errno)); 799 + return; 800 + } 801 + 802 + for (ifr6 = ifa0; ifr6; ifr6 = ifr6->ifa_next) { 803 + if (strcmp (ifr6->ifa_name, interface) == 0 804 + && ifr6->ifa_addr != NULL 805 + && ifr6->ifa_addr->sa_family == AF_INET6) 806 + break; 807 + } 808 + 809 + if(!ifr6) goto free_ipv6; 810 + 811 + memcpy(buf->address6, 812 + &((struct sockaddr_in6 *) ifr6->ifa_addr)->sin6_addr, 813 + 16); 814 + 815 + memcpy(buf->prefix6, 816 + &((struct sockaddr_in6 *) ifr6->ifa_netmask)->sin6_addr, 817 + 16); 818 + 819 + 820 + if (IN6_IS_ADDR_LINKLOCAL (buf->address6)) 821 + buf->scope6 = GLIBTOP_IF_IN6_SCOPE_LINK; 822 + 823 + else if (IN6_IS_ADDR_SITELOCAL (buf->address6)) 824 + buf->scope6 = GLIBTOP_IF_IN6_SCOPE_SITE; 825 + 826 + else if (IN6_IS_ADDR_GLOBAL (buf->address6) 827 + || IN6_IS_ADDR_MC_ORGLOCAL (buf->address6) 828 + || IN6_IS_ADDR_V4COMPAT (buf->address6) 829 + || IN6_IS_ADDR_MULTICAST (buf->address6) 830 + || IN6_IS_ADDR_UNSPECIFIED (buf->address6) 831 + ) 832 + buf->scope6 = GLIBTOP_IF_IN6_SCOPE_GLOBAL; 833 + 834 + else if (IN6_IS_ADDR_LOOPBACK (buf->address6)) 835 + buf->scope6 = GLIBTOP_IF_IN6_SCOPE_HOST; 836 + 837 + else 838 + buf->scope6 = GLIBTOP_IF_IN6_SCOPE_UNKNOWN; 839 + 840 + buf->flags |= _glibtop_sysdeps_netload_6; 841 + 842 + free_ipv6: 843 + freeifaddrs(ifa0); 844 +#endif 845 +} 846 + 847 +#endif /* HAVE_IFADDRS_H */ 848 + 849 static int 850 solaris_stats(glibtop *server, 851 glibtop_netload *buf, 852 @@ -245,6 +322,13 @@ 853 buf->subnet = ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr; 854 buf->flags |= (1L << GLIBTOP_NETLOAD_SUBNET); 855 } 856 + 857 +/* g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name); 858 + if (!ioctl (skfd, SIOCGIFHWADDR, &ifr)) { 859 + memcpy(buf->hwaddress, &ifr.ifr_hwaddr.sa_data, 8); 860 + buf->flags |= (1L << GLIBTOP_NETLOAD_HWADDRESS); 861 + }*/ 862 + 863 close (skfd); 864 } 865 866 @@ -254,4 +338,7 @@ 867 868 solaris_stats(server, buf, interface); 869 870 +#ifdef HAVE_IFADDRS_H 871 + get_ipv6(server, buf, interface); 872 +#endif /* HAVE_IFADDRS_H */ 873 } 874 diff -urN libgtop-2.25.91/sysdeps/solaris/open.c ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/open.c 875 --- libgtop-2.25.91/sysdeps/solaris/open.c 2008-05-23 22:13:24.000000000 +0000 876 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/open.c 2009-02-25 17:16:38.060014000 +0000 877 @@ -209,34 +209,34 @@ 878 } 879 } 880 881 - /* Now let's have a bit of magic dust... */ 882 +// /* Now let's have a bit of magic dust... */ 883 884 -#if GLIBTOP_SOLARIS_RELEASE >= 50600 885 +//#if GLIBTOP_SOLARIS_RELEASE >= 50600 886 887 - dl = dlopen("/usr/lib/libproc.so", RTLD_LAZY); 888 - if(server->machine.libproc) 889 - dlclose(server->machine.libproc); 890 - server->machine.libproc = dl; 891 - if(dl) 892 - { 893 - void *func; 894 + // dl = dlopen("/usr/lib/libproc.so", RTLD_LAZY); 895 + // if(server->machine.libproc) 896 +// // dlclose(server->machine.libproc); 897 + // server->machine.libproc = dl; 898 + // if(dl) 899 + // { 900 + // void *func; 901 902 - func = dlsym(dl, "Pobjname"); /* Solaris 8 */ 903 - if(!func) 904 - func = dlsym(dl, "proc_objname"); /* Solaris 7 */ 905 - server->machine.objname = (void (*) 906 - (void *, uintptr_t, const char *, size_t))func; 907 - server->machine.pgrab = (struct ps_prochandle *(*)(pid_t, int, int *)) 908 - dlsym(dl, "Pgrab"); 909 - server->machine.pfree = (void (*)(void *))dlsym(dl, "Pfree"); 910 - 911 - } 912 - else 913 - { 914 - server->machine.objname = NULL; 915 - server->machine.pgrab = NULL; 916 - server->machine.pfree = NULL; 917 - } 918 -#endif 919 + // func = dlsym(dl, "Pobjname"); /* Solaris 8 */ 920 + // if(!func) 921 +// func = dlsym(dl, "proc_objname"); /* Solaris 7 */ 922 + // server->machine.objname = (void (*) 923 +// (void *, uintptr_t, const char *, size_t))func; 924 + // server->machine.pgrab = (struct ps_prochandle *(*)(pid_t, int, int *)) 925 +// dlsym(dl, "Pgrab"); 926 + // server->machine.pfree = (void (*)(void *))dlsym(dl, "Pfree"); 927 + // 928 + // } 929 + // else 930 + // { 931 + // server->machine.objname = NULL; 932 + // server->machine.pgrab = NULL; 933 + // server->machine.pfree = NULL; 934 + // } 935 +//#endif 936 server->machine.me = getpid(); 937 } 938 diff -urN libgtop-2.25.91/sysdeps/solaris/procaffinity.c ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/procaffinity.c 939 --- libgtop-2.25.91/sysdeps/solaris/procaffinity.c 1970-01-01 00:00:00.000000000 +0000 940 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/procaffinity.c 2009-02-25 17:16:38.060320000 +0000 941 @@ -0,0 +1,84 @@ 942 +/* Copyright (C) 2007 Joe Marcus Clarke <marcus (a] FreeBSD.org> 943 + This file is part of LibGTop 2. 944 + 945 + LibGTop is free software; you can redistribute it and/or modify it 946 + under the terms of the GNU General Public License as published by 947 + the Free Software Foundation; either version 2 of the License, 948 + or (at your option) any later version. 949 + 950 + LibGTop is distributed in the hope that it will be useful, but WITHOUT 951 + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 952 + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 953 + for more details. 954 + 955 + You should have received a copy of the GNU General Public License 956 + along with LibGTop; see the file COPYING. If not, write to the 957 + Free Software Foundation, Inc., 59 Temple Place - Suite 330, 958 + Boston, MA 02111-1307, USA. 959 +*/ 960 + 961 +#include <config.h> 962 +#include <glibtop/procaffinity.h> 963 +#include <glibtop/error.h> 964 + 965 +#include <glibtop_private.h> 966 + 967 +#include <sys/param.h> 968 + 969 +void 970 +_glibtop_init_proc_affinity_s(glibtop *server) 971 +{ 972 +/* 973 + server->sysdeps.proc_affinity = 974 + (1 << GLIBTOP_PROC_AFFINITY_NUMBER) | 975 + (1 << GLIBTOP_PROC_AFFINITY_ALL); 976 +*/ 977 +} 978 + 979 + 980 +guint16 * 981 +glibtop_get_proc_affinity_s(glibtop *server, glibtop_proc_affinity *buf, pid_t pid) 982 +{ 983 +/* 984 +#if __FreeBSD_version > 800024 985 + id_t id; 986 + cpulevel_t level; 987 + cpuwhich_t which; 988 + cpuset_t mask; 989 + size_t i; 990 + GArray* cpus; 991 + 992 + memset(buf, 0, sizeof *buf); 993 + 994 + which = CPU_WHICH_PID; 995 + level = CPU_LEVEL_WHICH; 996 + id = pid; 997 + 998 + if (cpuset_getaffinity(level, which, id, sizeof(mask), &mask) != 0) { 999 + glibtop_error_r(server, "cpuset_getaffinity failed"); 1000 + return NULL; 1001 + } 1002 + 1003 + cpus = g_array_new(FALSE, FALSE, sizeof(guint16)); 1004 + 1005 + for (i = 0; i < MIN(CPU_SETSIZE, (size_t)(server->ncpu + 1)); i++) { 1006 + if (CPU_ISSET(i, &mask)) { 1007 + guint16 n = i; 1008 + g_array_append_val(cpus, n); 1009 + } 1010 + } 1011 + 1012 + buf->number = cpus->len; 1013 + buf->all = (cpus->len == (size_t)(server->ncpu + 1)); 1014 + buf->flags = (1 << GLIBTOP_PROC_AFFINITY_NUMBER) 1015 + | (1 << GLIBTOP_PROC_AFFINITY_ALL); 1016 + 1017 + return (guint16*) g_array_free(cpus, FALSE); 1018 +#else 1019 + memset(buf, 0, sizeof *buf); 1020 + 1021 + return NULL; 1022 +#endif 1023 +*/ 1024 +} 1025 + 1026 diff -urN libgtop-2.25.91/sysdeps/solaris/procmap.c ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/procmap.c 1027 --- libgtop-2.25.91/sysdeps/solaris/procmap.c 2008-05-23 22:13:24.000000000 +0000 1028 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/procmap.c 2009-02-25 17:16:38.061314000 +0000 1029 @@ -54,9 +54,16 @@ 1030 glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid) 1031 { 1032 int fd, i, nmaps, pr_err, heap; 1033 + 1034 + char filename [BUFSIZ]; 1035 + /* use flags as a check condition, if it is 1, check, or, not check... zhua */ 1036 + int check = buf->flags; 1037 + /* set flags back to 0 */ 1038 + buf->flags = 0; 1039 + 1040 #if GLIBTOP_SOLARIS_RELEASE >= 50600 1041 prxmap_t *maps; 1042 - struct ps_prochandle *Pr = NULL; 1043 +// struct ps_prochandle *Pr = NULL; 1044 #else 1045 prmap_t *maps; 1046 #endif 1047 @@ -123,16 +130,44 @@ 1048 buf->total = nmaps * sizeof(glibtop_map_entry); 1049 entry = g_malloc0(buf->total); 1050 1051 -#if GLIBTOP_SOLARIS_RELEASE >= 50600 1052 +//#if GLIBTOP_SOLARIS_RELEASE >= 50600 1053 1054 - if(server->machine.objname && server->machine.pgrab && 1055 - server->machine.pfree) 1056 - Pr = (server->machine.pgrab)(pid, 1, &pr_err); 1057 -#endif 1058 +// if(server->machine.objname && server->machine.pgrab && 1059 +// server->machine.pfree) 1060 +// Pr = (server->machine.pgrab)(pid, 1, &pr_err); 1061 +//#endif 1062 for(heap = 0,i = 0; i < nmaps; ++i) 1063 { 1064 int len; 1065 1066 + /* take a check to see if we need all information, if not, just get what we need.. 1067 + Also please see comments in get_process_memory_writable() of gnome-system-monitor zhua */ 1068 + if (check == 1) 1069 + { 1070 + if(maps[i].pr_mflags & MA_WRITE){ 1071 + entry[i].perm |= GLIBTOP_MAP_PERM_WRITE; 1072 + entry[i].size = maps[i].pr_size; 1073 + } 1074 + if(maps[i].pr_mflags & MA_SHARED){ 1075 + entry[i].perm |= GLIBTOP_MAP_PERM_SHARED; 1076 + /* here use shared_clean to store Shared Memory */ 1077 + entry[i].shared_clean = maps[i].pr_size; 1078 + } 1079 + } 1080 + else 1081 + if (check == 2) 1082 + { 1083 + if(maps[i].pr_mflags & MA_SHARED){ 1084 + entry[i].perm |= GLIBTOP_MAP_PERM_SHARED; 1085 + /* here use shared_clean to store Shared Memory */ 1086 + entry[i].shared_clean = maps[i].pr_size; 1087 + } 1088 + } 1089 + else { 1090 + 1091 + int len, rv; 1092 + 1093 + 1094 entry[i].start = maps[i].pr_vaddr; 1095 entry[i].end = maps[i].pr_vaddr + maps[i].pr_size; 1096 1097 @@ -177,25 +212,40 @@ 1098 entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME); 1099 } 1100 else 1101 - if(Pr) 1102 - { 1103 - server->machine.objname(Pr, maps[i].pr_vaddr, buffer, 1104 - BUFSIZ); 1105 - if((len = resolvepath(buffer, entry[i].filename, 1106 - GLIBTOP_MAP_FILENAME_LEN)) > 0) 1107 - { 1108 - entry[i].filename[len] = 0; 1109 - entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME); 1110 - } 1111 - } 1112 -#endif 1113 - } 1114 - 1115 -#if GLIBTOP_SOLARIS_RELEASE >= 50600 1116 - 1117 - if(Pr) 1118 - server->machine.pfree(Pr); 1119 -#endif 1120 +// if(Pr) 1121 +// { 1122 +// server->machine.objname(Pr, maps[i].pr_vaddr, buffer, 1123 +// BUFSIZ); 1124 +// if((len = resolvepath(buffer, entry[i].filename, 1125 +// GLIBTOP_MAP_FILENAME_LEN)) > 0) 1126 +// { 1127 +// entry[i].filename[len] = 0; 1128 +// entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME); 1129 +// } 1130 +// } 1131 + { 1132 + g_strlcpy(buffer, maps[i].pr_mapname, sizeof buffer); 1133 + /* from /path get file name */ 1134 + g_snprintf(filename, sizeof filename, "/proc/%d/path/%s", 1135 + pid, buffer); 1136 + 1137 + rv = readlink(filename, entry[i].filename, sizeof(entry[i].filename) - 1); 1138 + /* read object, if have not, set it as NULL */ 1139 + if(rv < 0) 1140 + rv = 0; 1141 + entry[i].filename[rv] = '\0'; 1142 + /* now set the flags */ 1143 + entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME); 1144 + } 1145 +#endif 1146 + } 1147 + } 1148 + 1149 +//#if GLIBTOP_SOLARIS_RELEASE >= 50600 1150 + 1151 +// if(Pr) 1152 +// server->machine.pfree(Pr); 1153 +//#endif 1154 buf->flags = _glibtop_sysdeps_proc_map; 1155 s_close(fd); 1156 return entry; 1157 diff -urN libgtop-2.25.91/sysdeps/solaris/procmem.c ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/procmem.c 1158 --- libgtop-2.25.91/sysdeps/solaris/procmem.c 2008-05-23 22:13:24.000000000 +0000 1159 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/procmem.c 2009-02-25 17:16:38.061600000 +0000 1160 @@ -22,12 +22,14 @@ 1161 #include <config.h> 1162 #include <glibtop.h> 1163 #include <glibtop/procmem.h> 1164 +#include <glibtop/procmap.h> 1165 1166 #include "glibtop_private.h" 1167 1168 static const unsigned long _glibtop_sysdeps_proc_mem = 1169 (1L << GLIBTOP_PROC_MEM_SIZE) + (1L << GLIBTOP_PROC_MEM_VSIZE) + 1170 -(1L << GLIBTOP_PROC_MEM_RESIDENT) + (1L << GLIBTOP_PROC_MEM_RSS); 1171 +(1L << GLIBTOP_PROC_MEM_RESIDENT) + (1L << GLIBTOP_PROC_MEM_RSS) + 1172 +(1L << GLIBTOP_PROC_MEM_SHARE); 1173 1174 /* Init function. */ 1175 1176 @@ -61,5 +63,31 @@ 1177 buf->size = buf->vsize = psinfo.pr_size << pagesize << 10; 1178 buf->resident = buf->rss = psinfo.pr_rssize << pagesize << 10; 1179 #endif 1180 +/* get Shared Memory */ 1181 + glibtop_proc_map mapbuf; 1182 + glibtop_map_entry *maps; 1183 + unsigned i; 1184 + buf->share = 0; 1185 + 1186 + /* we have to optimize the performance of libgtop, because update the information will occupy too much cpu. 1187 + 1188 + here I would like to make a little update:set glibtop_proc_map.flags=1,so as to let glibtop_get_proc_map_s() 1189 + only return the ones this function need: memwritable 1190 + 1191 + we do the check in glibtop_get_proc_map_s(), don't run the others part which don't need by this function, 1192 + I think this will accelerate the transaction lots, 1193 + Also this will not affect the existing codes, because when nobody set glibtop_proc_map.flags, 1194 + glibtop_get_proc_map() will return all as before. zhua 1195 + */ 1196 + mapbuf.flags = 2; 1197 + 1198 + maps = glibtop_get_proc_map_s(server, &mapbuf, pid); 1199 + 1200 + for (i = 0; i < mapbuf.number; ++i) { 1201 + if (maps[i].perm & GLIBTOP_MAP_PERM_SHARED) 1202 + buf->share += maps[i].shared_clean; 1203 + } 1204 + g_free(maps); 1205 + 1206 buf->flags = _glibtop_sysdeps_proc_mem; 1207 } 1208 diff -urN libgtop-2.25.91/sysdeps/solaris/procstate.c ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/procstate.c 1209 --- libgtop-2.25.91/sysdeps/solaris/procstate.c 2008-05-23 22:13:24.000000000 +0000 1210 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/procstate.c 2009-02-25 17:16:38.062411000 +0000 1211 @@ -62,6 +62,26 @@ 1212 buf->gid = psinfo.pr_egid; 1213 buf->ruid = psinfo.pr_uid; 1214 buf->rgid = psinfo.pr_gid; 1215 + /* zhua: get some value here, so that we don't need run open/pread/close psinfo later, 1216 + and can delete some other call for psinfo open/pread/close. it will save lots of time*/ 1217 +#ifdef HAVE_PROCFS_H 1218 + buf->nice = psinfo.pr_lwp.pr_nice - NZERO; 1219 +#else 1220 + buf->nice = psinfo.pr_nice - NZERO; 1221 +#endif 1222 + buf->start_time = psinfo.pr_start.tv_sec; 1223 + buf->ppid = psinfo.pr_ppid; 1224 + 1225 +#ifdef HAVE_PROCFS_H 1226 + buf->vsize = psinfo.pr_size << 10; 1227 + buf->resident= psinfo.pr_rssize << 10; 1228 + buf->load = (guint) psinfo.pr_lwp.pr_pctcpu * 100 / (guint) 0x8000; 1229 +#else 1230 + buf->vsize = psinfo.pr_size << pagesize << 10; 1231 + buf->resident = psinfo.pr_rssize << pagesize << 10; 1232 + buf->load = (guint) psinfo.pr_lwp.pr_pctcpu * 100 / (guint) 0x8000; 1233 +#endif 1234 + 1235 1236 #ifdef HAVE_PROCFS_H 1237 switch(psinfo.pr_lwp.pr_state) 1238 diff -urN libgtop-2.25.91/sysdeps/solaris/proctime.c ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/proctime.c 1239 --- libgtop-2.25.91/sysdeps/solaris/proctime.c 2008-05-23 22:13:24.000000000 +0000 1240 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/proctime.c 2009-02-25 17:16:38.062715000 +0000 1241 @@ -43,6 +43,11 @@ 1242 glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, 1243 pid_t pid) 1244 { 1245 +#ifdef HAVE_PROCFS_H 1246 + struct psinfo pinfo; 1247 +#else 1248 + struct prpsinfo pinfo; 1249 +#endif 1250 struct prusage prusage; 1251 GTimeVal time; 1252 1253 @@ -52,19 +57,27 @@ 1254 1255 if(pid) 1256 { 1257 + /* zhua remove this function call, because we can change to get start_time in 1258 + glibtop_get_proc_state(), it don't need open psinfo again here */ 1259 + 1260 + if (glibtop_get_proc_data_psinfo_s(server, &pinfo, pid)) 1261 + return; 1262 + buf->start_time = pinfo.pr_start.tv_sec; 1263 + 1264 if (glibtop_get_proc_data_usage_s (server, &prusage, pid)) 1265 return; 1266 1267 - g_get_current_time (&time); 1268 - /* prusage.pr_rtime.tv_sec is the during that the process existed */ 1269 - buf->start_time = time.tv_sec - prusage.pr_rtime.tv_sec; 1270 +// g_get_current_time (&time); 1271 +// /* prusage.pr_rtime.tv_sec is the during that the process existed */ 1272 + // buf->start_time = time.tv_sec - prusage.pr_rtime.tv_sec; 1273 1274 - buf->rtime = prusage.pr_rtime.tv_sec * 1E+6 + 1275 - prusage.pr_rtime.tv_nsec / 1E+3; 1276 +// buf->rtime = prusage.pr_rtime.tv_sec * 1E+6 + 1277 +// prusage.pr_rtime.tv_nsec / 1E+3; 1278 buf->utime = prusage.pr_utime.tv_sec * 1E+6 + 1279 prusage.pr_utime.tv_nsec / 1E+3; 1280 buf->stime = prusage.pr_stime.tv_sec * 1E+6 + 1281 prusage.pr_stime.tv_nsec / 1E+3; 1282 + buf->rtime = (buf->utime + buf->stime) / 10000; 1283 } 1284 1285 buf->flags = _glibtop_sysdeps_proc_time; 1286 diff -urN libgtop-2.25.91/sysdeps/solaris/procwd.c ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/procwd.c 1287 --- libgtop-2.25.91/sysdeps/solaris/procwd.c 1970-01-01 00:00:00.000000000 +0000 1288 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/procwd.c 2009-02-25 17:16:38.062977000 +0000 1289 @@ -0,0 +1,98 @@ 1290 +/* Copyright (C) 2007 Benot Dejean 1291 + This file is part of LibGTop 2. 1292 + 1293 + LibGTop is free software; you can redistribute it and/or modify it 1294 + under the terms of the GNU General Public License as published by 1295 + the Free Software Foundation; either version 2 of the License, 1296 + or (at your option) any later version. 1297 + 1298 + LibGTop is distributed in the hope that it will be useful, but WITHOUT 1299 + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1300 + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1301 + for more details. 1302 + 1303 + You should have received a copy of the GNU General Public License 1304 + along with LibGTop; see the file COPYING. If not, write to the 1305 + Free Software Foundation, Inc., 59 Temple Place - Suite 330, 1306 + Boston, MA 02111-1307, USA. 1307 +*/ 1308 + 1309 +#include <config.h> 1310 +#include <glibtop/procwd.h> 1311 +#include <glibtop/error.h> 1312 + 1313 +#include <glibtop_private.h> 1314 + 1315 +#include <unistd.h> 1316 +#include <dirent.h> 1317 +#include <sys/types.h> 1318 + 1319 + 1320 +void 1321 +_glibtop_init_proc_wd_s(glibtop *server) 1322 +{ 1323 + server->sysdeps.proc_wd = 1324 + (1 << GLIBTOP_PROC_WD_EXE) + 1325 + (1 << GLIBTOP_PROC_WD_ROOT) + 1326 + (1 << GLIBTOP_PROC_WD_NUMBER); 1327 + 1328 +} 1329 + 1330 +static gboolean is_in(GPtrArray *array, const char *str) 1331 +{ 1332 + guint i; 1333 + 1334 + for (i = 0; i != array->len; ++i) { 1335 + if (strcmp(g_ptr_array_index(array, i), str) == 0) 1336 + return TRUE; 1337 + } 1338 + 1339 + return FALSE; 1340 +} 1341 + 1342 + 1343 +char** 1344 +glibtop_get_proc_wd_s(glibtop *server, glibtop_proc_wd *buf, pid_t pid) 1345 +{ 1346 + GPtrArray *dirs; 1347 + char path[80]; 1348 + char dir[256]; 1349 + DIR *task; 1350 + 1351 + glibtop_init_s(&server, GLIBTOP_SYSDEPS_PROC_WD, 0); 1352 + 1353 + memset(buf, 0, sizeof(glibtop_proc_wd)); 1354 + 1355 + g_snprintf(path, sizeof path, "/proc/%u/root", pid); 1356 + if (safe_readlink(path, buf->root, sizeof buf->root)) 1357 + buf->flags |= (1 << GLIBTOP_PROC_WD_ROOT); 1358 + 1359 + g_snprintf(path, sizeof path, "/proc/%u/exe", pid); 1360 + if (safe_readlink(path, buf->exe, sizeof buf->exe)) 1361 + buf->flags |= (1 << GLIBTOP_PROC_WD_EXE); 1362 + 1363 + dirs = g_ptr_array_sized_new(2); 1364 + 1365 + g_snprintf(path, sizeof path, "/proc/%u/cwd", pid); 1366 + if (safe_readlink(path, dir, sizeof dir)) 1367 + g_ptr_array_add(dirs, g_strdup(dir)); 1368 + 1369 + g_snprintf(path, sizeof path, "/proc/%u/task", pid); 1370 + if ((task = opendir(path)) != NULL) { 1371 + struct dirent *sub; 1372 + while ((sub = readdir(task)) != NULL) { 1373 + g_snprintf(path, sizeof path, "/proc/%u/task/%s/cwd", pid, sub->d_name); 1374 + if (safe_readlink(path, dir, sizeof dir) && !is_in(dirs, dir)) 1375 + g_ptr_array_add(dirs, g_strdup(dir)); 1376 + } 1377 + closedir(task); 1378 + } 1379 + 1380 + buf->number = dirs->len; 1381 + buf->flags |= (1 << GLIBTOP_PROC_WD_NUMBER); 1382 + 1383 + g_ptr_array_add(dirs, NULL); 1384 + 1385 + return (char**) g_ptr_array_free(dirs, FALSE); 1386 +} 1387 + 1388 diff -urN libgtop-2.25.91/sysdeps/solaris/sem_limits.c ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/sem_limits.c 1389 --- libgtop-2.25.91/sysdeps/solaris/sem_limits.c 2008-05-23 22:13:24.000000000 +0000 1390 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/sem_limits.c 2009-02-25 17:16:38.063802000 +0000 1391 @@ -39,14 +39,22 @@ 1392 (1L << GLIBTOP_IPC_SEMUSZ) + (1L << GLIBTOP_IPC_SEMVMX) + 1393 (1L << GLIBTOP_IPC_SEMAEM); 1394 #else 1395 -static const unsigned long _glibtop_sysdeps_sem_limits = 0; 1396 +static const unsigned long _glibtop_sysdeps_sem_limits = 1397 +(1L << GLIBTOP_IPC_SEMMNI) + 1398 +(1L << GLIBTOP_IPC_SEMMSL) + 1399 +(1L << GLIBTOP_IPC_SEMOPM); 1400 #endif 1401 1402 1403 /* Init function. */ 1404 1405 +#if GLIBTOP_SUID_SEM_LIMITS 1406 void 1407 _glibtop_init_sem_limits_p (glibtop *server) 1408 +#else 1409 +void 1410 +_glibtop_init_sem_limits_s (glibtop *server) 1411 +#endif 1412 { 1413 #if GLIBTOP_SOLARIS_RELEASE < 51000 1414 1415 @@ -61,8 +69,13 @@ 1416 1417 /* Provides information about sysv sem limits. */ 1418 1419 +#if GLIBTOP_SUID_SEM_LIMITS 1420 void 1421 glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf) 1422 +#else 1423 +void 1424 +glibtop_get_sem_limits_s (glibtop *server, glibtop_sem_limits *buf) 1425 +#endif 1426 { 1427 #if GLIBTOP_SOLARIS_RELEASE < 51000 1428 kvm_t *kd = server->machine.kd; 1429 diff -urN libgtop-2.25.91/sysdeps/solaris/shm_limits.c ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/shm_limits.c 1430 --- libgtop-2.25.91/sysdeps/solaris/shm_limits.c 2008-05-23 22:13:24.000000000 +0000 1431 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/shm_limits.c 2009-02-25 17:16:38.064069000 +0000 1432 @@ -30,7 +30,9 @@ 1433 static const struct nlist nlst[] = { {"glibtop_shm_limits"}, {NULL} }; 1434 1435 #if GLIBTOP_SOLARIS_RELEASE >=51000 1436 -static const unsigned long _glibtop_sysdeps_shm_limits = 0; 1437 +static const unsigned long _glibtop_sysdeps_shm_limits = 1438 +(1L << GLIBTOP_IPC_SHMMAX) + 1439 +(1L << GLIBTOP_IPC_SHMMIN); 1440 #else 1441 # if GLIBTOP_SOLARIS_RELEASE < 50900 1442 static const unsigned long _glibtop_sysdeps_shm_limits = 1443 @@ -45,8 +47,13 @@ 1444 1445 /* Init function. */ 1446 1447 +#if GLIBTOP_SUID_SHM_LIMITS 1448 void 1449 _glibtop_init_shm_limits_p (glibtop *server) 1450 +#else 1451 +void 1452 +_glibtop_init_shm_limits_s (glibtop *server) 1453 +#endif 1454 { 1455 #if GLIBTOP_SOLARIS_RELEASE < 51000 1456 1457 @@ -61,8 +68,13 @@ 1458 1459 /* Provides information about sysv ipc limits. */ 1460 1461 +#if GLIBTOP_SUID_SHM_LIMITS 1462 void 1463 glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf) 1464 +#else 1465 +void 1466 +glibtop_get_shm_limits_s (glibtop *server, glibtop_shm_limits *buf) 1467 +#endif 1468 { 1469 #if GLIBTOP_SOLARIS_RELEASE < 51000 1470 1471 diff -urN libgtop-2.25.91/sysdeps/solaris/siglist.c ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/siglist.c 1472 --- libgtop-2.25.91/sysdeps/solaris/siglist.c 2008-05-23 22:13:24.000000000 +0000 1473 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/siglist.c 2009-02-25 17:16:38.064867000 +0000 1474 @@ -61,6 +61,7 @@ 1475 { 35, "SIGTHAW", "Checkpoint Thaw" }, 1476 { 36, "SIGCANCEL","Thread Cancelation" }, 1477 { 37, "SIGLOST", "Resource Lost" }, 1478 +#if GLIBTOP_SOLARIS_RELEASE < 50900 /* S8 */ 1479 { 38, "SIGRTMIN","First Realtime Signal" }, 1480 { 39, "SIGRTMIN+1", "Second Realtime Signal" }, 1481 { 40, "SIGRTMIN+2", "Third Realtime Signal" }, 1482 @@ -69,5 +70,30 @@ 1483 { 43, "SIGRTMAX-2", "Third Last Realtime Signal" }, 1484 { 44, "SIGRTMAX-1", "Second Last Realtime Signal" }, 1485 { 45, "SIGRTMAX", "Last Realtime Signal" }, 1486 +#endif 1487 +#if GLIBTOP_SOLARIS_RELEASE >= 50900 1488 + { 38, "SIGXRES","Resource Control Exceeded" }, 1489 +#if GLIBTOP_SOLARIS_RELEASE <51000 /* signal here existed in s9 */ 1490 + { 39, "SIGRTMIN","First Realtime Signal" }, 1491 + { 40, "SIGRTMIN+1", "Second Realtime Signal" }, 1492 + { 41, "SIGRTMIN+2", "Third Realtime Signal" }, 1493 + { 42, "SIGRTMIN+3", "Fourth Realtime Signal" }, 1494 + { 43, "SIGRTMAX-3", "Fourth Last Realtime Signal" }, 1495 + { 44, "SIGRTMAX-2", "Third Last Realtime Signal" }, 1496 + { 45, "SIGRTMAX-1", "Second Last Realtime Signal" }, 1497 + { 46, "SIGRTMAX", "Last Realtime Signal" }, 1498 +#else /* signal here existed in s10 and s11 */ 1499 + { 39, "SIGJVM1","Reserved signal for Java Virtual Machine" }, 1500 + { 40, "SIGJVM1","Reserved signal for Java Virtual Machine" }, 1501 + { 41, "SIGRTMIN","First Realtime Signal" }, 1502 + { 42, "SIGRTMIN+1", "Second Realtime Signal" }, 1503 + { 43, "SIGRTMIN+2", "Third Realtime Signal" }, 1504 + { 44, "SIGRTMIN+3", "Fourth Realtime Signal" }, 1505 + { 45, "SIGRTMAX-3", "Fourth Last Realtime Signal" }, 1506 + { 46, "SIGRTMAX-2", "Third Last Realtime Signal" }, 1507 + { 47, "SIGRTMAX-1", "Second Last Realtime Signal" }, 1508 + { 48, "SIGRTMAX", "Last Realtime Signal" }, 1509 +#endif 1510 +#endif 1511 { 0, NULL, NULL } 1512 }; 1513 diff -urN libgtop-2.25.91/sysdeps/solaris/sysinfo.c ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/sysinfo.c 1514 --- libgtop-2.25.91/sysdeps/solaris/sysinfo.c 1970-01-01 00:00:00.000000000 +0000 1515 +++ ../SUNWlibgtop-2.25.91.hacked/libgtop-2.25.91/sysdeps/solaris/sysinfo.c 2009-02-25 17:16:38.065095000 +0000 1516 @@ -0,0 +1,48 @@ 1517 +/* $Id: sysinfo.c,v 1.22 2004/11/28 01:32:55 bdejean Exp $ */ 1518 + 1519 +/* Copyright (C) 1998-99 Martin Baulig 1520 + This file is part of LibGTop 1.0. 1521 + 1522 + Contributed by Martin Baulig <martin (a] home-of-linux.org>, April 1998. 1523 + 1524 + LibGTop is free software; you can redistribute it and/or modify it 1525 + under the terms of the GNU General Public License as published by 1526 + the Free Software Foundation; either version 2 of the License, 1527 + or (at your option) any later version. 1528 + 1529 + LibGTop is distributed in the hope that it will be useful, but WITHOUT 1530 + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1531 + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1532 + for more details. 1533 + 1534 + You should have received a copy of the GNU General Public License 1535 + along with LibGTop; see the file COPYING. If not, write to the 1536 + Free Software Foundation, Inc., 59 Temple Place - Suite 330, 1537 + Boston, MA 02111-1307, USA. 1538 +*/ 1539 + 1540 +#include <config.h> 1541 +#include <glibtop/error.h> 1542 +#include <glibtop/cpu.h> 1543 +#include <glibtop/sysinfo.h> 1544 + 1545 +#include "glibtop_private.h" 1546 + 1547 + 1548 +static const unsigned long _glibtop_sysdeps_sysinfo = 1549 +(1L << GLIBTOP_SYSINFO_CPUINFO); 1550 + 1551 +static glibtop_sysinfo sysinfo = { .flags = 0 }; 1552 + 1553 +static void 1554 +init_sysinfo (glibtop *server) 1555 +{ 1556 + 1557 +} 1558 + 1559 +const glibtop_sysinfo * 1560 +glibtop_get_sysinfo_s (glibtop *server) 1561 +{ 1562 + init_sysinfo (server); 1563 + return &sysinfo; 1564 +} 1565