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 |
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> |
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; |
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; |
201 |
|
return 0; |
202 |
|
} |
203 |
|
|
204 |
+ |
|
205 |
+ |
#define BIG_ENOUGH 512 |
206 |
|
int build_mapping(){ |
207 |
< |
char device_name[512]; |
207 |
> |
char device_name[BIG_ENOUGH]; |
208 |
|
int x; |
209 |
|
kstat_ctl_t *kc; |
210 |
|
kstat_t *ksp; |
211 |
|
kstat_io_t kios; |
212 |
|
|
213 |
+ |
char driver_list[BIG_ENOUGH][BIG_ENOUGH]; |
214 |
+ |
int list_entries = 0; |
215 |
+ |
int found; |
216 |
+ |
|
217 |
|
if ((kc = kstat_open()) == NULL) { |
218 |
|
return; |
219 |
|
} |
230 |
|
} |
231 |
|
if(x == sizeof device_name) x--; |
232 |
|
device_name[x] = '\0'; |
233 |
< |
if((get_alias(device_name)) != 0){ |
234 |
< |
return 1; |
233 |
> |
|
234 |
> |
/* Check if we've not already looked it up */ |
235 |
> |
found = 0; |
236 |
> |
for(x=0;x<list_entries;x++){ |
237 |
> |
if (x>=BIG_ENOUGH){ |
238 |
> |
/* We've got bigger than we thought was massive */ |
239 |
> |
/* If we hit this.. Make big enough bigger */ |
240 |
> |
return 1; |
241 |
> |
} |
242 |
> |
if( !strncmp(driver_list[x], device_name, BIG_ENOUGH)){ |
243 |
> |
found = 1; |
244 |
> |
break; |
245 |
> |
} |
246 |
|
} |
247 |
+ |
|
248 |
+ |
if(!found){ |
249 |
+ |
if((get_alias(device_name)) != 0){ |
250 |
+ |
return 1; |
251 |
+ |
} |
252 |
+ |
strncpy(driver_list[x], device_name, BIG_ENOUGH); |
253 |
+ |
list_entries++; |
254 |
+ |
} |
255 |
|
} |
256 |
|
} |
257 |
|
|
308 |
|
#endif |
309 |
|
|
310 |
|
#ifndef HAVE_STRLCPY |
311 |
< |
* $OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $ */ |
311 |
> |
/* $OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $ */ |
312 |
|
|
313 |
|
/* |
314 |
|
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> |
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 |
|
|
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" }, |
410 |
< |
{ NULL } |
411 |
< |
}; |
412 |
< |
|
413 |
< |
if (kvm_nlist(kvmd, symbols) != 0) { |
414 |
< |
return NULL; |
415 |
< |
} |
416 |
< |
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 |
|
} |
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 |
|
} |