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 |
+ |
#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> |
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; |
420 |
|
return num; |
421 |
|
} |
422 |
|
|
423 |
< |
#ifdef ALLBSD |
423 |
> |
#ifdef FREEBSD |
424 |
|
kvm_t *get_kvm() { |
425 |
|
static kvm_t *kvmd = NULL; |
426 |
|
|
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" }, |
435 |
< |
{ NULL } |
436 |
< |
}; |
437 |
< |
|
438 |
< |
if (kvm_nlist(kvmd, symbols) != 0) { |
439 |
< |
return NULL; |
440 |
< |
} |
441 |
< |
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; |
467 |
|
} |
468 |
|
#endif |
458 |
– |
#ifdef NETBSD |
459 |
– |
{ |
460 |
– |
struct uvmexp *uvm = get_uvmexp(); |
461 |
– |
if (uvm == NULL) return 1; |
462 |
– |
} |
463 |
– |
#endif |
469 |
|
#ifdef SOLARIS |
470 |
|
/* On solaris 7, this will fail if you are not root. But, everything |
471 |
|
* will still work, just no disk mappings. So we will ignore the exit |
472 |
|
* status of this, and carry on merrily. |
473 |
|
*/ |
474 |
+ |
#ifdef HAVE_LIBDEVINFO_H |
475 |
|
build_mapping(); |
476 |
+ |
#endif |
477 |
|
#endif |
478 |
|
return 0; |
479 |
|
} |