1 |
|
/* |
2 |
|
* i-scream central monitoring system |
3 |
< |
* http://www.i-scream.org.uk |
4 |
< |
* Copyright (C) 2000-2002 i-scream |
3 |
> |
* http://www.i-scream.org |
4 |
> |
* Copyright (C) 2000-2003 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 |
24 |
|
|
25 |
|
#include <sys/utsname.h> |
26 |
|
#include "statgrab.h" |
27 |
+ |
#include <stdlib.h> |
28 |
|
#ifdef SOLARIS |
29 |
|
#include <kstat.h> |
30 |
|
#include <time.h> |
32 |
|
#ifdef LINUX |
33 |
|
#include <stdio.h> |
34 |
|
#endif |
35 |
+ |
#ifdef ALLBSD |
36 |
+ |
#ifdef FREEBSD |
37 |
+ |
#include <sys/types.h> |
38 |
+ |
#include <sys/sysctl.h> |
39 |
+ |
#else |
40 |
+ |
#include <sys/param.h> |
41 |
+ |
#include <sys/sysctl.h> |
42 |
+ |
#endif |
43 |
+ |
#include <time.h> |
44 |
+ |
#include <sys/time.h> |
45 |
+ |
#endif |
46 |
|
|
47 |
|
general_stat_t *get_general_stats(){ |
48 |
|
|
58 |
|
#ifdef LINUX |
59 |
|
FILE *f; |
60 |
|
#endif |
61 |
+ |
#ifdef ALLBSD |
62 |
+ |
int mib[2]; |
63 |
+ |
struct timeval boottime; |
64 |
+ |
time_t curtime; |
65 |
+ |
size_t size; |
66 |
+ |
#endif |
67 |
|
|
68 |
|
if((uname(&os)) < 0){ |
69 |
|
return NULL; |
99 |
|
#ifdef LINUX |
100 |
|
if ((f=fopen("/proc/uptime", "r")) == NULL) { |
101 |
|
return NULL; |
102 |
+ |
size = sizeof boottime; |
103 |
|
} |
104 |
|
if((fscanf(f,"%lu %*d",&general_stat.uptime)) != 1){ |
105 |
|
return NULL; |
106 |
|
} |
107 |
|
fclose(f); |
108 |
+ |
#endif |
109 |
+ |
#ifdef ALLBSD |
110 |
+ |
mib[0] = CTL_KERN; |
111 |
+ |
mib[1] = KERN_BOOTTIME; |
112 |
+ |
size = sizeof boottime; |
113 |
+ |
if (sysctl(mib, 2, &boottime, &size, NULL, 0) < 0){ |
114 |
+ |
return NULL; |
115 |
+ |
} |
116 |
+ |
time(&curtime); |
117 |
+ |
general_stat.uptime=curtime-boottime.tv_sec; |
118 |
|
#endif |
119 |
|
|
120 |
|
return &general_stat; |