1 |
|
/* |
2 |
< |
* i-scream central monitoring system |
2 |
> |
* i-scream libstatgrab |
3 |
|
* http://www.i-scream.org |
4 |
|
* Copyright (C) 2000-2004 i-scream |
5 |
|
* |
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 |
36 |
|
#include <stdio.h> |
37 |
|
#endif |
38 |
|
#ifdef ALLBSD |
39 |
< |
#ifdef FREEBSD |
39 |
> |
#if defined(FREEBSD) || defined(DFBSD) |
40 |
|
#include <sys/types.h> |
41 |
|
#include <sys/sysctl.h> |
42 |
|
#else |
46 |
|
#include <time.h> |
47 |
|
#include <sys/time.h> |
48 |
|
#endif |
49 |
+ |
#ifdef HPUX |
50 |
+ |
#include <sys/param.h> |
51 |
+ |
#include <sys/pstat.h> |
52 |
+ |
#include <time.h> |
53 |
+ |
#endif |
54 |
|
|
55 |
< |
general_stat_t *get_general_stats(){ |
55 |
> |
#include "tools.h" |
56 |
|
|
57 |
< |
static general_stat_t general_stat; |
57 |
> |
sg_host_info *sg_get_host_info(){ |
58 |
> |
|
59 |
> |
static sg_host_info general_stat; |
60 |
|
static struct utsname os; |
61 |
|
|
62 |
+ |
#ifdef HPUX |
63 |
+ |
struct pst_static *pstat_static; |
64 |
+ |
time_t currtime; |
65 |
+ |
long boottime; |
66 |
+ |
#endif |
67 |
|
#ifdef SOLARIS |
68 |
|
time_t boottime,curtime; |
69 |
|
kstat_ctl_t *kc; |
81 |
|
#endif |
82 |
|
|
83 |
|
if((uname(&os)) < 0){ |
84 |
+ |
sg_set_error_with_errno(SG_ERROR_UNAME, NULL); |
85 |
|
return NULL; |
86 |
|
} |
87 |
|
|
88 |
|
general_stat.os_name = os.sysname; |
89 |
< |
general_stat.os_release = os.release; |
90 |
< |
general_stat.os_version = os.version; |
91 |
< |
general_stat.platform = os.machine; |
92 |
< |
general_stat.hostname = os.nodename; |
89 |
> |
general_stat.os_release = os.release; |
90 |
> |
general_stat.os_version = os.version; |
91 |
> |
general_stat.platform = os.machine; |
92 |
> |
general_stat.hostname = os.nodename; |
93 |
|
|
94 |
|
/* get uptime */ |
95 |
+ |
#ifdef HPUX |
96 |
+ |
pstat_static = sg_get_pstat_static(); |
97 |
+ |
if (pstat_static == NULL) { |
98 |
+ |
return NULL; |
99 |
+ |
} |
100 |
+ |
|
101 |
+ |
currtime = time(NULL); |
102 |
+ |
|
103 |
+ |
boottime = pstat_static->boot_time; |
104 |
+ |
|
105 |
+ |
general_stat.uptime = currtime - boottime; |
106 |
+ |
#endif |
107 |
|
#ifdef SOLARIS |
108 |
|
if ((kc = kstat_open()) == NULL) { |
109 |
+ |
sg_set_error(SG_ERROR_KSTAT_OPEN, NULL); |
110 |
|
return NULL; |
111 |
|
} |
112 |
|
if((ksp=kstat_lookup(kc, "unix", -1, "system_misc"))==NULL){ |
113 |
+ |
sg_set_error(SG_ERROR_KSTAT_LOOKUP, "unix,-1,system_misc"); |
114 |
|
return NULL; |
115 |
|
} |
116 |
|
if (kstat_read(kc, ksp, 0) == -1) { |
117 |
+ |
sg_set_error(SG_ERROR_KSTAT_READ, NULL); |
118 |
|
return NULL; |
119 |
|
} |
120 |
|
if((kn=kstat_data_lookup(ksp, "boot_time")) == NULL){ |
121 |
+ |
sg_set_error(SG_ERROR_KSTAT_DATA_LOOKUP, "boot_time"); |
122 |
|
return NULL; |
123 |
|
} |
124 |
|
boottime=(kn->value.ui32); |
130 |
|
#endif |
131 |
|
#if defined(LINUX) || defined(CYGWIN) |
132 |
|
if ((f=fopen("/proc/uptime", "r")) == NULL) { |
133 |
+ |
sg_set_error_with_errno(SG_ERROR_OPEN, "/proc/uptime"); |
134 |
|
return NULL; |
135 |
|
} |
136 |
|
if((fscanf(f,"%lu %*d",&general_stat.uptime)) != 1){ |
137 |
+ |
sg_set_error(SG_ERROR_PARSE, NULL); |
138 |
|
return NULL; |
139 |
|
} |
140 |
|
fclose(f); |
144 |
|
mib[1] = KERN_BOOTTIME; |
145 |
|
size = sizeof boottime; |
146 |
|
if (sysctl(mib, 2, &boottime, &size, NULL, 0) < 0){ |
147 |
+ |
sg_set_error_with_errno(SG_ERROR_SYSCTL, |
148 |
+ |
"CTL_KERN.KERN_BOOTTIME"); |
149 |
|
return NULL; |
150 |
|
} |
151 |
|
time(&curtime); |