1 diff -Nrup libgtop-2.23.90.orig/include/glibtop/procstate.h libgtop-2.23.90.mod/include/glibtop/procstate.h 2 --- libgtop-2.23.90.orig/include/glibtop/procstate.h 2008-05-24 06:13:20.000000000 +0800 3 +++ libgtop-2.23.90.mod/include/glibtop/procstate.h 2008-08-20 10:26:31.847117000 +0800 4 @@ -69,6 +69,13 @@ struct _glibtop_proc_state 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 -Nrup libgtop-2.23.90.orig/procmap.c libgtop-2.23.90.mod/procmap.c 19 --- libgtop-2.23.90.orig/procmap.c 1970-01-01 08:00:00.000000000 +0800 20 +++ libgtop-2.23.90.mod/procmap.c 2008-08-20 19:05:25.738052000 +0800 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 -Nrup libgtop-2.23.90.orig/sysdeps/common/mountlist.c libgtop-2.23.90.mod/sysdeps/common/mountlist.c 275 --- libgtop-2.23.90.orig/sysdeps/common/mountlist.c 2008-05-24 06:13:22.000000000 +0800 276 +++ libgtop-2.23.90.mod/sysdeps/common/mountlist.c 2008-08-20 11:03:42.561589000 +0800 277 @@ -591,6 +591,17 @@ glibtop_get_mountlist_s (glibtop *server 278 279 for (cur = &entries[0]; cur != NULL; cur = next) { 280 281 + /*zhua: delete these 2 type of fs: objfs,ctfs */ 282 + if (!strcmp(cur->me_type, "objfs") || !strcmp(cur->me_type,"ctfs")){ 283 + /* free current mount_entry and move to the next */ 284 + next = cur->me_next; 285 + g_free(cur->me_devname); 286 + g_free(cur->me_mountdir); 287 + g_free(cur->me_type); 288 + g_free(cur); 289 + continue; 290 + } 291 + 292 if(all_fs || !ignore_mount_entry(cur)) { 293 /* add a new glibtop_mountentry */ 294 glibtop_mountentry e; 295 diff -Nrup libgtop-2.23.90.orig/sysdeps/solaris/Makefile.am libgtop-2.23.90.mod/sysdeps/solaris/Makefile.am 296 --- libgtop-2.23.90.orig/sysdeps/solaris/Makefile.am 2008-05-24 06:13:24.000000000 +0800 297 +++ libgtop-2.23.90.mod/sysdeps/solaris/Makefile.am 2008-08-20 21:07:30.398511000 +0800 298 @@ -9,6 +9,7 @@ libgtop_sysdeps_2_0_la_SOURCES = open.c 299 proctime.c procmem.c procsignal.c \ 300 prockernel.c procsegment.c procargs.c \ 301 procopenfiles.c \ 302 + sysinfo.c procwd.c glibtop_private.c procaffinity.c \ 303 procmap.c netload.c ppp.c procdata.c netlist.c 304 305 libgtop_sysdeps_2_0_la_LDFLAGS = $(LT_VERSION_INFO) 306 diff -Nrup libgtop-2.23.90.orig/sysdeps/solaris/cpu.c libgtop-2.23.90.mod/sysdeps/solaris/cpu.c 307 --- libgtop-2.23.90.orig/sysdeps/solaris/cpu.c 2008-05-24 06:13:24.000000000 +0800 308 +++ libgtop-2.23.90.mod/sysdeps/solaris/cpu.c 2008-08-20 11:06:54.437929000 +0800 309 @@ -34,6 +34,7 @@ static const unsigned long _glibtop_sysd 310 311 static const unsigned long _glibtop_sysdeps_cpu_all = 312 (1L << GLIBTOP_CPU_TOTAL) + (1L << GLIBTOP_CPU_USER) + 313 +(1L << GLIBTOP_CPU_NICE) + /* this value is needed by multiload */ 314 (1L << GLIBTOP_CPU_SYS) + (1L << GLIBTOP_CPU_IDLE) + 315 (1L << GLIBTOP_XCPU_TOTAL) + (1L << GLIBTOP_XCPU_USER) + 316 (1L << GLIBTOP_XCPU_SYS) + (1L << GLIBTOP_XCPU_IDLE) + 317 diff -Nrup libgtop-2.23.90.orig/sysdeps/solaris/glibtop_machine.h libgtop-2.23.90.mod/sysdeps/solaris/glibtop_machine.h 318 --- libgtop-2.23.90.orig/sysdeps/solaris/glibtop_machine.h 2008-05-24 06:13:24.000000000 +0800 319 +++ libgtop-2.23.90.mod/sysdeps/solaris/glibtop_machine.h 2008-08-20 11:48:46.031067000 +0800 320 @@ -61,14 +61,14 @@ struct _glibtop_machine 321 int pagesize; /* in bits to shift, ie. 2^pagesize gives Kb */ 322 int ticks; /* clock ticks, as returned by sysconf() */ 323 unsigned long long boot; /* boot time, although it's ui32 in kstat */ 324 - void *libproc; /* libproc handle */ 325 -#if GLIBTOP_SOLARIS_RELEASE >= 50600 326 - void (*objname)(void *, uintptr_t, const char *, size_t); 327 - struct ps_prochandle *(*pgrab)(pid_t, int, int *); 328 - void (*pfree)(void *); 329 -#else 330 +// void *libproc; /* libproc handle */ 331 +//#if GLIBTOP_SOLARIS_RELEASE >= 50600 332 +// void (*objname)(void *, uintptr_t, const char *, size_t); 333 +// struct ps_prochandle *(*pgrab)(pid_t, int, int *); 334 +// void (*pfree)(void *); 335 +//#else 336 void *filler[3]; 337 -#endif 338 +//#endif 339 }; 340 341 G_END_DECLS 342 diff -Nrup libgtop-2.23.90.orig/sysdeps/solaris/glibtop_private.c libgtop-2.23.90.mod/sysdeps/solaris/glibtop_private.c 343 --- libgtop-2.23.90.orig/sysdeps/solaris/glibtop_private.c 1970-01-01 08:00:00.000000000 +0800 344 +++ libgtop-2.23.90.mod/sysdeps/solaris/glibtop_private.c 2008-08-20 11:50:10.409057000 +0800 345 @@ -0,0 +1,203 @@ 346 +#include <config.h> 347 +#include <glibtop.h> 348 +#include <glibtop/error.h> 349 + 350 +#include "glibtop_private.h" 351 + 352 +#include <glib.h> 353 + 354 +#include <string.h> 355 +#include <stdlib.h> 356 +#include <stdarg.h> 357 + 358 +#include <fcntl.h> 359 +#include <unistd.h> 360 + 361 +#if 0 362 +unsigned long long 363 +get_scaled(const char *buffer, const char *key) 364 +{ 365 + const char *ptr; 366 + char *next; 367 + unsigned long long value = 0; 368 + 369 + if (G_LIKELY((ptr = strstr(buffer, key)))) 370 + { 371 + ptr += strlen(key); 372 + value = strtoull(ptr, &next, 0); 373 + 374 + for ( ; *next; ++next) { 375 + if (*next == 'k') { 376 + value *= 1024; 377 + break; 378 + } else if (*next == 'M') { 379 + value *= 1024 * 1024; 380 + break; 381 + } 382 + } 383 + } else 384 + g_warning("Could not read key '%s' in buffer '%s'", 385 + key, buffer); 386 + 387 + return value; 388 +} 389 + 390 + 391 +char * 392 +skip_token (const char *p) 393 +{ 394 + p = next_token(p); 395 + while (*p && !isspace(*p)) p++; 396 + p = next_token(p); 397 + return (char *)p; 398 +} 399 + 400 + 401 +/* 402 + * Read functions 403 + */ 404 +enum TRY_FILE_TO_BUFFER 405 +{ 406 + TRY_FILE_TO_BUFFER_OK = 0, 407 + TRY_FILE_TO_BUFFER_OPEN = -1, 408 + TRY_FILE_TO_BUFFER_READ = -2 409 +}; 410 + 411 +int try_file_to_buffer(char *buffer, const char *format, ...) 412 +{ 413 + char path[4096]; 414 + int fd; 415 + ssize_t len; 416 + va_list pa; 417 + 418 + va_start(pa, format); 419 + 420 + /* C99 also provides vsnprintf */ 421 + g_vsnprintf(path, sizeof path, format, pa); 422 + 423 + va_end(pa); 424 + 425 + buffer [0] = '\0'; 426 + 427 + if((fd = open (path, O_RDONLY)) < 0) 428 + return TRY_FILE_TO_BUFFER_OPEN; 429 + 430 + len = read (fd, buffer, BUFSIZ-1); 431 + close (fd); 432 + 433 + if (len < 0) 434 + return TRY_FILE_TO_BUFFER_READ; 435 + 436 + buffer [len] = '\0'; 437 + 438 + return TRY_FILE_TO_BUFFER_OK; 439 +} 440 + 441 + 442 +void 443 +file_to_buffer(glibtop *server, char *buffer, const char *filename) 444 +{ 445 + switch(try_file_to_buffer(buffer, filename)) 446 + { 447 + case TRY_FILE_TO_BUFFER_OPEN: 448 + glibtop_error_io_r (server, "open (%s)", filename); 449 + case TRY_FILE_TO_BUFFER_READ: 450 + glibtop_error_io_r (server, "read (%s)", filename); 451 + } 452 +} 453 + 454 + 455 + 456 + 457 +static unsigned long 458 +read_boot_time(glibtop *server) 459 +{ 460 + char buffer[BUFSIZ]; 461 + char *btime; 462 + 463 + file_to_buffer(server, buffer, "/proc/stat"); 464 + 465 + btime = strstr(buffer, "btime"); 466 + 467 + if (!btime) { 468 + glibtop_warn_io_r(server, "cannot find btime in /proc/stat"); 469 + return 0UL; 470 + } 471 + 472 + btime = skip_token(btime); 473 + return strtoul(btime, NULL, 10); 474 +} 475 + 476 + 477 + 478 +unsigned long 479 +get_boot_time(glibtop *server) 480 +{ 481 + static unsigned long boot_time = 0UL; 482 + 483 + if(G_UNLIKELY(!boot_time)) 484 + { 485 + boot_time = read_boot_time(server); 486 + } 487 + 488 + return boot_time; 489 +} 490 + 491 + 492 +size_t 493 +get_page_size(void) 494 +{ 495 + static size_t pagesize = 0; 496 + 497 + if(G_UNLIKELY(!pagesize)) 498 + { 499 + pagesize = getpagesize(); 500 + } 501 + 502 + return pagesize; 503 +} 504 + 505 + 506 + 507 +gboolean 508 +check_cpu_line(glibtop *server, const char *line, unsigned i) 509 +{ 510 + char start[10]; 511 + 512 + g_snprintf(start, sizeof start, "cpu%u", i); 513 + 514 + return g_str_has_prefix(line, start); 515 +} 516 + 517 + 518 + 519 +gboolean 520 +has_sysfs(void) 521 +{ 522 + static gboolean init; 523 + static gboolean sysfs; 524 + 525 + if (G_UNLIKELY(!init)) { 526 + sysfs = g_file_test("/sys", G_FILE_TEST_IS_DIR); 527 + init = TRUE; 528 + } 529 + 530 + return sysfs; 531 +} 532 +#endif 533 + 534 + 535 +gboolean safe_readlink(const char *path, char *buf, size_t bufsiz) 536 +{ 537 + ssize_t ret; 538 + 539 + ret = readlink(path, buf, bufsiz - 1); 540 + 541 + if (ret == -1) { 542 + g_warning("Could not read link %s : %s", path, strerror(errno)); 543 + return FALSE; 544 + } 545 + 546 + buf[ret] = '\0'; 547 + return TRUE; 548 +} 549 diff -Nrup libgtop-2.23.90.orig/sysdeps/solaris/glibtop_private.h libgtop-2.23.90.mod/sysdeps/solaris/glibtop_private.h 550 --- libgtop-2.23.90.orig/sysdeps/solaris/glibtop_private.h 2008-05-24 06:13:24.000000000 +0800 551 +++ libgtop-2.23.90.mod/sysdeps/solaris/glibtop_private.h 2008-08-20 11:50:43.153956000 +0800 552 @@ -60,6 +60,8 @@ int glibtop_get_proc_credentials_s(glibt 553 /* Reread kstat chains */ 554 void glibtop_get_kstats(glibtop *); 555 556 +gboolean safe_readlink(const char *path, char *buf, size_t bufsiz); 557 + 558 G_END_DECLS 559 560 #endif /* __GLIBTOP_PRIVATE_H__ */ 561 diff -Nrup libgtop-2.23.90.orig/sysdeps/solaris/glibtop_server.h libgtop-2.23.90.mod/sysdeps/solaris/glibtop_server.h 562 --- libgtop-2.23.90.orig/sysdeps/solaris/glibtop_server.h 2008-05-24 06:13:24.000000000 +0800 563 +++ libgtop-2.23.90.mod/sysdeps/solaris/glibtop_server.h 2008-08-20 20:27:29.536004000 +0800 564 @@ -29,9 +29,15 @@ G_BEGIN_DECLS 565 #define GLIBTOP_SUID_SWAP 0 566 #define GLIBTOP_SUID_UPTIME 0 567 #define GLIBTOP_SUID_LOADAVG 0 568 +#if GLIBTOP_SOLARIS_RELEASE < 51000 569 #define GLIBTOP_SUID_SHM_LIMITS (1L << GLIBTOP_SYSDEPS_SHM_LIMITS) 570 #define GLIBTOP_SUID_MSG_LIMITS (1L << GLIBTOP_SYSDEPS_MSG_LIMITS) 571 #define GLIBTOP_SUID_SEM_LIMITS (1L << GLIBTOP_SYSDEPS_SEM_LIMITS) 572 +#else 573 +#define GLIBTOP_SUID_SHM_LIMITS 0 574 +#define GLIBTOP_SUID_MSG_LIMITS 0 575 +#define GLIBTOP_SUID_SEM_LIMITS 0 576 +#endif 577 #define GLIBTOP_SUID_PROCLIST 0 578 #define GLIBTOP_SUID_PROC_STATE 0 579 #define GLIBTOP_SUID_PROC_UID 0 580 @@ -44,7 +50,10 @@ G_BEGIN_DECLS 581 #define GLIBTOP_SUID_PROC_MAP 0 582 #define GLIBTOP_SUID_NETLOAD 0 583 #define GLIBTOP_SUID_NETLIST 0 584 +#define GLIBTOP_SUID_PROC_WD 0 585 #define GLIBTOP_SUID_PPP 0 586 +#define GLIBTOP_SUID_PROC_AFFINITY 0 587 + 588 589 G_END_DECLS 590 591 diff -Nrup libgtop-2.23.90.orig/sysdeps/solaris/msg_limits.c libgtop-2.23.90.mod/sysdeps/solaris/msg_limits.c 592 --- libgtop-2.23.90.orig/sysdeps/solaris/msg_limits.c 2008-05-24 06:13:24.000000000 +0800 593 +++ libgtop-2.23.90.mod/sysdeps/solaris/msg_limits.c 2008-08-20 11:54:47.408687000 +0800 594 @@ -37,14 +37,24 @@ static const unsigned long _glibtop_sysd 595 (1L << GLIBTOP_IPC_MSGMNB) + (1L << GLIBTOP_IPC_MSGMNI) + 596 (1L << GLIBTOP_IPC_MSGTQL); 597 #else 598 -static const unsigned long _glibtop_sysdeps_msg_limits = 0; 599 +static const unsigned long _glibtop_sysdeps_msg_limits = 600 +(1L << GLIBTOP_IPC_MSGMNB) + 601 +(1L << GLIBTOP_IPC_MSGMNI) + 602 +(1L << GLIBTOP_IPC_MSGMAX) + 603 +(1L << GLIBTOP_IPC_MSGPOOL) + 604 +(1L << GLIBTOP_IPC_MSGTQL); 605 #endif 606 607 608 /* Init function. */ 609 610 +#if GLIBTOP_SUID_MSG_LIMITS 611 void 612 _glibtop_init_msg_limits_p (glibtop *server) 613 +#else 614 +void 615 +_glibtop_init_msg_limits_s (glibtop *server) 616 +#endif 617 { 618 #if GLIBTOP_SOLARIS_RELEASE < 51000 619 620 @@ -59,8 +69,13 @@ _glibtop_init_msg_limits_p (glibtop *ser 621 622 /* Provides information about sysv ipc limits. */ 623 624 +#if GLIBTOP_SUID_MSG_LIMITS 625 void 626 glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf) 627 +#else 628 +void 629 +glibtop_get_msg_limits_s (glibtop *server, glibtop_msg_limits *buf) 630 +#endif 631 { 632 #if GLIBTOP_SOLARIS_RELEASE < 51000 633 634 diff -Nrup libgtop-2.23.90.orig/sysdeps/solaris/netload.c libgtop-2.23.90.mod/sysdeps/solaris/netload.c 635 --- libgtop-2.23.90.orig/sysdeps/solaris/netload.c 2008-05-24 06:13:24.000000000 +0800 636 +++ libgtop-2.23.90.mod/sysdeps/solaris/netload.c 2008-08-20 20:11:42.601468000 +0800 637 @@ -37,6 +37,17 @@ 638 639 #include <net/if.h> 640 641 +#ifdef HAVE_IFADDRS_H 642 +/* needed for IPV6 support */ 643 + 644 +#include <ifaddrs.h> 645 + 646 +#ifndef IN6_IS_ADDR_GLOBAL 647 +#define IN6_IS_ADDR_GLOBAL(a) \ 648 + (((((__const uint8_t *) (a))[0] & 0xff) == 0x3f \ 649 + || (((__const uint8_t *) (a))[0] & 0xff) == 0x20)) 650 +#endif 651 +#endif /* HAVE_IFADDRS_H */ 652 653 static const unsigned long _glibtop_sysdeps_netload = 654 (1L << GLIBTOP_NETLOAD_ERRORS_IN) + 655 @@ -89,6 +100,72 @@ _glibtop_init_netload_s (glibtop *server 656 _glibtop_sysdeps_netload_packets; 657 } 658 659 +#ifdef HAVE_IFADDRS_H 660 + 661 +static void get_ipv6(glibtop *server, glibtop_netload *buf, 662 + const char *interface) 663 +{ 664 +/* 665 + * remove this code, because they are not available at Solaris, but keep them here for reference. 666 + * in fact, the function will not be called at Solaris, because HAVE_IFADDRS_H don't def. 667 + * 668 +*/ 669 +#if 0 670 + struct ifaddrs *ifa0, *ifr6; 671 + 672 + if(getifaddrs (&ifa0) != 0) 673 + { 674 + glibtop_warn_r(server, "getifaddrs failed : %s", g_strerror(errno)); 675 + return; 676 + } 677 + 678 + for (ifr6 = ifa0; ifr6; ifr6 = ifr6->ifa_next) { 679 + if (strcmp (ifr6->ifa_name, interface) == 0 680 + && ifr6->ifa_addr != NULL 681 + && ifr6->ifa_addr->sa_family == AF_INET6) 682 + break; 683 + } 684 + 685 + if(!ifr6) goto free_ipv6; 686 + 687 + memcpy(buf->address6, 688 + &((struct sockaddr_in6 *) ifr6->ifa_addr)->sin6_addr, 689 + 16); 690 + 691 + memcpy(buf->prefix6, 692 + &((struct sockaddr_in6 *) ifr6->ifa_netmask)->sin6_addr, 693 + 16); 694 + 695 + 696 + if (IN6_IS_ADDR_LINKLOCAL (buf->address6)) 697 + buf->scope6 = GLIBTOP_IF_IN6_SCOPE_LINK; 698 + 699 + else if (IN6_IS_ADDR_SITELOCAL (buf->address6)) 700 + buf->scope6 = GLIBTOP_IF_IN6_SCOPE_SITE; 701 + 702 + else if (IN6_IS_ADDR_GLOBAL (buf->address6) 703 + || IN6_IS_ADDR_MC_ORGLOCAL (buf->address6) 704 + || IN6_IS_ADDR_V4COMPAT (buf->address6) 705 + || IN6_IS_ADDR_MULTICAST (buf->address6) 706 + || IN6_IS_ADDR_UNSPECIFIED (buf->address6) 707 + ) 708 + buf->scope6 = GLIBTOP_IF_IN6_SCOPE_GLOBAL; 709 + 710 + else if (IN6_IS_ADDR_LOOPBACK (buf->address6)) 711 + buf->scope6 = GLIBTOP_IF_IN6_SCOPE_HOST; 712 + 713 + else 714 + buf->scope6 = GLIBTOP_IF_IN6_SCOPE_UNKNOWN; 715 + 716 + buf->flags |= _glibtop_sysdeps_netload_6; 717 + 718 + free_ipv6: 719 + freeifaddrs(ifa0); 720 +#endif 721 +} 722 + 723 +#endif /* HAVE_IFADDRS_H */ 724 + 725 static int 726 solaris_stats(glibtop *server, 727 glibtop_netload *buf, 728 @@ -245,6 +322,13 @@ glibtop_get_netload_s (glibtop *server, 729 buf->subnet = ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr; 730 buf->flags |= (1L << GLIBTOP_NETLOAD_SUBNET); 731 } 732 + 733 +/* g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name); 734 + if (!ioctl (skfd, SIOCGIFHWADDR, &ifr)) { 735 + memcpy(buf->hwaddress, &ifr.ifr_hwaddr.sa_data, 8); 736 + buf->flags |= (1L << GLIBTOP_NETLOAD_HWADDRESS); 737 + }*/ 738 + 739 close (skfd); 740 } 741 742 @@ -254,4 +338,7 @@ glibtop_get_netload_s (glibtop *server, 743 744 solaris_stats(server, buf, interface); 745 746 +#ifdef HAVE_IFADDRS_H 747 + get_ipv6(server, buf, interface); 748 +#endif /* HAVE_IFADDRS_H */ 749 } 750 diff -Nrup libgtop-2.23.90.orig/sysdeps/solaris/open.c libgtop-2.23.90.mod/sysdeps/solaris/open.c 751 --- libgtop-2.23.90.orig/sysdeps/solaris/open.c 2008-05-24 06:13:24.000000000 +0800 752 +++ libgtop-2.23.90.mod/sysdeps/solaris/open.c 2008-08-20 18:55:17.944520000 +0800 753 @@ -209,34 +209,34 @@ glibtop_open_s (glibtop *server, const c 754 } 755 } 756 757 - /* Now let's have a bit of magic dust... */ 758 +// /* Now let's have a bit of magic dust... */ 759 760 -#if GLIBTOP_SOLARIS_RELEASE >= 50600 761 +//#if GLIBTOP_SOLARIS_RELEASE >= 50600 762 763 - dl = dlopen("/usr/lib/libproc.so", RTLD_LAZY); 764 - if(server->machine.libproc) 765 - dlclose(server->machine.libproc); 766 - server->machine.libproc = dl; 767 - if(dl) 768 - { 769 - void *func; 770 + // dl = dlopen("/usr/lib/libproc.so", RTLD_LAZY); 771 + // if(server->machine.libproc) 772 +// // dlclose(server->machine.libproc); 773 + // server->machine.libproc = dl; 774 + // if(dl) 775 + // { 776 + // void *func; 777 778 - func = dlsym(dl, "Pobjname"); /* Solaris 8 */ 779 - if(!func) 780 - func = dlsym(dl, "proc_objname"); /* Solaris 7 */ 781 - server->machine.objname = (void (*) 782 - (void *, uintptr_t, const char *, size_t))func; 783 - server->machine.pgrab = (struct ps_prochandle *(*)(pid_t, int, int *)) 784 - dlsym(dl, "Pgrab"); 785 - server->machine.pfree = (void (*)(void *))dlsym(dl, "Pfree"); 786 - 787 - } 788 - else 789 - { 790 - server->machine.objname = NULL; 791 - server->machine.pgrab = NULL; 792 - server->machine.pfree = NULL; 793 - } 794 -#endif 795 + // func = dlsym(dl, "Pobjname"); /* Solaris 8 */ 796 + // if(!func) 797 +// func = dlsym(dl, "proc_objname"); /* Solaris 7 */ 798 + // server->machine.objname = (void (*) 799 +// (void *, uintptr_t, const char *, size_t))func; 800 + // server->machine.pgrab = (struct ps_prochandle *(*)(pid_t, int, int *)) 801 +// dlsym(dl, "Pgrab"); 802 + // server->machine.pfree = (void (*)(void *))dlsym(dl, "Pfree"); 803 + // 804 + // } 805 + // else 806 + // { 807 + // server->machine.objname = NULL; 808 + // server->machine.pgrab = NULL; 809 + // server->machine.pfree = NULL; 810 + // } 811 +//#endif 812 server->machine.me = getpid(); 813 } 814 diff -Nrup libgtop-2.23.90.orig/sysdeps/solaris/procaffinity.c libgtop-2.23.90.mod/sysdeps/solaris/procaffinity.c 815 --- libgtop-2.23.90.orig/sysdeps/solaris/procaffinity.c 1970-01-01 08:00:00.000000000 +0800 816 +++ libgtop-2.23.90.mod/sysdeps/solaris/procaffinity.c 2008-08-20 20:39:47.771308000 +0800 817 @@ -0,0 +1,84 @@ 818 +/* Copyright (C) 2007 Joe Marcus Clarke <marcus (a] FreeBSD.org> 819 + This file is part of LibGTop 2. 820 + 821 + LibGTop is free software; you can redistribute it and/or modify it 822 + under the terms of the GNU General Public License as published by 823 + the Free Software Foundation; either version 2 of the License, 824 + or (at your option) any later version. 825 + 826 + LibGTop is distributed in the hope that it will be useful, but WITHOUT 827 + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 828 + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 829 + for more details. 830 + 831 + You should have received a copy of the GNU General Public License 832 + along with LibGTop; see the file COPYING. If not, write to the 833 + Free Software Foundation, Inc., 59 Temple Place - Suite 330, 834 + Boston, MA 02111-1307, USA. 835 +*/ 836 + 837 +#include <config.h> 838 +#include <glibtop/procaffinity.h> 839 +#include <glibtop/error.h> 840 + 841 +#include <glibtop_private.h> 842 + 843 +#include <sys/param.h> 844 + 845 +void 846 +_glibtop_init_proc_affinity_s(glibtop *server) 847 +{ 848 +/* 849 + server->sysdeps.proc_affinity = 850 + (1 << GLIBTOP_PROC_AFFINITY_NUMBER) | 851 + (1 << GLIBTOP_PROC_AFFINITY_ALL); 852 +*/ 853 +} 854 + 855 + 856 +guint16 * 857 +glibtop_get_proc_affinity_s(glibtop *server, glibtop_proc_affinity *buf, pid_t pid) 858 +{ 859 +/* 860 +#if __FreeBSD_version > 800024 861 + id_t id; 862 + cpulevel_t level; 863 + cpuwhich_t which; 864 + cpuset_t mask; 865 + size_t i; 866 + GArray* cpus; 867 + 868 + memset(buf, 0, sizeof *buf); 869 + 870 + which = CPU_WHICH_PID; 871 + level = CPU_LEVEL_WHICH; 872 + id = pid; 873 + 874 + if (cpuset_getaffinity(level, which, id, sizeof(mask), &mask) != 0) { 875 + glibtop_error_r(server, "cpuset_getaffinity failed"); 876 + return NULL; 877 + } 878 + 879 + cpus = g_array_new(FALSE, FALSE, sizeof(guint16)); 880 + 881 + for (i = 0; i < MIN(CPU_SETSIZE, (size_t)(server->ncpu + 1)); i++) { 882 + if (CPU_ISSET(i, &mask)) { 883 + guint16 n = i; 884 + g_array_append_val(cpus, n); 885 + } 886 + } 887 + 888 + buf->number = cpus->len; 889 + buf->all = (cpus->len == (size_t)(server->ncpu + 1)); 890 + buf->flags = (1 << GLIBTOP_PROC_AFFINITY_NUMBER) 891 + | (1 << GLIBTOP_PROC_AFFINITY_ALL); 892 + 893 + return (guint16*) g_array_free(cpus, FALSE); 894 +#else 895 + memset(buf, 0, sizeof *buf); 896 + 897 + return NULL; 898 +#endif 899 +*/ 900 +} 901 + 902 diff -Nrup libgtop-2.23.90.orig/sysdeps/solaris/procmap.c libgtop-2.23.90.mod/sysdeps/solaris/procmap.c 903 --- libgtop-2.23.90.orig/sysdeps/solaris/procmap.c 2008-05-24 06:13:24.000000000 +0800 904 +++ libgtop-2.23.90.mod/sysdeps/solaris/procmap.c 2008-08-20 19:06:32.593851000 +0800 905 @@ -54,9 +54,16 @@ glibtop_map_entry * 906 glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid) 907 { 908 int fd, i, nmaps, pr_err, heap; 909 + 910 + char filename [BUFSIZ]; 911 + /* use flags as a check condition, if it is 1, check, or, not check... zhua */ 912 + int check = buf->flags; 913 + /* set flags back to 0 */ 914 + buf->flags = 0; 915 + 916 #if GLIBTOP_SOLARIS_RELEASE >= 50600 917 prxmap_t *maps; 918 - struct ps_prochandle *Pr = NULL; 919 +// struct ps_prochandle *Pr = NULL; 920 #else 921 prmap_t *maps; 922 #endif 923 @@ -123,16 +130,44 @@ glibtop_get_proc_map_s (glibtop *server, 924 buf->total = nmaps * sizeof(glibtop_map_entry); 925 entry = g_malloc0(buf->total); 926 927 -#if GLIBTOP_SOLARIS_RELEASE >= 50600 928 +//#if GLIBTOP_SOLARIS_RELEASE >= 50600 929 930 - if(server->machine.objname && server->machine.pgrab && 931 - server->machine.pfree) 932 - Pr = (server->machine.pgrab)(pid, 1, &pr_err); 933 -#endif 934 +// if(server->machine.objname && server->machine.pgrab && 935 +// server->machine.pfree) 936 +// Pr = (server->machine.pgrab)(pid, 1, &pr_err); 937 +//#endif 938 for(heap = 0,i = 0; i < nmaps; ++i) 939 { 940 int len; 941 942 + /* take a check to see if we need all information, if not, just get what we need.. 943 + Also please see comments in get_process_memory_writable() of gnome-system-monitor zhua */ 944 + if (check == 1) 945 + { 946 + if(maps[i].pr_mflags & MA_WRITE){ 947 + entry[i].perm |= GLIBTOP_MAP_PERM_WRITE; 948 + entry[i].size = maps[i].pr_size; 949 + } 950 + if(maps[i].pr_mflags & MA_SHARED){ 951 + entry[i].perm |= GLIBTOP_MAP_PERM_SHARED; 952 + /* here use shared_clean to store Shared Memory */ 953 + entry[i].shared_clean = maps[i].pr_size; 954 + } 955 + } 956 + else 957 + if (check == 2) 958 + { 959 + if(maps[i].pr_mflags & MA_SHARED){ 960 + entry[i].perm |= GLIBTOP_MAP_PERM_SHARED; 961 + /* here use shared_clean to store Shared Memory */ 962 + entry[i].shared_clean = maps[i].pr_size; 963 + } 964 + } 965 + else { 966 + 967 + int len, rv; 968 + 969 + 970 entry[i].start = maps[i].pr_vaddr; 971 entry[i].end = maps[i].pr_vaddr + maps[i].pr_size; 972 973 @@ -177,25 +212,40 @@ glibtop_get_proc_map_s (glibtop *server, 974 entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME); 975 } 976 else 977 - if(Pr) 978 - { 979 - server->machine.objname(Pr, maps[i].pr_vaddr, buffer, 980 - BUFSIZ); 981 - if((len = resolvepath(buffer, entry[i].filename, 982 - GLIBTOP_MAP_FILENAME_LEN)) > 0) 983 - { 984 - entry[i].filename[len] = 0; 985 - entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME); 986 - } 987 - } 988 -#endif 989 - } 990 - 991 -#if GLIBTOP_SOLARIS_RELEASE >= 50600 992 - 993 - if(Pr) 994 - server->machine.pfree(Pr); 995 -#endif 996 +// if(Pr) 997 +// { 998 +// server->machine.objname(Pr, maps[i].pr_vaddr, buffer, 999 +// BUFSIZ); 1000 +// if((len = resolvepath(buffer, entry[i].filename, 1001 +// GLIBTOP_MAP_FILENAME_LEN)) > 0) 1002 +// { 1003 +// entry[i].filename[len] = 0; 1004 +// entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME); 1005 +// } 1006 +// } 1007 + { 1008 + g_strlcpy(buffer, maps[i].pr_mapname, sizeof buffer); 1009 + /* from /path get file name */ 1010 + g_snprintf(filename, sizeof filename, "/proc/%d/path/%s", 1011 + pid, buffer); 1012 + 1013 + rv = readlink(filename, entry[i].filename, sizeof(entry[i].filename) - 1); 1014 + /* read object, if have not, set it as NULL */ 1015 + if(rv < 0) 1016 + rv = 0; 1017 + entry[i].filename[rv] = '\0'; 1018 + /* now set the flags */ 1019 + entry[i].flags |= (1L << GLIBTOP_MAP_ENTRY_FILENAME); 1020 + } 1021 +#endif 1022 + } 1023 + } 1024 + 1025 +//#if GLIBTOP_SOLARIS_RELEASE >= 50600 1026 + 1027 +// if(Pr) 1028 +// server->machine.pfree(Pr); 1029 +//#endif 1030 buf->flags = _glibtop_sysdeps_proc_map; 1031 s_close(fd); 1032 return entry; 1033 diff -Nrup libgtop-2.23.90.orig/sysdeps/solaris/procmem.c libgtop-2.23.90.mod/sysdeps/solaris/procmem.c 1034 --- libgtop-2.23.90.orig/sysdeps/solaris/procmem.c 2008-05-24 06:13:24.000000000 +0800 1035 +++ libgtop-2.23.90.mod/sysdeps/solaris/procmem.c 2008-08-20 19:09:08.485871000 +0800 1036 @@ -22,12 +22,14 @@ 1037 #include <config.h> 1038 #include <glibtop.h> 1039 #include <glibtop/procmem.h> 1040 +#include <glibtop/procmap.h> 1041 1042 #include "glibtop_private.h" 1043 1044 static const unsigned long _glibtop_sysdeps_proc_mem = 1045 (1L << GLIBTOP_PROC_MEM_SIZE) + (1L << GLIBTOP_PROC_MEM_VSIZE) + 1046 -(1L << GLIBTOP_PROC_MEM_RESIDENT) + (1L << GLIBTOP_PROC_MEM_RSS); 1047 +(1L << GLIBTOP_PROC_MEM_RESIDENT) + (1L << GLIBTOP_PROC_MEM_RSS) + 1048 +(1L << GLIBTOP_PROC_MEM_SHARE); 1049 1050 /* Init function. */ 1051 1052 @@ -61,5 +63,31 @@ glibtop_get_proc_mem_s (glibtop *server, 1053 buf->size = buf->vsize = psinfo.pr_size << pagesize << 10; 1054 buf->resident = buf->rss = psinfo.pr_rssize << pagesize << 10; 1055 #endif 1056 +/* get Shared Memory */ 1057 + glibtop_proc_map mapbuf; 1058 + glibtop_map_entry *maps; 1059 + unsigned i; 1060 + buf->share = 0; 1061 + 1062 + /* we have to optimize the performance of libgtop, because update the information will occupy too much cpu. 1063 + 1064 + here I would like to make a little update:set glibtop_proc_map.flags=1,so as to let glibtop_get_proc_map_s() 1065 + only return the ones this function need: memwritable 1066 + 1067 + we do the check in glibtop_get_proc_map_s(), don't run the others part which don't need by this function, 1068 + I think this will accelerate the transaction lots, 1069 + Also this will not affect the existing codes, because when nobody set glibtop_proc_map.flags, 1070 + glibtop_get_proc_map() will return all as before. zhua 1071 + */ 1072 + mapbuf.flags = 2; 1073 + 1074 + maps = glibtop_get_proc_map_s(server, &mapbuf, pid); 1075 + 1076 + for (i = 0; i < mapbuf.number; ++i) { 1077 + if (maps[i].perm & GLIBTOP_MAP_PERM_SHARED) 1078 + buf->share += maps[i].shared_clean; 1079 + } 1080 + g_free(maps); 1081 + 1082 buf->flags = _glibtop_sysdeps_proc_mem; 1083 } 1084 diff -Nrup libgtop-2.23.90.orig/sysdeps/solaris/procstate.c libgtop-2.23.90.mod/sysdeps/solaris/procstate.c 1085 --- libgtop-2.23.90.orig/sysdeps/solaris/procstate.c 2008-05-24 06:13:24.000000000 +0800 1086 +++ libgtop-2.23.90.mod/sysdeps/solaris/procstate.c 2008-08-20 22:19:57.697233000 +0800 1087 @@ -62,6 +62,26 @@ glibtop_get_proc_state_s (glibtop *serve 1088 buf->gid = psinfo.pr_egid; 1089 buf->ruid = psinfo.pr_uid; 1090 buf->rgid = psinfo.pr_gid; 1091 + /* zhua: get some value here, so that we don't need run open/pread/close psinfo later, 1092 + and can delete some other call for psinfo open/pread/close. it will save lots of time*/ 1093 +#ifdef HAVE_PROCFS_H 1094 + buf->nice = psinfo.pr_lwp.pr_nice - NZERO; 1095 +#else 1096 + buf->nice = psinfo.pr_nice - NZERO; 1097 +#endif 1098 + buf->start_time = psinfo.pr_start.tv_sec; 1099 + buf->ppid = psinfo.pr_ppid; 1100 + 1101 +#ifdef HAVE_PROCFS_H 1102 + buf->vsize = psinfo.pr_size << 10; 1103 + buf->resident= psinfo.pr_rssize << 10; 1104 + buf->load = (guint) psinfo.pr_lwp.pr_pctcpu * 100 / (guint) 0x8000; 1105 +#else 1106 + buf->vsize = psinfo.pr_size << pagesize << 10; 1107 + buf->resident = psinfo.pr_rssize << pagesize << 10; 1108 + buf->load = (guint) psinfo.pr_lwp.pr_pctcpu * 100 / (guint) 0x8000; 1109 +#endif 1110 + 1111 1112 #ifdef HAVE_PROCFS_H 1113 switch(psinfo.pr_lwp.pr_state) 1114 diff -Nrup libgtop-2.23.90.orig/sysdeps/solaris/proctime.c libgtop-2.23.90.mod/sysdeps/solaris/proctime.c 1115 --- libgtop-2.23.90.orig/sysdeps/solaris/proctime.c 2008-05-24 06:13:24.000000000 +0800 1116 +++ libgtop-2.23.90.mod/sysdeps/solaris/proctime.c 2008-08-20 19:38:04.212493000 +0800 1117 @@ -43,6 +43,11 @@ void 1118 glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, 1119 pid_t pid) 1120 { 1121 +#ifdef HAVE_PROCFS_H 1122 + struct psinfo pinfo; 1123 +#else 1124 + struct prpsinfo pinfo; 1125 +#endif 1126 struct prusage prusage; 1127 GTimeVal time; 1128 1129 @@ -52,19 +57,27 @@ glibtop_get_proc_time_s (glibtop *server 1130 1131 if(pid) 1132 { 1133 + /* zhua remove this function call, because we can change to get start_time in 1134 + glibtop_get_proc_state(), it don't need open psinfo again here */ 1135 + 1136 + if (glibtop_get_proc_data_psinfo_s(server, &pinfo, pid)) 1137 + return; 1138 + buf->start_time = pinfo.pr_start.tv_sec; 1139 + 1140 if (glibtop_get_proc_data_usage_s (server, &prusage, pid)) 1141 return; 1142 1143 - g_get_current_time (&time); 1144 - /* prusage.pr_rtime.tv_sec is the during that the process existed */ 1145 - buf->start_time = time.tv_sec - prusage.pr_rtime.tv_sec; 1146 +// g_get_current_time (&time); 1147 +// /* prusage.pr_rtime.tv_sec is the during that the process existed */ 1148 + // buf->start_time = time.tv_sec - prusage.pr_rtime.tv_sec; 1149 1150 - buf->rtime = prusage.pr_rtime.tv_sec * 1E+6 + 1151 - prusage.pr_rtime.tv_nsec / 1E+3; 1152 +// buf->rtime = prusage.pr_rtime.tv_sec * 1E+6 + 1153 +// prusage.pr_rtime.tv_nsec / 1E+3; 1154 buf->utime = prusage.pr_utime.tv_sec * 1E+6 + 1155 prusage.pr_utime.tv_nsec / 1E+3; 1156 buf->stime = prusage.pr_stime.tv_sec * 1E+6 + 1157 prusage.pr_stime.tv_nsec / 1E+3; 1158 + buf->rtime = (buf->utime + buf->stime) / 10000; 1159 } 1160 1161 buf->flags = _glibtop_sysdeps_proc_time; 1162 diff -Nrup libgtop-2.23.90.orig/sysdeps/solaris/procwd.c libgtop-2.23.90.mod/sysdeps/solaris/procwd.c 1163 --- libgtop-2.23.90.orig/sysdeps/solaris/procwd.c 1970-01-01 08:00:00.000000000 +0800 1164 +++ libgtop-2.23.90.mod/sysdeps/solaris/procwd.c 2008-08-20 19:17:28.084980000 +0800 1165 @@ -0,0 +1,98 @@ 1166 +/* Copyright (C) 2007 Benot Dejean 1167 + This file is part of LibGTop 2. 1168 + 1169 + LibGTop is free software; you can redistribute it and/or modify it 1170 + under the terms of the GNU General Public License as published by 1171 + the Free Software Foundation; either version 2 of the License, 1172 + or (at your option) any later version. 1173 + 1174 + LibGTop is distributed in the hope that it will be useful, but WITHOUT 1175 + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1176 + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1177 + for more details. 1178 + 1179 + You should have received a copy of the GNU General Public License 1180 + along with LibGTop; see the file COPYING. If not, write to the 1181 + Free Software Foundation, Inc., 59 Temple Place - Suite 330, 1182 + Boston, MA 02111-1307, USA. 1183 +*/ 1184 + 1185 +#include <config.h> 1186 +#include <glibtop/procwd.h> 1187 +#include <glibtop/error.h> 1188 + 1189 +#include <glibtop_private.h> 1190 + 1191 +#include <unistd.h> 1192 +#include <dirent.h> 1193 +#include <sys/types.h> 1194 + 1195 + 1196 +void 1197 +_glibtop_init_proc_wd_s(glibtop *server) 1198 +{ 1199 + server->sysdeps.proc_wd = 1200 + (1 << GLIBTOP_PROC_WD_EXE) + 1201 + (1 << GLIBTOP_PROC_WD_ROOT) + 1202 + (1 << GLIBTOP_PROC_WD_NUMBER); 1203 + 1204 +} 1205 + 1206 +static gboolean is_in(GPtrArray *array, const char *str) 1207 +{ 1208 + guint i; 1209 + 1210 + for (i = 0; i != array->len; ++i) { 1211 + if (strcmp(g_ptr_array_index(array, i), str) == 0) 1212 + return TRUE; 1213 + } 1214 + 1215 + return FALSE; 1216 +} 1217 + 1218 + 1219 +char** 1220 +glibtop_get_proc_wd_s(glibtop *server, glibtop_proc_wd *buf, pid_t pid) 1221 +{ 1222 + GPtrArray *dirs; 1223 + char path[80]; 1224 + char dir[256]; 1225 + DIR *task; 1226 + 1227 + glibtop_init_s(&server, GLIBTOP_SYSDEPS_PROC_WD, 0); 1228 + 1229 + memset(buf, 0, sizeof(glibtop_proc_wd)); 1230 + 1231 + g_snprintf(path, sizeof path, "/proc/%u/root", pid); 1232 + if (safe_readlink(path, buf->root, sizeof buf->root)) 1233 + buf->flags |= (1 << GLIBTOP_PROC_WD_ROOT); 1234 + 1235 + g_snprintf(path, sizeof path, "/proc/%u/exe", pid); 1236 + if (safe_readlink(path, buf->exe, sizeof buf->exe)) 1237 + buf->flags |= (1 << GLIBTOP_PROC_WD_EXE); 1238 + 1239 + dirs = g_ptr_array_sized_new(2); 1240 + 1241 + g_snprintf(path, sizeof path, "/proc/%u/cwd", pid); 1242 + if (safe_readlink(path, dir, sizeof dir)) 1243 + g_ptr_array_add(dirs, g_strdup(dir)); 1244 + 1245 + g_snprintf(path, sizeof path, "/proc/%u/task", pid); 1246 + if ((task = opendir(path)) != NULL) { 1247 + struct dirent *sub; 1248 + while ((sub = readdir(task)) != NULL) { 1249 + g_snprintf(path, sizeof path, "/proc/%u/task/%s/cwd", pid, sub->d_name); 1250 + if (safe_readlink(path, dir, sizeof dir) && !is_in(dirs, dir)) 1251 + g_ptr_array_add(dirs, g_strdup(dir)); 1252 + } 1253 + closedir(task); 1254 + } 1255 + 1256 + buf->number = dirs->len; 1257 + buf->flags |= (1 << GLIBTOP_PROC_WD_NUMBER); 1258 + 1259 + g_ptr_array_add(dirs, NULL); 1260 + 1261 + return (char**) g_ptr_array_free(dirs, FALSE); 1262 +} 1263 + 1264 diff -Nrup libgtop-2.23.90.orig/sysdeps/solaris/sem_limits.c libgtop-2.23.90.mod/sysdeps/solaris/sem_limits.c 1265 --- libgtop-2.23.90.orig/sysdeps/solaris/sem_limits.c 2008-05-24 06:13:24.000000000 +0800 1266 +++ libgtop-2.23.90.mod/sysdeps/solaris/sem_limits.c 2008-08-20 20:21:27.584506000 +0800 1267 @@ -39,14 +39,22 @@ static const unsigned long _glibtop_sysd 1268 (1L << GLIBTOP_IPC_SEMUSZ) + (1L << GLIBTOP_IPC_SEMVMX) + 1269 (1L << GLIBTOP_IPC_SEMAEM); 1270 #else 1271 -static const unsigned long _glibtop_sysdeps_sem_limits = 0; 1272 +static const unsigned long _glibtop_sysdeps_sem_limits = 1273 +(1L << GLIBTOP_IPC_SEMMNI) + 1274 +(1L << GLIBTOP_IPC_SEMMSL) + 1275 +(1L << GLIBTOP_IPC_SEMOPM); 1276 #endif 1277 1278 1279 /* Init function. */ 1280 1281 +#if GLIBTOP_SUID_SEM_LIMITS 1282 void 1283 _glibtop_init_sem_limits_p (glibtop *server) 1284 +#else 1285 +void 1286 +_glibtop_init_sem_limits_s (glibtop *server) 1287 +#endif 1288 { 1289 #if GLIBTOP_SOLARIS_RELEASE < 51000 1290 1291 @@ -61,8 +69,13 @@ _glibtop_init_sem_limits_p (glibtop *ser 1292 1293 /* Provides information about sysv sem limits. */ 1294 1295 +#if GLIBTOP_SUID_SEM_LIMITS 1296 void 1297 glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf) 1298 +#else 1299 +void 1300 +glibtop_get_sem_limits_s (glibtop *server, glibtop_sem_limits *buf) 1301 +#endif 1302 { 1303 #if GLIBTOP_SOLARIS_RELEASE < 51000 1304 kvm_t *kd = server->machine.kd; 1305 diff -Nrup libgtop-2.23.90.orig/sysdeps/solaris/shm_limits.c libgtop-2.23.90.mod/sysdeps/solaris/shm_limits.c 1306 --- libgtop-2.23.90.orig/sysdeps/solaris/shm_limits.c 2008-05-24 06:13:24.000000000 +0800 1307 +++ libgtop-2.23.90.mod/sysdeps/solaris/shm_limits.c 2008-08-20 21:46:13.220805000 +0800 1308 @@ -30,7 +30,9 @@ 1309 static const struct nlist nlst[] = { {"glibtop_shm_limits"}, {NULL} }; 1310 1311 #if GLIBTOP_SOLARIS_RELEASE >=51000 1312 -static const unsigned long _glibtop_sysdeps_shm_limits = 0; 1313 +static const unsigned long _glibtop_sysdeps_shm_limits = 1314 +(1L << GLIBTOP_IPC_SHMMAX) + 1315 +(1L << GLIBTOP_IPC_SHMMIN); 1316 #else 1317 # if GLIBTOP_SOLARIS_RELEASE < 50900 1318 static const unsigned long _glibtop_sysdeps_shm_limits = 1319 @@ -45,8 +47,13 @@ static const unsigned long _glibtop_sysd 1320 1321 /* Init function. */ 1322 1323 +#if GLIBTOP_SUID_SHM_LIMITS 1324 void 1325 _glibtop_init_shm_limits_p (glibtop *server) 1326 +#else 1327 +void 1328 +_glibtop_init_shm_limits_s (glibtop *server) 1329 +#endif 1330 { 1331 #if GLIBTOP_SOLARIS_RELEASE < 51000 1332 1333 @@ -61,8 +68,13 @@ _glibtop_init_shm_limits_p (glibtop *ser 1334 1335 /* Provides information about sysv ipc limits. */ 1336 1337 +#if GLIBTOP_SUID_SHM_LIMITS 1338 void 1339 glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf) 1340 +#else 1341 +void 1342 +glibtop_get_shm_limits_s (glibtop *server, glibtop_shm_limits *buf) 1343 +#endif 1344 { 1345 #if GLIBTOP_SOLARIS_RELEASE < 51000 1346 1347 diff -Nrup libgtop-2.23.90.orig/sysdeps/solaris/siglist.c libgtop-2.23.90.mod/sysdeps/solaris/siglist.c 1348 --- libgtop-2.23.90.orig/sysdeps/solaris/siglist.c 2008-05-24 06:13:24.000000000 +0800 1349 +++ libgtop-2.23.90.mod/sysdeps/solaris/siglist.c 2008-08-20 19:22:53.411487000 +0800 1350 @@ -61,6 +61,7 @@ const glibtop_signame glibtop_sys_siglis 1351 { 35, "SIGTHAW", "Checkpoint Thaw" }, 1352 { 36, "SIGCANCEL","Thread Cancelation" }, 1353 { 37, "SIGLOST", "Resource Lost" }, 1354 +#if GLIBTOP_SOLARIS_RELEASE < 50900 /* S8 */ 1355 { 38, "SIGRTMIN","First Realtime Signal" }, 1356 { 39, "SIGRTMIN+1", "Second Realtime Signal" }, 1357 { 40, "SIGRTMIN+2", "Third Realtime Signal" }, 1358 @@ -69,5 +70,30 @@ const glibtop_signame glibtop_sys_siglis 1359 { 43, "SIGRTMAX-2", "Third Last Realtime Signal" }, 1360 { 44, "SIGRTMAX-1", "Second Last Realtime Signal" }, 1361 { 45, "SIGRTMAX", "Last Realtime Signal" }, 1362 +#endif 1363 +#if GLIBTOP_SOLARIS_RELEASE >= 50900 1364 + { 38, "SIGXRES","Resource Control Exceeded" }, 1365 +#if GLIBTOP_SOLARIS_RELEASE <51000 /* signal here existed in s9 */ 1366 + { 39, "SIGRTMIN","First Realtime Signal" }, 1367 + { 40, "SIGRTMIN+1", "Second Realtime Signal" }, 1368 + { 41, "SIGRTMIN+2", "Third Realtime Signal" }, 1369 + { 42, "SIGRTMIN+3", "Fourth Realtime Signal" }, 1370 + { 43, "SIGRTMAX-3", "Fourth Last Realtime Signal" }, 1371 + { 44, "SIGRTMAX-2", "Third Last Realtime Signal" }, 1372 + { 45, "SIGRTMAX-1", "Second Last Realtime Signal" }, 1373 + { 46, "SIGRTMAX", "Last Realtime Signal" }, 1374 +#else /* signal here existed in s10 and s11 */ 1375 + { 39, "SIGJVM1","Reserved signal for Java Virtual Machine" }, 1376 + { 40, "SIGJVM1","Reserved signal for Java Virtual Machine" }, 1377 + { 41, "SIGRTMIN","First Realtime Signal" }, 1378 + { 42, "SIGRTMIN+1", "Second Realtime Signal" }, 1379 + { 43, "SIGRTMIN+2", "Third Realtime Signal" }, 1380 + { 44, "SIGRTMIN+3", "Fourth Realtime Signal" }, 1381 + { 45, "SIGRTMAX-3", "Fourth Last Realtime Signal" }, 1382 + { 46, "SIGRTMAX-2", "Third Last Realtime Signal" }, 1383 + { 47, "SIGRTMAX-1", "Second Last Realtime Signal" }, 1384 + { 48, "SIGRTMAX", "Last Realtime Signal" }, 1385 +#endif 1386 +#endif 1387 { 0, NULL, NULL } 1388 }; 1389 diff -Nrup libgtop-2.23.90.orig/sysdeps/solaris/sysinfo.c libgtop-2.23.90.mod/sysdeps/solaris/sysinfo.c 1390 --- libgtop-2.23.90.orig/sysdeps/solaris/sysinfo.c 1970-01-01 08:00:00.000000000 +0800 1391 +++ libgtop-2.23.90.mod/sysdeps/solaris/sysinfo.c 2008-08-20 19:23:21.791056000 +0800 1392 @@ -0,0 +1,48 @@ 1393 +/* $Id: sysinfo.c,v 1.22 2004/11/28 01:32:55 bdejean Exp $ */ 1394 + 1395 +/* Copyright (C) 1998-99 Martin Baulig 1396 + This file is part of LibGTop 1.0. 1397 + 1398 + Contributed by Martin Baulig <martin (a] home-of-linux.org>, April 1998. 1399 + 1400 + LibGTop is free software; you can redistribute it and/or modify it 1401 + under the terms of the GNU General Public License as published by 1402 + the Free Software Foundation; either version 2 of the License, 1403 + or (at your option) any later version. 1404 + 1405 + LibGTop is distributed in the hope that it will be useful, but WITHOUT 1406 + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1407 + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1408 + for more details. 1409 + 1410 + You should have received a copy of the GNU General Public License 1411 + along with LibGTop; see the file COPYING. If not, write to the 1412 + Free Software Foundation, Inc., 59 Temple Place - Suite 330, 1413 + Boston, MA 02111-1307, USA. 1414 +*/ 1415 + 1416 +#include <config.h> 1417 +#include <glibtop/error.h> 1418 +#include <glibtop/cpu.h> 1419 +#include <glibtop/sysinfo.h> 1420 + 1421 +#include "glibtop_private.h" 1422 + 1423 + 1424 +static const unsigned long _glibtop_sysdeps_sysinfo = 1425 +(1L << GLIBTOP_SYSINFO_CPUINFO); 1426 + 1427 +static glibtop_sysinfo sysinfo = { .flags = 0 }; 1428 + 1429 +static void 1430 +init_sysinfo (glibtop *server) 1431 +{ 1432 + 1433 +} 1434 + 1435 +const glibtop_sysinfo * 1436 +glibtop_get_sysinfo_s (glibtop *server) 1437 +{ 1438 + init_sysinfo (server); 1439 + return &sysinfo; 1440 +} 1441