1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
--- src/stats-bsd.c.orig Sat Nov 30 03:27:16 2002
+++ src/stats-bsd.c Wed Dec 18 03:28:16 2002
@@ -64,6 +64,8 @@
#include "locale.h" /* gettext */
+void logcalc(char *, char *);
+
/**
* @desc Verbose level 2 logging of calulations
*/
@@ -81,12 +83,13 @@
void
initCPU(char *cpu)
{
- char buf[CPU_SIZE] = "";
static int initialized = 0;
- size_t size;
- int mib[2];
if (!initialized) {
+ char buf[CPU_SIZE] = "";
+ size_t size;
+ int mib[2];
+
initialized = 1;
mib[0] = CTL_HW;
@@ -98,7 +101,6 @@
if (sysctl(mib, 2, buf, &size, NULL, 0) == -1) {
uplog(LOG_WARNING, "sysctl: hw.model");
- /* warn("sysctl: hw.model"); */
}
strlcpy(cpu, buf, CPU_SIZE);
logcalc(_("CPU"), cpu);
@@ -154,7 +156,6 @@
err(1, "sysctl: kern.boottime");
}
boottimesecs = boottime.tv_sec;
- /* logcalc(_("boot time"), boottimesecs); */
#if defined DEBUG
uplog(LOG_DEBUG, "initBoottime() initialized %d", boottimesecs);
#endif /* DEBUG */
@@ -173,19 +174,18 @@
_("%s %s not implemented for this operating system %s"),
_("WARNING:"), _("Load-average"), strerror(errno));
cfg_SendUsage = 0;
- return;
}
else if (loads < 0) {
uplog(LOG_WARNING, _("%s Could not get load-average %s"), _("WARNING:"),
strerror(errno));
- return;
}
-
- /* Use the 3rd element (15 minute Load-average) */
- *loadavg = loadavgs[2];
+ else {
+ /* Use the 3rd element (15 minute Load-average) */
+ *loadavg = loadavgs[2];
#if defined DEBUG
- uplog(LOG_DEBUG, "getLoadavg() %.2f", *loadavg);
+ uplog(LOG_DEBUG, "getLoadavg() %.2f", *loadavg);
#endif /* DEBUG */
+ }
}
#if !defined __MACH__ /* Mach kernel stuff is in stats-mach.c */
@@ -245,7 +245,7 @@
for (state = 0; state < CPUSTATES; state++) {
time += ctime[state] - stime[state];
- if (!(state == CPU_STATE_IDLE)) {
+ if (!(state == CP_IDLE)) {
nonidlecpu += (float)(ctime[state] - stime[state]);
}
}
@@ -258,6 +258,10 @@
for (state = 0; state < CPUSTATES; state++)
stime[state] = ctime[state];
+#if defined DEBUG
+ uplog(LOG_DEBUG, "getLoadIdle() load=%.1f idle=%.1f", *UsagePercent,
+ *IdlePercent);
+#endif /* DEBUG */
}
}
else {
@@ -268,17 +272,13 @@
cfg_SendUsage = 0;
cfg_SendIdle = 0;
}
-#if defined DEBUG
- uplog(LOG_DEBUG, "getLoadIdle() load=%.1f idle=%.1f", *UsagePercent,
- *IdlePercent);
-#endif /* DEBUG */
}
#endif /* !__MACH__ */
void
getUptime(unsigned long *uptimeminutes)
{
- static time_t boottimesecs;
+ time_t boottimesecs;
boottimesecs = initBoottime();
@@ -293,7 +293,7 @@
#endif /* DEBUG */
}
else {
- uplog(LOG_INFO, _("%s: %s failed"), _("ERROR:"),
+ uplog(LOG_ERR, _("%s %s failed"), _("ERROR:"),
"getUptime() boottime.tv_sec");
}
}
@@ -306,19 +306,18 @@
double *IdlePercent, char *osname, char *osversion, char *cpu,
double *loadavg)
{
- getUptime(&*uptimeminutes);
+ getUptime(uptimeminutes);
if (cfg_SendUsage || cfg_SendIdle)
- getLoadIdle(&*UsagePercent, &*IdlePercent);
+ getLoadIdle(UsagePercent, IdlePercent);
if (cfg_sendosname || cfg_sendosversion)
- initOS(&*osname, &*osversion);
+ initOS(osname, osversion);
if (cfg_sendcpu)
- initCPU(&*cpu);
-
- /* if (cfg_sendloadavg) */
- getLoadavg(&*loadavg);
+ initCPU(cpu);
+ if (cfg_sendloadavg)
+ getLoadavg(loadavg);
}
#endif /* PLATFORM_BSD */
|