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.25 by pajs, Tue Feb 10 16:07:43 2004 UTC vs.
Revision 1.28 by ats, Fri Feb 13 15:22:49 2004 UTC

# Line 35 | Line 35
35   #include <fcntl.h>
36   #include <kvm.h>
37   #endif
38 < #ifdef NETBSD
38 > #if defined(NETBSD) || defined(OPENBSD)
39   #include <uvm/uvm_extern.h>
40 + #include <sys/param.h>
41 + #include <sys/sysctl.h>
42   #endif
43  
44   #include "tools.h"
45  
46   #ifdef SOLARIS
47 + #ifdef HAVE_LIBDEVINFO_H
48   #include <libdevinfo.h>
49 + #endif
50   #include <kstat.h>
51   #include <unistd.h>
52   #include <ctype.h>
# Line 54 | Line 58
58   #include <dirent.h>
59   #endif
60  
61 < #if defined(SOLARIS) && !defined(HAVE_LIBDEVINFO_H)
61 > #if defined(SOLARIS) && defined(HAVE_LIBDEVINFO_H)
62   struct map{
63          char *bsd;
64          char *svr;
# Line 64 | Line 68 | struct map{
68   typedef struct map mapping_t;
69  
70   static mapping_t *mapping = NULL;
71 + #endif
72  
73 + #ifdef SOLARIS
74   char *get_svr_from_bsd(char *bsd){
75 + #ifdef HAVE_LIBDEVINFO_H
76          mapping_t *map_ptr;
77          for(map_ptr = mapping; map_ptr != NULL; map_ptr = map_ptr->next)
78                  if(!strcmp(map_ptr->bsd, bsd)) return map_ptr->svr;
79 <
79 > #endif
80          return bsd;
81   }
82 + #endif
83  
84 + #if defined(SOLARIS) && defined(HAVE_LIBDEVINFO_H)
85   void add_mapping(char *bsd, char *svr){
86          mapping_t *map_ptr;
87          mapping_t *map_end_ptr;
# Line 422 | Line 431 | kvm_t *get_kvm() {
431   }
432   #endif
433  
434 < #ifdef NETBSD
434 > #if defined(NETBSD) || defined(OPENBSD)
435   struct uvmexp *get_uvmexp() {
436 <        static u_long addr = 0;
437 <        static struct uvmexp uvm;
438 <        kvm_t *kvmd = get_kvm();
436 >        int mib[2];
437 >        size_t size;
438 >        static struct uvmexp *uvm = NULL;
439  
440 <        if (kvmd == NULL) {
440 >        mib[0] = CTL_VM;
441 >        mib[1] = VM_UVMEXP;
442 >
443 >        if (sysctl(mib, 2, NULL, &size, NULL, 0) < 0) {
444                  return NULL;
445          }
446  
447 <        if (addr == 0) {
448 <                struct nlist symbols[] = {
449 <                        { "_uvmexp" },
438 <                        { NULL }
439 <                };
440 <
441 <                if (kvm_nlist(kvmd, symbols) != 0) {
442 <                        return NULL;
443 <                }
444 <                addr = symbols[0].n_value;
447 >        uvm = realloc(uvm, size);
448 >        if (uvm == NULL) {
449 >                return NULL;
450          }
451  
452 <        if (kvm_read(kvmd, addr, &uvm, sizeof uvm) != sizeof uvm) {
452 >        if (sysctl(mib, 2, uvm, &size, NULL, 0) < 0) {
453                  return NULL;
454          }
455 <        return &uvm;
455 >
456 >        return uvm;
457   }
458   #endif
459  
# Line 469 | Line 475 | int statgrab_init(){
475           * will still work, just no disk mappings. So we will ignore the exit
476           * status of this, and carry on merrily.
477           */
478 < #ifdef(HAVE_LIBDEVINFO_H)
478 > #ifdef HAVE_LIBDEVINFO_H
479          build_mapping();
480   #endif
481   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines