ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/tools.c
(Generate patch)

Comparing projects/libstatgrab/src/libstatgrab/tools.c (file contents):
Revision 1.58 by ats, Mon Nov 1 20:34:58 2004 UTC vs.
Revision 1.64 by tdb, Mon Oct 9 14:09:38 2006 UTC

# Line 42 | Line 42
42   #include <sys/param.h>
43   #include <sys/sysctl.h>
44   #endif
45 + #ifdef HPUX
46 + #include <sys/param.h>
47 + #include <sys/pstat.h>
48 + #endif
49  
50   #include "tools.h"
51   #include "statgrab.h"
# Line 60 | Line 64
64   #include <sys/fcntl.h>
65   #include <dirent.h>
66   #endif
67 + #ifdef WIN32
68 + #include "win32.h"
69 + #endif
70  
71   #if defined(SOLARIS) && defined(HAVE_LIBDEVINFO_H)
72   struct map{
# Line 230 | Line 237 | static int build_mapping(){
237                          if(strcmp(ksp->ks_module, "md")==0) continue;
238                          if((kstat_read(kc, ksp, &kios))==-1) continue;
239                          strncpy(device_name, ksp->ks_name, sizeof device_name);
240 <                        for(x=0;x<(sizeof device_name);x++){
240 >                        for(x=0;x<(int)(sizeof device_name);x++){
241                                  if( isdigit((int)device_name[x]) ) break;
242                          }
243                          if(x == sizeof device_name) x--;
# Line 242 | Line 249 | static int build_mapping(){
249                                  if (x>=BIG_ENOUGH){
250                                          /* We've got bigger than we thought was massive */
251                                          /* If we hit this.. Make big enough bigger */
252 +                                        kstat_close(kc);
253                                          return -1;
254                                  }
255                                  if( !strncmp(driver_list[x], device_name, BIG_ENOUGH)){
# Line 252 | Line 260 | static int build_mapping(){
260  
261                          if(!found){
262                                  if((get_alias(device_name)) != 0){
263 +                                        kstat_close(kc);
264                                          return -1;
265                                  }
266                                  strncpy(driver_list[x], device_name, BIG_ENOUGH);
# Line 260 | Line 269 | static int build_mapping(){
269                  }
270          }
271  
272 +        kstat_close(kc);
273 +
274          return 0;
275   }
276  
# Line 290 | Line 301 | char *sg_get_string_match(char *line, regmatch_t *matc
301          return match_string;
302   }
303  
304 < long long sg_get_ll_match(char *line, regmatch_t *match){
294 <        char *ptr;
295 <        long long num;
296 <
297 <        ptr=line+match->rm_so;
298 <        num=atoll(ptr);
299 <
300 <        return num;
301 < }
302 < #endif
303 <
304 > /* Cygwin (without a recent newlib) doesn't have atoll */
305   #ifndef HAVE_ATOLL
306   static long long atoll(const char *s) {
307          long long value = 0;
# Line 321 | Line 322 | static long long atoll(const char *s) {
322   }
323   #endif
324  
325 + long long sg_get_ll_match(char *line, regmatch_t *match){
326 +        char *ptr;
327 +        long long num;
328 +
329 +        ptr=line+match->rm_so;
330 +        num=atoll(ptr);
331 +
332 +        return num;
333 + }
334 + #endif
335 +
336   /*      $OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $     */
337  
338   /*
# Line 439 | Line 451 | int sg_update_string(char **dest, const char *src) {
451          return 0;
452   }
453  
454 + /* join two strings together */
455 + int sg_concat_string(char **dest, const char *src) {
456 +        char *new;
457 +        int len = strlen(*dest) + strlen(src) + 1;
458 +
459 +        new = sg_realloc(*dest, len);
460 +        if (new == NULL) {
461 +                return -1;
462 +        }
463 +
464 +        *dest = new;
465 +        strcat(*dest, src);
466 +        return 0;
467 + }
468 +
469   #if (defined(FREEBSD) && !defined(FREEBSD5)) || defined(DFBSD)
470   kvm_t *sg_get_kvm() {
471          static kvm_t *kvmd = NULL;
# Line 489 | Line 516 | struct uvmexp *sg_get_uvmexp() {
516   }
517   #endif
518  
519 + #ifdef HPUX
520 + struct pst_static *sg_get_pstat_static() {
521 +        static int got = 0;
522 +        static struct pst_static pst;
523 +
524 +        if (!got) {
525 +                if (pstat_getstatic(&pst, sizeof pst, 1, 0) == -1) {
526 +                        sg_set_error_with_errno(SG_ERROR_PSTAT,
527 +                                                "pstat_static");
528 +                        return NULL;
529 +                }
530 +                got = 1;
531 +        }
532 +        return &pst;
533 + }
534 + #endif
535 +
536   int sg_init(){
537          sg_set_error(SG_ERROR_NONE, NULL);
538  
# Line 509 | Line 553 | int sg_init(){
553          build_mapping();
554   #endif
555   #endif
556 + #ifdef WIN32
557 +        return sg_win32_start_capture();
558 + #endif
559          return 0;
560   }
561  
562 + int sg_shutdown() {
563 + #ifdef WIN32
564 +        sg_win32_end_capture();
565 + #endif
566 +        return 0;
567 + }
568 +
569 + int sg_snapshot() {
570 + #ifdef WIN32
571 +        return sg_win32_snapshot();
572 + #else
573 +        return 0;
574 + #endif
575 + }
576 +
577   int sg_drop_privileges() {
578 + #ifndef WIN32
579   #ifdef HAVE_SETEGID
580          if (setegid(getgid()) != 0) {
581   #elif defined(HAVE_SETRESGID)
# Line 533 | Line 596 | int sg_drop_privileges() {
596                  sg_set_error_with_errno(SG_ERROR_SETEUID, NULL);
597                  return -1;
598          }
599 + #endif /* WIN32 */
600          return 0;
601   }
602  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines