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> |
31 |
|
#endif |
32 |
< |
#ifdef LINUX |
32 |
> |
#if defined(LINUX) || defined(CYGWIN) |
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 |
55 |
|
kstat_t *ksp; |
56 |
|
kstat_named_t *kn; |
57 |
|
#endif |
58 |
< |
#ifdef LINUX |
58 |
> |
#if defined(LINUX) || defined(CYGWIN) |
59 |
|
FILE *f; |
60 |
|
#endif |
61 |
< |
#ifdef FREEBSD |
61 |
> |
#ifdef ALLBSD |
62 |
> |
int mib[2]; |
63 |
|
struct timeval boottime; |
64 |
|
time_t curtime; |
65 |
|
size_t size; |
96 |
|
time(&curtime); |
97 |
|
general_stat.uptime = curtime - boottime; |
98 |
|
#endif |
99 |
< |
#ifdef LINUX |
99 |
> |
#if defined(LINUX) || defined(CYGWIN) |
100 |
|
if ((f=fopen("/proc/uptime", "r")) == NULL) { |
101 |
|
return NULL; |
102 |
|
} |
105 |
|
} |
106 |
|
fclose(f); |
107 |
|
#endif |
108 |
< |
#ifdef FREEBSD |
109 |
< |
if (sysctlbyname("kern.boottime", &boottime, &size, NULL, 0) < 0){ |
108 |
> |
#ifdef ALLBSD |
109 |
> |
mib[0] = CTL_KERN; |
110 |
> |
mib[1] = KERN_BOOTTIME; |
111 |
> |
size = sizeof boottime; |
112 |
> |
if (sysctl(mib, 2, &boottime, &size, NULL, 0) < 0){ |
113 |
|
return NULL; |
114 |
|
} |
115 |
|
time(&curtime); |