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.20 by pajs, Fri Jan 9 16:37:08 2004 UTC vs.
Revision 1.28 by ats, Fri Feb 13 15:22:49 2004 UTC

# Line 1 | Line 1
1 < /*
1 > /*
2   * i-scream central monitoring system
3   * http://www.i-scream.org
4 < * Copyright (C) 2000-2003 i-scream
4 > * Copyright (C) 2000-2004 i-scream
5   *
6 < * This program is free software; you can redistribute it and/or
7 < * modify it under the terms of the GNU General Public License
8 < * as published by the Free Software Foundation; either version 2
9 < * of the License, or (at your option) any later version.
6 > * This library is free software; you can redistribute it and/or
7 > * modify it under the terms of the GNU Lesser General Public
8 > * License as published by the Free Software Foundation; either
9 > * version 2.1 of the License, or (at your option) any later version.
10   *
11 < * This program is distributed in the hope that it will be useful,
11 > * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 < * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 < * GNU General Public License for more details.
13 > * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 > * Lesser General Public License for more details.
15   *
16 < * You should have received a copy of the GNU General Public License
17 < * along with this program; if not, write to the Free Software
18 < * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16 > * You should have received a copy of the GNU Lesser General Public
17 > * License along with this library; if not, write to the Free Software
18 > * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 > * 02111-1307 USA
20 > *
21 > * $Id$
22   */
23  
24   #ifdef HAVE_CONFIG_H
# Line 32 | 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 51 | Line 58
58   #include <dirent.h>
59   #endif
60  
61 < #ifdef SOLARIS
61 > #if defined(SOLARIS) && defined(HAVE_LIBDEVINFO_H)
62   struct map{
63          char *bsd;
64          char *svr;
# Line 61 | 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 187 | Line 199 | int get_alias(char *alias){
199          return 0;
200   }
201  
202 +
203 + #define BIG_ENOUGH 512
204   int build_mapping(){
205 <        char device_name[512];
205 >        char device_name[BIG_ENOUGH];
206          int x;
207          kstat_ctl_t *kc;
208          kstat_t *ksp;
209          kstat_io_t kios;
210  
211 +        char driver_list[BIG_ENOUGH][BIG_ENOUGH];
212 +        int list_entries = 0;
213 +        int found;
214 +
215          if ((kc = kstat_open()) == NULL) {
216                  return;
217          }
# Line 210 | Line 228 | int build_mapping(){
228                          }
229                          if(x == sizeof device_name) x--;
230                          device_name[x] = '\0';
231 <                        if((get_alias(device_name)) != 0){
232 <                                return 1;
231 >
232 >                        /* Check if we've not already looked it up */
233 >                        found = 0;
234 >                        for(x=0;x<list_entries;x++){
235 >                                if (x>=BIG_ENOUGH){
236 >                                        /* We've got bigger than we thought was massive */
237 >                                        /* If we hit this.. Make big enough bigger */
238 >                                        return 1;
239 >                                }
240 >                                if( !strncmp(driver_list[x], device_name, BIG_ENOUGH)){
241 >                                        found = 1;
242 >                                        break;
243 >                                }
244                          }
245 +
246 +                        if(!found){
247 +                                if((get_alias(device_name)) != 0){
248 +                                        return 1;
249 +                                }
250 +                                strncpy(driver_list[x], device_name, BIG_ENOUGH);
251 +                                list_entries++;
252 +                        }
253                  }
254          }
255  
# Line 269 | Line 306 | static long long atoll(const char *s) {
306   #endif
307  
308   #ifndef HAVE_STRLCPY
309 < *      $OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $     */
309 > /*      $OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $     */
310  
311   /*
312   * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
# Line 394 | 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" },
410 <                        { NULL }
411 <                };
412 <
413 <                if (kvm_nlist(kvmd, symbols) != 0) {
414 <                        return NULL;
415 <                }
416 <                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 441 | 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
479          build_mapping();
480 + #endif
481   #endif
482          return 0;
483   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines