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.29 by tdb, Sat Feb 14 12:38:18 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines