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.34 by tdb, Sun Apr 4 22:09:32 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   #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 > #if (defined(FREEBSD) && !defined(FREEBSD5)) || defined(DFBSD)
424   kvm_t *get_kvm() {
425          static kvm_t *kvmd = NULL;
426  
# Line 420 | Line 431 | kvm_t *get_kvm() {
431          kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, NULL);
432          return kvmd;
433   }
434 +
435 + /* Can't think of a better name for this function */
436 + kvm_t *get_kvm2() {
437 +        static kvm_t *kvmd2 = NULL;
438 +
439 +        if (kvmd2 != NULL) {
440 +                return kvmd2;
441 +        }
442 +
443 +        kvmd2 = kvm_openfiles(_PATH_DEVNULL, _PATH_DEVNULL, NULL, O_RDONLY, NULL);
444 +        return kvmd2;
445 + }
446   #endif
447  
448 < #ifdef NETBSD
448 > #if defined(NETBSD) || defined(OPENBSD)
449   struct uvmexp *get_uvmexp() {
450 <        static u_long addr = 0;
451 <        static struct uvmexp uvm;
452 <        kvm_t *kvmd = get_kvm();
450 >        int mib[2];
451 >        size_t size;
452 >        static struct uvmexp *uvm = NULL;
453  
454 <        if (kvmd == NULL) {
454 >        mib[0] = CTL_VM;
455 >        mib[1] = VM_UVMEXP;
456 >
457 >        if (sysctl(mib, 2, NULL, &size, NULL, 0) < 0) {
458                  return NULL;
459          }
460  
461 <        if (addr == 0) {
462 <                struct nlist symbols[] = {
463 <                        { "_uvmexp" },
438 <                        { NULL }
439 <                };
440 <
441 <                if (kvm_nlist(kvmd, symbols) != 0) {
442 <                        return NULL;
443 <                }
444 <                addr = symbols[0].n_value;
461 >        uvm = realloc(uvm, size);
462 >        if (uvm == NULL) {
463 >                return NULL;
464          }
465  
466 <        if (kvm_read(kvmd, addr, &uvm, sizeof uvm) != sizeof uvm) {
466 >        if (sysctl(mib, 2, uvm, &size, NULL, 0) < 0) {
467                  return NULL;
468          }
469 <        return &uvm;
469 >
470 >        return uvm;
471   }
472   #endif
473  
474   int statgrab_init(){
475 < #ifdef ALLBSD
475 > #if (defined(FREEBSD) && !defined(FREEBSD5)) || defined(DFBSD)
476          {
477                  kvm_t *kvmd = get_kvm();
478                  if (kvmd == NULL) return 1;
479          }
480 +        {
481 +                kvm_t *kvmd2 = get_kvm2();
482 +                if (kvmd2 == NULL) return 1;
483 +        }
484   #endif
485 < #ifdef NETBSD
485 > #if defined(NETBSD) || defined(OPENBSD)
486          {
487 +                /* This should always succeed, but it seems that on some
488 +                 * versions of NetBSD the first call to get_uvmexp will return
489 +                 * a non-filled-in structure; this is a workaround for that.
490 +                 */
491                  struct uvmexp *uvm = get_uvmexp();
492                  if (uvm == NULL) return 1;
493          }
# Line 469 | Line 497 | int statgrab_init(){
497           * will still work, just no disk mappings. So we will ignore the exit
498           * status of this, and carry on merrily.
499           */
500 + #ifdef HAVE_LIBDEVINFO_H
501          build_mapping();
502 + #endif
503   #endif
504          return 0;
505   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines