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.24 by tdb, Mon Jan 19 16:49:21 2004 UTC vs.
Revision 1.35 by tdb, Sun Apr 4 22:48:50 2004 UTC

# Line 33 | Line 33
33   #include <regex.h>
34   #ifdef ALLBSD
35   #include <fcntl.h>
36 + #endif
37 + #if (defined(FREEBSD) && !defined(FREEBSD5)) || defined(DFBSD)
38   #include <kvm.h>
39 + #include <paths.h>
40   #endif
41 < #ifdef NETBSD
41 > #if defined(NETBSD) || defined(OPENBSD)
42   #include <uvm/uvm_extern.h>
43 + #include <sys/param.h>
44 + #include <sys/sysctl.h>
45   #endif
46  
47   #include "tools.h"
48  
49   #ifdef SOLARIS
50 + #ifdef HAVE_LIBDEVINFO_H
51   #include <libdevinfo.h>
52 + #endif
53   #include <kstat.h>
54   #include <unistd.h>
55   #include <ctype.h>
# Line 54 | Line 61
61   #include <dirent.h>
62   #endif
63  
64 < #ifdef SOLARIS
64 > #if defined(SOLARIS) && defined(HAVE_LIBDEVINFO_H)
65   struct map{
66          char *bsd;
67          char *svr;
# Line 64 | Line 71 | struct map{
71   typedef struct map mapping_t;
72  
73   static mapping_t *mapping = NULL;
74 + #endif
75  
76 + #ifdef SOLARIS
77   char *get_svr_from_bsd(char *bsd){
78 + #ifdef HAVE_LIBDEVINFO_H
79          mapping_t *map_ptr;
80          for(map_ptr = mapping; map_ptr != NULL; map_ptr = map_ptr->next)
81                  if(!strcmp(map_ptr->bsd, bsd)) return map_ptr->svr;
82 <
82 > #endif
83          return bsd;
84   }
85 + #endif
86  
87 + #if defined(SOLARIS) && defined(HAVE_LIBDEVINFO_H)
88   void add_mapping(char *bsd, char *svr){
89          mapping_t *map_ptr;
90          mapping_t *map_end_ptr;
# Line 409 | Line 421 | long long get_ll_match(char *line, regmatch_t *match){
421          return num;
422   }
423  
424 < #ifdef ALLBSD
424 > #if (defined(FREEBSD) && !defined(FREEBSD5)) || defined(DFBSD)
425   kvm_t *get_kvm() {
426          static kvm_t *kvmd = NULL;
427  
# Line 420 | Line 432 | kvm_t *get_kvm() {
432          kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, NULL);
433          return kvmd;
434   }
435 +
436 + /* Can't think of a better name for this function */
437 + kvm_t *get_kvm2() {
438 +        static kvm_t *kvmd2 = NULL;
439 +
440 +        if (kvmd2 != NULL) {
441 +                return kvmd2;
442 +        }
443 +
444 +        kvmd2 = kvm_openfiles(_PATH_DEVNULL, _PATH_DEVNULL, NULL, O_RDONLY, NULL);
445 +        return kvmd2;
446 + }
447   #endif
448  
449 < #ifdef NETBSD
449 > #if defined(NETBSD) || defined(OPENBSD)
450   struct uvmexp *get_uvmexp() {
451 <        static u_long addr = 0;
452 <        static struct uvmexp uvm;
453 <        kvm_t *kvmd = get_kvm();
451 >        int mib[2];
452 >        size_t size;
453 >        static struct uvmexp *uvm = NULL;
454  
455 <        if (kvmd == NULL) {
455 >        mib[0] = CTL_VM;
456 >        mib[1] = VM_UVMEXP;
457 >
458 >        if (sysctl(mib, 2, NULL, &size, NULL, 0) < 0) {
459                  return NULL;
460          }
461  
462 <        if (addr == 0) {
463 <                struct nlist symbols[] = {
464 <                        { "_uvmexp" },
438 <                        { NULL }
439 <                };
440 <
441 <                if (kvm_nlist(kvmd, symbols) != 0) {
442 <                        return NULL;
443 <                }
444 <                addr = symbols[0].n_value;
462 >        uvm = realloc(uvm, size);
463 >        if (uvm == NULL) {
464 >                return NULL;
465          }
466  
467 <        if (kvm_read(kvmd, addr, &uvm, sizeof uvm) != sizeof uvm) {
467 >        if (sysctl(mib, 2, uvm, &size, NULL, 0) < 0) {
468                  return NULL;
469          }
470 <        return &uvm;
470 >
471 >        return uvm;
472   }
473   #endif
474  
475   int statgrab_init(){
476 < #ifdef ALLBSD
476 > #if (defined(FREEBSD) && !defined(FREEBSD5)) || defined(DFBSD)
477          {
478                  kvm_t *kvmd = get_kvm();
479                  if (kvmd == NULL) return 1;
480          }
481 +        {
482 +                kvm_t *kvmd2 = get_kvm2();
483 +                if (kvmd2 == NULL) return 1;
484 +        }
485   #endif
486 < #ifdef NETBSD
486 > #if defined(NETBSD) || defined(OPENBSD)
487          {
488 +                /* This should always succeed, but it seems that on some
489 +                 * versions of NetBSD the first call to get_uvmexp will return
490 +                 * a non-filled-in structure; this is a workaround for that.
491 +                 */
492                  struct uvmexp *uvm = get_uvmexp();
493                  if (uvm == NULL) return 1;
494          }
# Line 469 | Line 498 | int statgrab_init(){
498           * will still work, just no disk mappings. So we will ignore the exit
499           * status of this, and carry on merrily.
500           */
501 + #ifdef HAVE_LIBDEVINFO_H
502          build_mapping();
503 + #endif
504   #endif
505          return 0;
506   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines