Bug Summary

File:rc/client.c
Location:line 652, column 24
Description:The left operand of '==' is a garbage value

Annotated Source Code

1/* GKrellM
2| Copyright (C) 1999-2010 Bill Wilson
3|
4| Author: Bill Wilson billw@gkrellm.net
5| Latest versions might be found at: http://gkrellm.net
6|
7|
8| GKrellM is free software: you can redistribute it and/or modify it
9| under the terms of the GNU General Public License as published by
10| the Free Software Foundation, either version 3 of the License, or
11| (at your option) any later version.
12|
13| GKrellM is distributed in the hope that it will be useful, but WITHOUT
14| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15| or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16| License for more details.
17|
18| You should have received a copy of the GNU General Public License
19| along with this program. If not, see http://www.gnu.org/licenses/
20|
21|
22| Additional permission under GNU GPL version 3 section 7
23|
24| If you modify this program, or any covered work, by linking or
25| combining it with the OpenSSL project's OpenSSL library (or a
26| modified version of that library), containing parts covered by
27| the terms of the OpenSSL or SSLeay licenses, you are granted
28| additional permission to convey the resulting work.
29| Corresponding Source for a non-source form of such a combination
30| shall include the source code for the parts of OpenSSL used as well
31| as that of the covered work.
32*/
33
34
35#include "gkrellm.h"
36#include "gkrellm-private.h"
37#include "gkrellm-sysdeps.h"
38
39#include <inttypes.h>
40
41#if !defined(WIN32)
42#include <sys/socket.h>
43#include <utime.h>
44#include <sys/time.h>
45#include <netinet/in.h>
46#include <arpa/inet.h>
47#include <netdb.h>
48#else
49#include <winsock2.h>
50#include <ws2tcpip.h>
51#endif
52
53#include <errno(*__errno_location ()).h>
54
55
56
57#if defined(__linux__1)
58#if defined(__GLIBC__2) && ((__GLIBC__2>2)||(__GLIBC__2==2 && __GLIBC_MINOR__19>=1))
59#define HAVE_GETADDRINFO1 1
60#endif
61#endif
62
63#if defined(__DragonFly__)
64#define HAVE_GETADDRINFO1 1
65#endif
66
67#if defined(__FreeBSD__)
68#if __FreeBSD_version >= 400000
69#define HAVE_GETADDRINFO1 1
70#endif
71#endif
72
73#if defined(__OpenBSD__)
74#define HAVE_GETADDRINFO1 1
75#endif
76
77#if defined(__NetBSD__)
78#define HAVE_GETADDRINFO1 1
79#endif
80
81#if defined(__solaris__)
82/* getaddrinfo is related to IPv6 stuff */
83# include <netconfig.h>
84# if defined(NC_INET6)
85# define HAVE_GETADDRINFO1 1
86# endif
87#endif
88
89
90typedef struct
91 {
92 gchar *key;
93 void (*func)();
94 }
95 KeyTable;
96
97static gint server_major_version,
98 server_minor_version,
99 server_rev_version;
100
101static gint client_input_id,
102 client_fd;
103static gboolean server_alive;
104
105static gchar server_buf[4097]; /* TODO: Use dynamic receive buffer */
106static gint buf_index;
107
108static gchar locale_decimal_point;
109static gchar server_decimal_point = '.';
110static gboolean need_locale_fix = FALSE(0);
111
112
113gboolean
114gkrellm_client_check_server_version(gint major, gint minor, gint rev)
115 {
116 if ( server_major_version > major
117 || (server_major_version == major && server_minor_version > minor)
118 || ( server_major_version == major && server_minor_version == minor
119 && server_rev_version >= rev
120 )
121 )
122 return TRUE(!(0));
123 return FALSE(0);
124 }
125
126
127 /* There can be a locale decimal point mismatch with the server.
128 */
129static void
130locale_fix(gchar *buf)
131 {
132 gchar *s;
133
134 for (s = buf; *s; ++s)
135 if (*s == server_decimal_point)
136 *s = locale_decimal_point;
137 }
138
139
140/* ================================================================= */
141/* CPU */
142
143typedef struct
144 {
145 gint instance;
146 gulong user,
147 nice,
148 sys,
149 idle;
150 }
151 Cpu;
152
153static GList *cpu_list,
154 *instance_list;
155static gint n_cpus = 1;
156static gboolean nice_time_supported = TRUE(!(0));
157
158static void
159client_cpu_line_from_server(gchar *line)
160 {
161 GList *list;
162 Cpu *cpu = NULL((void*)0);
163 gint n;
164 guint64 user, nice, sys, idle;
165
166 sscanf(line, "%d %" PRIu64"l" "u" " %" PRIu64"l" "u" " %" PRIu64"l" "u" " %" PRIu64"l" "u", &n, &user, &nice, &sys, &idle);
167 for (list = cpu_list; list; list = list->next)
168 {
169 cpu = (Cpu *) list->data;
170 if (cpu->instance == n)
171 break;
172 }
173 if (list)
174 {
175 cpu->user = user;
176 cpu->nice = nice;
177 cpu->sys = sys;
178 cpu->idle = idle;
179 }
180 }
181
182static void
183cpu_read_data(void)
184 {
185 Cpu *cpu;
186 GList *list;
187
188 for (list = cpu_list; list; list = list->next)
189 {
190 cpu = (Cpu *) list->data;
191 gkrellm_cpu_assign_data(cpu->instance, cpu->user, cpu->nice,
192 cpu->sys, cpu->idle);
193 }
194 }
195
196static void
197client_sys_cpu_init(void)
198 {
199 GList *list;
200 Cpu *cpu;
201 gint n;
202
203 /* Do initialization based on info received in client_cpu_setup(). Here
204 | we need to get the same effective work done as would be done in the
205 | sysdep gkrellm_sys_cpu_init() when not running in client mode.
206 */
207 for (n = 0; n < n_cpus; ++ n)
208 {
209 cpu = g_new0(Cpu, 1)(Cpu *) (__extension__ ({ gsize __n = (gsize) (1); gsize __s =
sizeof (Cpu); gpointer __p; if (__s == 1) __p = g_malloc0 (__n
); else if (__builtin_constant_p (__n) && (__s == 0 ||
__n <= (9223372036854775807L *2UL+1UL) / __s)) __p = g_malloc0
(__n * __s); else __p = g_malloc0_n (__n, __s); __p; }))
;
210 if (instance_list && (list = g_list_nth(instance_list, n)) != NULL((void*)0))
211 {
212 cpu->instance = GPOINTER_TO_INT(list->data)((gint) (glong) (list->data));
213 gkrellm_cpu_add_instance(cpu->instance);
214 }
215 else
216 cpu->instance = n;
217 cpu_list = g_list_append(cpu_list, cpu);
218 }
219 gkrellm_cpu_set_number_of_cpus(n_cpus);
220 if (!nice_time_supported)
221 gkrellm_cpu_nice_time_unsupported();
222
223 /* Diverting the cpu_read_data function in cpu.c causes the cpu monitor
224 | to not call the gkrellm_sys_cpu_init() sysdep function and also to call
225 | our client cpu_read_data function instead of gkrellm_sys_cpu_read_data()
226 */
227 gkrellm_cpu_client_divert(cpu_read_data);
228 }
229
230static void
231client_cpu_setup(gchar *line)
232 {
233 gint instance;
234
235 if (!strncmp(line, "n_cpus", 6)(__extension__ (__builtin_constant_p (6) && ((__builtin_constant_p
(line) && strlen (line) < ((size_t) (6))) || (__builtin_constant_p
("n_cpus") && strlen ("n_cpus") < ((size_t) (6)))
) ? __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(line) && __builtin_constant_p ("n_cpus") &&
(__s1_len = strlen (line), __s2_len = strlen ("n_cpus"), (!(
(size_t)(const void *)((line) + 1) - (size_t)(const void *)(line
) == 1) || __s1_len >= 4) && (!((size_t)(const void
*)(("n_cpus") + 1) - (size_t)(const void *)("n_cpus") == 1) ||
__s2_len >= 4)) ? __builtin_strcmp (line, "n_cpus") : (__builtin_constant_p
(line) && ((size_t)(const void *)((line) + 1) - (size_t
)(const void *)(line) == 1) && (__s1_len = strlen (line
), __s1_len < 4) ? (__builtin_constant_p ("n_cpus") &&
((size_t)(const void *)(("n_cpus") + 1) - (size_t)(const void
*)("n_cpus") == 1) ? __builtin_strcmp (line, "n_cpus") : (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) ("n_cpus"); int __result = (((const unsigned char *)
(const char *) (line))[0] - __s2[0]); if (__s1_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (line))[1] - __s2[1]); if (__s1_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (line))[2] - __s2[2]); if (__s1_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) (line))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p
("n_cpus") && ((size_t)(const void *)(("n_cpus") + 1
) - (size_t)(const void *)("n_cpus") == 1) && (__s2_len
= strlen ("n_cpus"), __s2_len < 4) ? (__builtin_constant_p
(line) && ((size_t)(const void *)((line) + 1) - (size_t
)(const void *)(line) == 1) ? __builtin_strcmp (line, "n_cpus"
) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (line); int __result = (((const unsigned
char *) (const char *) ("n_cpus"))[0] - __s2[0]); if (__s2_len
> 0 && __result == 0) { __result = (((const unsigned
char *) (const char *) ("n_cpus"))[1] - __s2[1]); if (__s2_len
> 1 && __result == 0) { __result = (((const unsigned
char *) (const char *) ("n_cpus"))[2] - __s2[2]); if (__s2_len
> 2 && __result == 0) __result = (((const unsigned
char *) (const char *) ("n_cpus"))[3] - __s2[3]); } } __result
; })))) : __builtin_strcmp (line, "n_cpus")))); }) : strncmp (
line, "n_cpus", 6)))
)
236 sscanf(line, "%*s %d", &n_cpus);
237 else if (!strncmp(line, "cpu_instance", 12)(__extension__ (__builtin_constant_p (12) && ((__builtin_constant_p
(line) && strlen (line) < ((size_t) (12))) || (__builtin_constant_p
("cpu_instance") && strlen ("cpu_instance") < ((size_t
) (12)))) ? __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(line) && __builtin_constant_p ("cpu_instance") &&
(__s1_len = strlen (line), __s2_len = strlen ("cpu_instance"
), (!((size_t)(const void *)((line) + 1) - (size_t)(const void
*)(line) == 1) || __s1_len >= 4) && (!((size_t)(const
void *)(("cpu_instance") + 1) - (size_t)(const void *)("cpu_instance"
) == 1) || __s2_len >= 4)) ? __builtin_strcmp (line, "cpu_instance"
) : (__builtin_constant_p (line) && ((size_t)(const void
*)((line) + 1) - (size_t)(const void *)(line) == 1) &&
(__s1_len = strlen (line), __s1_len < 4) ? (__builtin_constant_p
("cpu_instance") && ((size_t)(const void *)(("cpu_instance"
) + 1) - (size_t)(const void *)("cpu_instance") == 1) ? __builtin_strcmp
(line, "cpu_instance") : (__extension__ ({ const unsigned char
*__s2 = (const unsigned char *) (const char *) ("cpu_instance"
); int __result = (((const unsigned char *) (const char *) (line
))[0] - __s2[0]); if (__s1_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) (line
))[1] - __s2[1]); if (__s1_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (line
))[2] - __s2[2]); if (__s1_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (line))
[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("cpu_instance"
) && ((size_t)(const void *)(("cpu_instance") + 1) - (
size_t)(const void *)("cpu_instance") == 1) && (__s2_len
= strlen ("cpu_instance"), __s2_len < 4) ? (__builtin_constant_p
(line) && ((size_t)(const void *)((line) + 1) - (size_t
)(const void *)(line) == 1) ? __builtin_strcmp (line, "cpu_instance"
) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (line); int __result = (((const unsigned
char *) (const char *) ("cpu_instance"))[0] - __s2[0]); if (
__s2_len > 0 && __result == 0) { __result = (((const
unsigned char *) (const char *) ("cpu_instance"))[1] - __s2[
1]); if (__s2_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) ("cpu_instance"))
[2] - __s2[2]); if (__s2_len > 2 && __result == 0)
__result = (((const unsigned char *) (const char *) ("cpu_instance"
))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (line
, "cpu_instance")))); }) : strncmp (line, "cpu_instance", 12)
))
)
238 {
239 sscanf(line, "%*s %d", &instance);
240 instance_list = g_list_append(instance_list,
241 GINT_TO_POINTER(instance)((gpointer) (glong) (instance)));
242 }
243 else if (!strcmp(line, "nice_time_unsupported")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(line) && __builtin_constant_p ("nice_time_unsupported"
) && (__s1_len = strlen (line), __s2_len = strlen ("nice_time_unsupported"
), (!((size_t)(const void *)((line) + 1) - (size_t)(const void
*)(line) == 1) || __s1_len >= 4) && (!((size_t)(const
void *)(("nice_time_unsupported") + 1) - (size_t)(const void
*)("nice_time_unsupported") == 1) || __s2_len >= 4)) ? __builtin_strcmp
(line, "nice_time_unsupported") : (__builtin_constant_p (line
) && ((size_t)(const void *)((line) + 1) - (size_t)(const
void *)(line) == 1) && (__s1_len = strlen (line), __s1_len
< 4) ? (__builtin_constant_p ("nice_time_unsupported") &&
((size_t)(const void *)(("nice_time_unsupported") + 1) - (size_t
)(const void *)("nice_time_unsupported") == 1) ? __builtin_strcmp
(line, "nice_time_unsupported") : (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) ("nice_time_unsupported"
); int __result = (((const unsigned char *) (const char *) (line
))[0] - __s2[0]); if (__s1_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) (line
))[1] - __s2[1]); if (__s1_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (line
))[2] - __s2[2]); if (__s1_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (line))
[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("nice_time_unsupported"
) && ((size_t)(const void *)(("nice_time_unsupported"
) + 1) - (size_t)(const void *)("nice_time_unsupported") == 1
) && (__s2_len = strlen ("nice_time_unsupported"), __s2_len
< 4) ? (__builtin_constant_p (line) && ((size_t)(
const void *)((line) + 1) - (size_t)(const void *)(line) == 1
) ? __builtin_strcmp (line, "nice_time_unsupported") : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (line); int __result = (((const unsigned char *) (const
char *) ("nice_time_unsupported"))[0] - __s2[0]); if (__s2_len
> 0 && __result == 0) { __result = (((const unsigned
char *) (const char *) ("nice_time_unsupported"))[1] - __s2[
1]); if (__s2_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) ("nice_time_unsupported"
))[2] - __s2[2]); if (__s2_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) ("nice_time_unsupported"
))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (line
, "nice_time_unsupported")))); })
)
244 nice_time_supported = FALSE(0);
245 }
246
247/* ================================================================= */
248static struct
249 {
250 gint n_processes,
251 n_running,
252 n_users;
253 gulong n_forks;
254 gfloat load;
255 }
256 proc;
257
258static void
259client_proc_line_from_server(gchar *line)
260 {
261 if (need_locale_fix)
262 locale_fix(line);
263 sscanf(line, "%d %d %lu %f %d", &proc.n_processes, &proc.n_running,
264 &proc.n_forks, &proc.load, &proc.n_users);
265 }
266
267static void
268read_proc_data(void)
269 {
270 gkrellm_proc_assign_data(proc.n_processes, proc.n_running,
271 proc.n_forks, proc.load);
272 }
273
274static void
275read_user_data(void)
276 {
277 gkrellm_proc_assign_users(proc.n_users);
278 }
279
280static void
281client_sys_proc_init(void)
282 {
283 gkrellm_proc_client_divert(read_proc_data, read_user_data);
284 }
285
286/* ================================================================= */
287typedef struct
288 {
289 gchar *name;
290 gchar *subdisk_parent;
291 guint64 rblk,
292 wblk;
293 gboolean virtual;
294 }
295 DiskData;
296
297static GList *disk_list;
298
299static gboolean units_are_blocks;
300
301static void
302client_disk_line_from_server(gchar *line)
303 {
304 DiskData *disk = NULL((void*)0);
305 GList *list;
306 gchar *name;
307 gchar s1[32], s2[32], s3[32];
308 guint64 rblk, wblk;
309 gint n;
310 gboolean virtual = FALSE(0);
311
312 g_assert(line != NULL)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_
; if (line != ((void*)0)) _g_boolean_var_ = 1; else _g_boolean_var_
= 0; _g_boolean_var_; }), 1)) ; else g_assertion_message_expr
(((gchar*) 0), "client.c", 312, ((const char*) (__func__)), "line != NULL"
); } while (0)
;
313 name = g_malloc(strlen(line) * sizeof(gchar));
314
315 /* FIXME: Extend client and server to support disks with both name and label */
316 n = sscanf(line, "%s %31s %31s %31s", name, s1, s2, s3);
317 if (n == 4)
318 {
319 if ( gkrellm_client_check_server_version(2, 2, 7)
320 && !strcmp(s1, "virtual")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(s1) && __builtin_constant_p ("virtual") && (
__s1_len = strlen (s1), __s2_len = strlen ("virtual"), (!((size_t
)(const void *)((s1) + 1) - (size_t)(const void *)(s1) == 1) ||
__s1_len >= 4) && (!((size_t)(const void *)(("virtual"
) + 1) - (size_t)(const void *)("virtual") == 1) || __s2_len >=
4)) ? __builtin_strcmp (s1, "virtual") : (__builtin_constant_p
(s1) && ((size_t)(const void *)((s1) + 1) - (size_t)
(const void *)(s1) == 1) && (__s1_len = strlen (s1), __s1_len
< 4) ? (__builtin_constant_p ("virtual") && ((size_t
)(const void *)(("virtual") + 1) - (size_t)(const void *)("virtual"
) == 1) ? __builtin_strcmp (s1, "virtual") : (__extension__ (
{ const unsigned char *__s2 = (const unsigned char *) (const char
*) ("virtual"); int __result = (((const unsigned char *) (const
char *) (s1))[0] - __s2[0]); if (__s1_len > 0 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
s1))[1] - __s2[1]); if (__s1_len > 1 && __result ==
0) { __result = (((const unsigned char *) (const char *) (s1
))[2] - __s2[2]); if (__s1_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (s1))[3
] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("virtual"
) && ((size_t)(const void *)(("virtual") + 1) - (size_t
)(const void *)("virtual") == 1) && (__s2_len = strlen
("virtual"), __s2_len < 4) ? (__builtin_constant_p (s1) &&
((size_t)(const void *)((s1) + 1) - (size_t)(const void *)(s1
) == 1) ? __builtin_strcmp (s1, "virtual") : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (s1); int __result = (((const unsigned char *) (const
char *) ("virtual"))[0] - __s2[0]); if (__s2_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ("virtual"))[1] - __s2[1]); if (__s2_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ("virtual"))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) ("virtual"))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp
(s1, "virtual")))); })
321 )
322 {
323 virtual = TRUE(!(0));
324 s1[0] = '\0';
325 }
326 rblk = strtoull(s2, NULL((void*)0), 0);
327 wblk = strtoull(s3, NULL((void*)0), 0);
328 }
329 else if (n == 3)
330 {
331 rblk = strtoull(s1, NULL((void*)0), 0);
332 wblk = strtoull(s2, NULL((void*)0), 0);
333 s1[0] = '\0';
334 }
335 else
336 {
337 g_warning("Invalid disk line received from server: \"%s\"", line);
338 g_free(name);
339 return;
340 }
341
342 for (list = disk_list; list; list = list->next)
343 {
344 /* Search disk in list */
345 disk = (DiskData *) list->data;
346 if (!strcmp(disk->name, name)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(disk->name) && __builtin_constant_p (name) &&
(__s1_len = strlen (disk->name), __s2_len = strlen (name)
, (!((size_t)(const void *)((disk->name) + 1) - (size_t)(const
void *)(disk->name) == 1) || __s1_len >= 4) &&
(!((size_t)(const void *)((name) + 1) - (size_t)(const void *
)(name) == 1) || __s2_len >= 4)) ? __builtin_strcmp (disk->
name, name) : (__builtin_constant_p (disk->name) &&
((size_t)(const void *)((disk->name) + 1) - (size_t)(const
void *)(disk->name) == 1) && (__s1_len = strlen (
disk->name), __s1_len < 4) ? (__builtin_constant_p (name
) && ((size_t)(const void *)((name) + 1) - (size_t)(const
void *)(name) == 1) ? __builtin_strcmp (disk->name, name)
: (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (name); int __result = (((const unsigned
char *) (const char *) (disk->name))[0] - __s2[0]); if (__s1_len
> 0 && __result == 0) { __result = (((const unsigned
char *) (const char *) (disk->name))[1] - __s2[1]); if (__s1_len
> 1 && __result == 0) { __result = (((const unsigned
char *) (const char *) (disk->name))[2] - __s2[2]); if (__s1_len
> 2 && __result == 0) __result = (((const unsigned
char *) (const char *) (disk->name))[3] - __s2[3]); } } __result
; }))) : (__builtin_constant_p (name) && ((size_t)(const
void *)((name) + 1) - (size_t)(const void *)(name) == 1) &&
(__s2_len = strlen (name), __s2_len < 4) ? (__builtin_constant_p
(disk->name) && ((size_t)(const void *)((disk->
name) + 1) - (size_t)(const void *)(disk->name) == 1) ? __builtin_strcmp
(disk->name, name) : (- (__extension__ ({ const unsigned char
*__s2 = (const unsigned char *) (const char *) (disk->name
); int __result = (((const unsigned char *) (const char *) (name
))[0] - __s2[0]); if (__s2_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) (name
))[1] - __s2[1]); if (__s2_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (name
))[2] - __s2[2]); if (__s2_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (name))
[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (disk->
name, name)))); })
)
347 break;
348 }
349 if (!list)
350 {
351 /* Disk wasn't found, create new disk and add to list */
352 disk = g_new0(DiskData, 1)(DiskData *) (__extension__ ({ gsize __n = (gsize) (1); gsize
__s = sizeof (DiskData); gpointer __p; if (__s == 1) __p = g_malloc0
(__n); else if (__builtin_constant_p (__n) && (__s ==
0 || __n <= (9223372036854775807L *2UL+1UL) / __s)) __p =
g_malloc0 (__n * __s); else __p = g_malloc0_n (__n, __s); __p
; }))
;
353 disk->name = g_strdup(name);
354 if (s1[0]) /* I expect server to send in order */
355 disk->subdisk_parent = g_strdup(s1);
356 disk_list = g_list_append(disk_list, disk);
357 }
358 if (disk)
359 {
360 /* Assign parsed data to disk */
361 disk->rblk = rblk;
362 disk->wblk = wblk;
363 disk->virtual = virtual;
364 }
365 g_free(name);
366 }
367
368static void
369read_disk_data(void)
370 {
371 GList *list;
372 DiskData *disk;
373
374 for (list = disk_list; list; list = list->next)
375 {
376 disk = (DiskData *) list->data;
377 if (disk->subdisk_parent)
378 gkrellm_disk_subdisk_assign_data_by_name(disk->name,
379 disk->subdisk_parent, disk->rblk, disk->wblk);
380 else
381 gkrellm_disk_assign_data_by_name(disk->name,
382 disk->rblk, disk->wblk, disk->virtual);
383 }
384 }
385
386static gint
387order_from_name(gchar *name)
388 {
389 return -1;
390 }
391
392static void
393client_sys_disk_init(void)
394 {
395 gkrellm_disk_client_divert(read_disk_data, NULL((void*)0), order_from_name);
396 if (units_are_blocks)
397 gkrellm_disk_units_are_blocks();
398
399 /* Disk monitor config needs to know will be using assign by name
400 */
401 gkrellm_disk_assign_data_by_name(NULL((void*)0), 0, 0, FALSE(0));
402 }
403
404static void
405client_disk_setup(gchar *line)
406 {
407 if (!strcmp(line, "units_are_blocks")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(line) && __builtin_constant_p ("units_are_blocks") &&
(__s1_len = strlen (line), __s2_len = strlen ("units_are_blocks"
), (!((size_t)(const void *)((line) + 1) - (size_t)(const void
*)(line) == 1) || __s1_len >= 4) && (!((size_t)(const
void *)(("units_are_blocks") + 1) - (size_t)(const void *)("units_are_blocks"
) == 1) || __s2_len >= 4)) ? __builtin_strcmp (line, "units_are_blocks"
) : (__builtin_constant_p (line) && ((size_t)(const void
*)((line) + 1) - (size_t)(const void *)(line) == 1) &&
(__s1_len = strlen (line), __s1_len < 4) ? (__builtin_constant_p
("units_are_blocks") && ((size_t)(const void *)(("units_are_blocks"
) + 1) - (size_t)(const void *)("units_are_blocks") == 1) ? __builtin_strcmp
(line, "units_are_blocks") : (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) ("units_are_blocks"
); int __result = (((const unsigned char *) (const char *) (line
))[0] - __s2[0]); if (__s1_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) (line
))[1] - __s2[1]); if (__s1_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (line
))[2] - __s2[2]); if (__s1_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (line))
[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("units_are_blocks"
) && ((size_t)(const void *)(("units_are_blocks") + 1
) - (size_t)(const void *)("units_are_blocks") == 1) &&
(__s2_len = strlen ("units_are_blocks"), __s2_len < 4) ? (
__builtin_constant_p (line) && ((size_t)(const void *
)((line) + 1) - (size_t)(const void *)(line) == 1) ? __builtin_strcmp
(line, "units_are_blocks") : (- (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) (line); int
__result = (((const unsigned char *) (const char *) ("units_are_blocks"
))[0] - __s2[0]); if (__s2_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) ("units_are_blocks"
))[1] - __s2[1]); if (__s2_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) ("units_are_blocks"
))[2] - __s2[2]); if (__s2_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) ("units_are_blocks"
))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (line
, "units_are_blocks")))); })
)
408 units_are_blocks = TRUE(!(0));
409 }
410
411/* ================================================================= */
412typedef struct
413 {
414 gchar *name;
415 gboolean up_event,
416 down_event;
417
418 gint up_time;
419
420 gulong rx,
421 tx;
422 }
423 NetData;
424
425static NetData *net_timer;
426
427static GList *net_list;
428
429static gchar *net_timer_name;
430
431static gboolean net_server_use_routed;
432
433static void
434client_net_line_from_server(gchar *line)
435 {
436 GList *list;
437 NetData *net;
438 gchar name[32];
439 guint64 rx, tx;
440
441 sscanf(line, "%31s %" PRIu64"l" "u" " %" PRIu64"l" "u", name, &rx, &tx);
442 for (list = net_list; list; list = list->next)
443 {
444 net = (NetData *) list->data;
445 if (!strcmp(name, net->name)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(name) && __builtin_constant_p (net->name) &&
(__s1_len = strlen (name), __s2_len = strlen (net->name),
(!((size_t)(const void *)((name) + 1) - (size_t)(const void *
)(name) == 1) || __s1_len >= 4) && (!((size_t)(const
void *)((net->name) + 1) - (size_t)(const void *)(net->
name) == 1) || __s2_len >= 4)) ? __builtin_strcmp (name, net
->name) : (__builtin_constant_p (name) && ((size_t
)(const void *)((name) + 1) - (size_t)(const void *)(name) ==
1) && (__s1_len = strlen (name), __s1_len < 4) ? (
__builtin_constant_p (net->name) && ((size_t)(const
void *)((net->name) + 1) - (size_t)(const void *)(net->
name) == 1) ? __builtin_strcmp (name, net->name) : (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (net->name); int __result = (((const unsigned char
*) (const char *) (name))[0] - __s2[0]); if (__s1_len > 0
&& __result == 0) { __result = (((const unsigned char
*) (const char *) (name))[1] - __s2[1]); if (__s1_len > 1
&& __result == 0) { __result = (((const unsigned char
*) (const char *) (name))[2] - __s2[2]); if (__s1_len > 2
&& __result == 0) __result = (((const unsigned char *
) (const char *) (name))[3] - __s2[3]); } } __result; }))) : (
__builtin_constant_p (net->name) && ((size_t)(const
void *)((net->name) + 1) - (size_t)(const void *)(net->
name) == 1) && (__s2_len = strlen (net->name), __s2_len
< 4) ? (__builtin_constant_p (name) && ((size_t)(
const void *)((name) + 1) - (size_t)(const void *)(name) == 1
) ? __builtin_strcmp (name, net->name) : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (name); int __result = (((const unsigned char *) (const
char *) (net->name))[0] - __s2[0]); if (__s2_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (net->name))[1] - __s2[1]); if (__s2_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (net->name))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) (net->name))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp
(name, net->name)))); })
)
446 {
447 net->rx = rx;
448 net->tx = tx;
449 break;
450 }
451 }
452 if (!list)
453 {
454 net = g_new0(NetData, 1)(NetData *) (__extension__ ({ gsize __n = (gsize) (1); gsize __s
= sizeof (NetData); gpointer __p; if (__s == 1) __p = g_malloc0
(__n); else if (__builtin_constant_p (__n) && (__s ==
0 || __n <= (9223372036854775807L *2UL+1UL) / __s)) __p =
g_malloc0 (__n * __s); else __p = g_malloc0_n (__n, __s); __p
; }))
;
455 net->name = g_strdup(name);
456 net_list = g_list_append(net_list, net);
457 net->rx = rx;
458 net->tx = tx;
459
460 if (net_timer_name && !strcmp(net_timer_name, net->name)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(net_timer_name) && __builtin_constant_p (net->name
) && (__s1_len = strlen (net_timer_name), __s2_len = strlen
(net->name), (!((size_t)(const void *)((net_timer_name) +
1) - (size_t)(const void *)(net_timer_name) == 1) || __s1_len
>= 4) && (!((size_t)(const void *)((net->name)
+ 1) - (size_t)(const void *)(net->name) == 1) || __s2_len
>= 4)) ? __builtin_strcmp (net_timer_name, net->name) :
(__builtin_constant_p (net_timer_name) && ((size_t)(
const void *)((net_timer_name) + 1) - (size_t)(const void *)(
net_timer_name) == 1) && (__s1_len = strlen (net_timer_name
), __s1_len < 4) ? (__builtin_constant_p (net->name) &&
((size_t)(const void *)((net->name) + 1) - (size_t)(const
void *)(net->name) == 1) ? __builtin_strcmp (net_timer_name
, net->name) : (__extension__ ({ const unsigned char *__s2
= (const unsigned char *) (const char *) (net->name); int
__result = (((const unsigned char *) (const char *) (net_timer_name
))[0] - __s2[0]); if (__s1_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) (net_timer_name
))[1] - __s2[1]); if (__s1_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (net_timer_name
))[2] - __s2[2]); if (__s1_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (net_timer_name
))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (
net->name) && ((size_t)(const void *)((net->name
) + 1) - (size_t)(const void *)(net->name) == 1) &&
(__s2_len = strlen (net->name), __s2_len < 4) ? (__builtin_constant_p
(net_timer_name) && ((size_t)(const void *)((net_timer_name
) + 1) - (size_t)(const void *)(net_timer_name) == 1) ? __builtin_strcmp
(net_timer_name, net->name) : (- (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) (net_timer_name
); int __result = (((const unsigned char *) (const char *) (net
->name))[0] - __s2[0]); if (__s2_len > 0 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
net->name))[1] - __s2[1]); if (__s2_len > 1 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
net->name))[2] - __s2[2]); if (__s2_len > 2 && __result
== 0) __result = (((const unsigned char *) (const char *) (net
->name))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp
(net_timer_name, net->name)))); })
)
461 net_timer = net;
462 }
463 }
464
465static void
466client_net_routed_line_from_server(gchar *line)
467 {
468 GList *list;
469 NetData *net = NULL((void*)0);
470 gchar name[32];
471 gboolean routed;
472
473 sscanf(line, "%31s %d", name, &routed);
474 for (list = net_list; list; list = list->next)
475 {
476 net = (NetData *) list->data;
477 if (!strcmp(name, net->name)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(name) && __builtin_constant_p (net->name) &&
(__s1_len = strlen (name), __s2_len = strlen (net->name),
(!((size_t)(const void *)((name) + 1) - (size_t)(const void *
)(name) == 1) || __s1_len >= 4) && (!((size_t)(const
void *)((net->name) + 1) - (size_t)(const void *)(net->
name) == 1) || __s2_len >= 4)) ? __builtin_strcmp (name, net
->name) : (__builtin_constant_p (name) && ((size_t
)(const void *)((name) + 1) - (size_t)(const void *)(name) ==
1) && (__s1_len = strlen (name), __s1_len < 4) ? (
__builtin_constant_p (net->name) && ((size_t)(const
void *)((net->name) + 1) - (size_t)(const void *)(net->
name) == 1) ? __builtin_strcmp (name, net->name) : (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (net->name); int __result = (((const unsigned char
*) (const char *) (name))[0] - __s2[0]); if (__s1_len > 0
&& __result == 0) { __result = (((const unsigned char
*) (const char *) (name))[1] - __s2[1]); if (__s1_len > 1
&& __result == 0) { __result = (((const unsigned char
*) (const char *) (name))[2] - __s2[2]); if (__s1_len > 2
&& __result == 0) __result = (((const unsigned char *
) (const char *) (name))[3] - __s2[3]); } } __result; }))) : (
__builtin_constant_p (net->name) && ((size_t)(const
void *)((net->name) + 1) - (size_t)(const void *)(net->
name) == 1) && (__s2_len = strlen (net->name), __s2_len
< 4) ? (__builtin_constant_p (name) && ((size_t)(
const void *)((name) + 1) - (size_t)(const void *)(name) == 1
) ? __builtin_strcmp (name, net->name) : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (name); int __result = (((const unsigned char *) (const
char *) (net->name))[0] - __s2[0]); if (__s2_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (net->name))[1] - __s2[1]); if (__s2_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (net->name))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) (net->name))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp
(name, net->name)))); })
)
478 break;
479 }
480 if (!list)
481 {
482 net = g_new0(NetData, 1)(NetData *) (__extension__ ({ gsize __n = (gsize) (1); gsize __s
= sizeof (NetData); gpointer __p; if (__s == 1) __p = g_malloc0
(__n); else if (__builtin_constant_p (__n) && (__s ==
0 || __n <= (9223372036854775807L *2UL+1UL) / __s)) __p =
g_malloc0 (__n * __s); else __p = g_malloc0_n (__n, __s); __p
; }))
;
483 net->name = g_strdup(name);
484 net_list = g_list_append(net_list, net);
485 }
486 if (net)
487 {
488 if (routed)
489 net->up_event = TRUE(!(0));
490 else
491 net->down_event = TRUE(!(0));
492 }
493 }
494
495gint
496gkrellm_client_server_get_net_timer(void)
497 {
498 return net_timer ? net_timer->up_time : 0;
499 }
500
501static void
502client_net_timer_line_from_server(gchar *line)
503 {
504 gchar name[32];
505
506 if (!net_timer)
507 return;
508 sscanf(line, "%s %d", name, &net_timer->up_time);
509 }
510
511static void
512check_net_routes(void)
513 {
514 GList *list;
515 NetData *net;
516
517 for (list = net_list; list; list = list->next)
518 {
519 net = (NetData *) list->data;
520 if (net->up_event || net->down_event)
521 gkrellm_net_routed_event(net->name, net->up_event);
522 net->up_event = net->down_event = FALSE(0);
523 }
524 }
525
526static void
527read_net_data(void)
528 {
529 GList *list;
530 NetData *net;
531
532 for (list = net_list; list; list = list->next)
533 {
534 net = (NetData *) list->data;
535 gkrellm_net_assign_data(net->name, net->rx, net->tx);
536 }
537 }
538
539 /* gkrellmd to gkrellm server/client interface always uses the net routed
540 | mode regardless if the server uses routed in its sysdep code.
541 */
542static void
543client_sys_net_init(void)
544 {
545 gkrellm_net_client_divert(read_net_data, check_net_routes, NULL((void*)0));
546 gkrellm_net_use_routed(net_server_use_routed);
547
548 if (net_timer_name)
549 gkrellm_net_server_has_timer();
550 }
551
552static void
553client_net_setup(gchar *line)
554 {
555 gchar buf[32];
556
557 /* This is the server sysdep net_use_routed value. The client <-> server
558 | link always uses routed mode.
559 */
560 if (!strcmp(line, "net_use_routed")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(line) && __builtin_constant_p ("net_use_routed") &&
(__s1_len = strlen (line), __s2_len = strlen ("net_use_routed"
), (!((size_t)(const void *)((line) + 1) - (size_t)(const void
*)(line) == 1) || __s1_len >= 4) && (!((size_t)(const
void *)(("net_use_routed") + 1) - (size_t)(const void *)("net_use_routed"
) == 1) || __s2_len >= 4)) ? __builtin_strcmp (line, "net_use_routed"
) : (__builtin_constant_p (line) && ((size_t)(const void
*)((line) + 1) - (size_t)(const void *)(line) == 1) &&
(__s1_len = strlen (line), __s1_len < 4) ? (__builtin_constant_p
("net_use_routed") && ((size_t)(const void *)(("net_use_routed"
) + 1) - (size_t)(const void *)("net_use_routed") == 1) ? __builtin_strcmp
(line, "net_use_routed") : (__extension__ ({ const unsigned char
*__s2 = (const unsigned char *) (const char *) ("net_use_routed"
); int __result = (((const unsigned char *) (const char *) (line
))[0] - __s2[0]); if (__s1_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) (line
))[1] - __s2[1]); if (__s1_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (line
))[2] - __s2[2]); if (__s1_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (line))
[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("net_use_routed"
) && ((size_t)(const void *)(("net_use_routed") + 1) -
(size_t)(const void *)("net_use_routed") == 1) && (__s2_len
= strlen ("net_use_routed"), __s2_len < 4) ? (__builtin_constant_p
(line) && ((size_t)(const void *)((line) + 1) - (size_t
)(const void *)(line) == 1) ? __builtin_strcmp (line, "net_use_routed"
) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (line); int __result = (((const unsigned
char *) (const char *) ("net_use_routed"))[0] - __s2[0]); if
(__s2_len > 0 && __result == 0) { __result = (((const
unsigned char *) (const char *) ("net_use_routed"))[1] - __s2
[1]); if (__s2_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) ("net_use_routed"
))[2] - __s2[2]); if (__s2_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) ("net_use_routed"
))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (line
, "net_use_routed")))); })
)
561 net_server_use_routed = TRUE(!(0));
562
563 if (!strncmp(line, "net_timer", 9)(__extension__ (__builtin_constant_p (9) && ((__builtin_constant_p
(line) && strlen (line) < ((size_t) (9))) || (__builtin_constant_p
("net_timer") && strlen ("net_timer") < ((size_t)
(9)))) ? __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(line) && __builtin_constant_p ("net_timer") &&
(__s1_len = strlen (line), __s2_len = strlen ("net_timer"), (
!((size_t)(const void *)((line) + 1) - (size_t)(const void *)
(line) == 1) || __s1_len >= 4) && (!((size_t)(const
void *)(("net_timer") + 1) - (size_t)(const void *)("net_timer"
) == 1) || __s2_len >= 4)) ? __builtin_strcmp (line, "net_timer"
) : (__builtin_constant_p (line) && ((size_t)(const void
*)((line) + 1) - (size_t)(const void *)(line) == 1) &&
(__s1_len = strlen (line), __s1_len < 4) ? (__builtin_constant_p
("net_timer") && ((size_t)(const void *)(("net_timer"
) + 1) - (size_t)(const void *)("net_timer") == 1) ? __builtin_strcmp
(line, "net_timer") : (__extension__ ({ const unsigned char *
__s2 = (const unsigned char *) (const char *) ("net_timer"); int
__result = (((const unsigned char *) (const char *) (line))[
0] - __s2[0]); if (__s1_len > 0 && __result == 0) {
__result = (((const unsigned char *) (const char *) (line))[
1] - __s2[1]); if (__s1_len > 1 && __result == 0) {
__result = (((const unsigned char *) (const char *) (line))[
2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result
= (((const unsigned char *) (const char *) (line))[3] - __s2
[3]); } } __result; }))) : (__builtin_constant_p ("net_timer"
) && ((size_t)(const void *)(("net_timer") + 1) - (size_t
)(const void *)("net_timer") == 1) && (__s2_len = strlen
("net_timer"), __s2_len < 4) ? (__builtin_constant_p (line
) && ((size_t)(const void *)((line) + 1) - (size_t)(const
void *)(line) == 1) ? __builtin_strcmp (line, "net_timer") :
(- (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (line); int __result = (((const unsigned
char *) (const char *) ("net_timer"))[0] - __s2[0]); if (__s2_len
> 0 && __result == 0) { __result = (((const unsigned
char *) (const char *) ("net_timer"))[1] - __s2[1]); if (__s2_len
> 1 && __result == 0) { __result = (((const unsigned
char *) (const char *) ("net_timer"))[2] - __s2[2]); if (__s2_len
> 2 && __result == 0) __result = (((const unsigned
char *) (const char *) ("net_timer"))[3] - __s2[3]); } } __result
; })))) : __builtin_strcmp (line, "net_timer")))); }) : strncmp
(line, "net_timer", 9)))
)
564 {
565 sscanf(line, "%*s %31s\n", buf);
566 net_timer_name = g_strdup(buf);
567 }
568 }
569
570
571/* ================================================================= */
572#include "../src/inet.h"
573
574static GList *inet_list;
575
576static gboolean inet_unsupported;
577
578static void
579client_inet_line_from_server(gchar *line)
580 {
581 GList *list;
582 ActiveTCP tcp, *t;
583 gchar *ap, *aap;
584#if defined(INET6) && defined(HAVE_GETADDRINFO1)
585 struct addrinfo hints, *res;
586 gchar buf[NI_MAXHOST1025];
587#else
588 gchar buf[128];
589#endif
590 gint n, slen;
591
592 if (_GK.debug_level & DEBUG_INET0x800)
1
Taking false branch
593 g_print("inet server: %s\n", line);
594 if (*(line + 1) == '0')
2
Taking false branch
595 {
596 n = sscanf(line + 3, "%x %127[^:]:%x", &tcp.local_port,
597 buf, &tcp.remote_port);
598 if (n != 3 || inet_aton(buf, &tcp.remote_addr) == 0)
599 return;
600 tcp.family = AF_INET2;
601 }
602#if defined(INET6) && defined(HAVE_GETADDRINFO1)
603 else if (*(line + 1) == '6')
3
Taking false branch
604 {
605#define STR(x)"x" #x
606#define XSTR(x)"x" STR(x)"x"
607 n = sscanf(line + 3, "%x [%" XSTR(NI_MAXHOST)"1025" "[^]]]:%x",
608 &tcp.local_port, buf, &tcp.remote_port);
609 if (n != 3)
610 return;
611 memset(&hints, 0, sizeof(hints));
612 hints.ai_family = AF_INET610;
613 hints.ai_socktype = SOCK_STREAMSOCK_STREAM;
614 hints.ai_flags = AI_PASSIVE0x0001 | AI_NUMERICHOST0x0004;
615 if (getaddrinfo(buf, NULL((void*)0), &hints, &res) != 0)
616 return;
617 memcpy(&tcp.remote_addr6,
618 &((struct sockaddr_in6 *)res->ai_addr)->sin6_addr,
619 sizeof(struct in6_addr));
620 freeaddrinfo(res);
621 tcp.family = AF_INET610;
622 }
623#endif
624 if (*line == '+')
4
Taking false branch
625 {
626 t = g_new0(ActiveTCP, 1)(ActiveTCP *) (__extension__ ({ gsize __n = (gsize) (1); gsize
__s = sizeof (ActiveTCP); gpointer __p; if (__s == 1) __p = g_malloc0
(__n); else if (__builtin_constant_p (__n) && (__s ==
0 || __n <= (9223372036854775807L *2UL+1UL) / __s)) __p =
g_malloc0 (__n * __s); else __p = g_malloc0_n (__n, __s); __p
; }))
;
627 *t = tcp;
628 inet_list = g_list_append(inet_list, t);
629 }
630 else if (*line == '-')
5
Taking true branch
631 {
632 for (list = inet_list; list; list = list->next)
6
Loop condition is true. Entering loop body
633 {
634 t = (ActiveTCP *) list->data;
635 if (t->family == AF_INET2)
7
Taking true branch
636 {
637 ap = (gchar *) &t->remote_addr;
638 aap = (gchar *) &tcp.remote_addr;
639 slen = sizeof(struct in_addr);
640 }
641#if defined(INET6)
642 else if (t->family == AF_INET610)
643 {
644 ap = (gchar *) &t->remote_addr6;
645 aap = (gchar *) &tcp.remote_addr6;
646 slen = sizeof(struct in6_addr);
647 }
648#endif
649 else
650 return;
651 if ( memcmp(aap, ap, slen) == 0
652 && tcp.remote_port == t->remote_port
8
The left operand of '==' is a garbage value
653 && tcp.local_port == t->local_port
654 )
655 {
656 g_free(t);
657 inet_list = g_list_remove_link(inet_list, list);
658 break;
659 }
660 }
661 }
662 }
663
664static void
665read_tcp_data(void)
666 {
667 GList *list;
668 ActiveTCP *tcp;
669
670 for (list = inet_list; list; list = list->next)
671 {
672 tcp = (ActiveTCP *) list->data;
673 gkrellm_inet_log_tcp_port_data(tcp);
674 }
675 }
676
677static void
678client_inet_reset(void)
679 {
680 gkrellm_free_glist_and_data(&inet_list);
681 }
682
683static void
684client_sys_inet_init(void)
685 {
686 if (inet_unsupported)
687 return;
688 gkrellm_inet_client_divert(read_tcp_data);
689 }
690
691static void
692client_inet_setup(gchar *line)
693 {
694 if (!strcmp(line, "inet_unsupported")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(line) && __builtin_constant_p ("inet_unsupported") &&
(__s1_len = strlen (line), __s2_len = strlen ("inet_unsupported"
), (!((size_t)(const void *)((line) + 1) - (size_t)(const void
*)(line) == 1) || __s1_len >= 4) && (!((size_t)(const
void *)(("inet_unsupported") + 1) - (size_t)(const void *)("inet_unsupported"
) == 1) || __s2_len >= 4)) ? __builtin_strcmp (line, "inet_unsupported"
) : (__builtin_constant_p (line) && ((size_t)(const void
*)((line) + 1) - (size_t)(const void *)(line) == 1) &&
(__s1_len = strlen (line), __s1_len < 4) ? (__builtin_constant_p
("inet_unsupported") && ((size_t)(const void *)(("inet_unsupported"
) + 1) - (size_t)(const void *)("inet_unsupported") == 1) ? __builtin_strcmp
(line, "inet_unsupported") : (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) ("inet_unsupported"
); int __result = (((const unsigned char *) (const char *) (line
))[0] - __s2[0]); if (__s1_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) (line
))[1] - __s2[1]); if (__s1_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (line
))[2] - __s2[2]); if (__s1_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (line))
[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("inet_unsupported"
) && ((size_t)(const void *)(("inet_unsupported") + 1
) - (size_t)(const void *)("inet_unsupported") == 1) &&
(__s2_len = strlen ("inet_unsupported"), __s2_len < 4) ? (
__builtin_constant_p (line) && ((size_t)(const void *
)((line) + 1) - (size_t)(const void *)(line) == 1) ? __builtin_strcmp
(line, "inet_unsupported") : (- (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) (line); int
__result = (((const unsigned char *) (const char *) ("inet_unsupported"
))[0] - __s2[0]); if (__s2_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) ("inet_unsupported"
))[1] - __s2[1]); if (__s2_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) ("inet_unsupported"
))[2] - __s2[2]); if (__s2_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) ("inet_unsupported"
))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (line
, "inet_unsupported")))); })
)
695 inet_unsupported = TRUE(!(0));
696 }
697
698/* ================================================================= */
699struct
700 {
701 guint64 total,
702 used,
703 free,
704 shared,
705 buffers,
706 cached;
707 guint64 swap_total,
708 swap_used;
709 gulong swap_in,
710 swap_out;
711 }
712 mem;
713
714static void
715client_mem_line_from_server(gchar *line)
716 {
717 sscanf(line, "%" PRIu64"l" "u" "%" PRIu64"l" "u" " %" PRIu64"l" "u" " %" PRIu64"l" "u" " %" PRIu64"l" "u" " %" PRIu64"l" "u",
718 &mem.total, &mem.used, &mem.free,
719 &mem.shared, &mem.buffers, &mem.cached);
720 }
721
722static void
723client_swap_line_from_server(gchar *line)
724 {
725 sscanf(line, "%" PRIu64"l" "u" " %" PRIu64"l" "u" " %lu %lu",
726 &mem.swap_total, &mem.swap_used,
727 &mem.swap_in, &mem.swap_out);
728 }
729
730static void
731read_mem_data(void)
732 {
733 gkrellm_mem_assign_data(mem.total, mem.used, mem.free, mem.shared,
734 mem.buffers, mem.cached);
735 }
736
737static void
738read_swap_data(void)
739 {
740 gkrellm_swap_assign_data(mem.swap_total, mem.swap_used,
741 mem.swap_in, mem.swap_out);
742 }
743
744static void
745client_sys_mem_init(void)
746 {
747 gkrellm_mem_client_divert(read_mem_data, read_swap_data);
748 }
749
750/* ================================================================= */
751typedef struct
752 {
753 gchar *directory,
754 *device,
755 *type;
756 gulong blocks,
757 bavail,
758 bfree,
759 bsize;
760 }
761 Mount;
762
763static GList *mounts_list,
764 *fstab_list;
765
766static gboolean fstab_modified,
767 mounting_unsupported;
768
769static void
770client_fstab_line_from_server(gchar *line)
771 {
772 GList *list;
773 Mount *m;
774 gchar dir[128], dev[64], type[64];
775
776 if (!strcmp(line, ".clear")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(line) && __builtin_constant_p (".clear") &&
(__s1_len = strlen (line), __s2_len = strlen (".clear"), (!(
(size_t)(const void *)((line) + 1) - (size_t)(const void *)(line
) == 1) || __s1_len >= 4) && (!((size_t)(const void
*)((".clear") + 1) - (size_t)(const void *)(".clear") == 1) ||
__s2_len >= 4)) ? __builtin_strcmp (line, ".clear") : (__builtin_constant_p
(line) && ((size_t)(const void *)((line) + 1) - (size_t
)(const void *)(line) == 1) && (__s1_len = strlen (line
), __s1_len < 4) ? (__builtin_constant_p (".clear") &&
((size_t)(const void *)((".clear") + 1) - (size_t)(const void
*)(".clear") == 1) ? __builtin_strcmp (line, ".clear") : (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (".clear"); int __result = (((const unsigned char *)
(const char *) (line))[0] - __s2[0]); if (__s1_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (line))[1] - __s2[1]); if (__s1_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (line))[2] - __s2[2]); if (__s1_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) (line))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p
(".clear") && ((size_t)(const void *)((".clear") + 1
) - (size_t)(const void *)(".clear") == 1) && (__s2_len
= strlen (".clear"), __s2_len < 4) ? (__builtin_constant_p
(line) && ((size_t)(const void *)((line) + 1) - (size_t
)(const void *)(line) == 1) ? __builtin_strcmp (line, ".clear"
) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (line); int __result = (((const unsigned
char *) (const char *) (".clear"))[0] - __s2[0]); if (__s2_len
> 0 && __result == 0) { __result = (((const unsigned
char *) (const char *) (".clear"))[1] - __s2[1]); if (__s2_len
> 1 && __result == 0) { __result = (((const unsigned
char *) (const char *) (".clear"))[2] - __s2[2]); if (__s2_len
> 2 && __result == 0) __result = (((const unsigned
char *) (const char *) (".clear"))[3] - __s2[3]); } } __result
; })))) : __builtin_strcmp (line, ".clear")))); })
)
777 {
778 for (list = fstab_list; list; list = list->next)
779 {
780 m = (Mount *) list->data;
781 g_free(m->directory);
782 g_free(m->device);
783 g_free(m->type);
784 g_free(m);
785 }
786 g_list_free(fstab_list);
787 fstab_list = NULL((void*)0);
788 fstab_modified = TRUE(!(0));
789 }
790 else
791 {
792 m = g_new0(Mount, 1)(Mount *) (__extension__ ({ gsize __n = (gsize) (1); gsize __s
= sizeof (Mount); gpointer __p; if (__s == 1) __p = g_malloc0
(__n); else if (__builtin_constant_p (__n) && (__s ==
0 || __n <= (9223372036854775807L *2UL+1UL) / __s)) __p =
g_malloc0 (__n * __s); else __p = g_malloc0_n (__n, __s); __p
; }))
;
793 sscanf(line, "%127s %63s %63s", dir, dev, type);
794 m->directory = g_strdup(dir);
795 m->device = g_strdup(dev);
796 m->type = g_strdup(type);
797 fstab_list = g_list_append(fstab_list, m);
798 }
799 }
800
801static void
802client_mounts_line_from_server(gchar *line)
803 {
804 GList *list;
805 Mount *m;
806 gchar dir[128], dev[64], type[64];
807
808 if (!strcmp(line, ".clear")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(line) && __builtin_constant_p (".clear") &&
(__s1_len = strlen (line), __s2_len = strlen (".clear"), (!(
(size_t)(const void *)((line) + 1) - (size_t)(const void *)(line
) == 1) || __s1_len >= 4) && (!((size_t)(const void
*)((".clear") + 1) - (size_t)(const void *)(".clear") == 1) ||
__s2_len >= 4)) ? __builtin_strcmp (line, ".clear") : (__builtin_constant_p
(line) && ((size_t)(const void *)((line) + 1) - (size_t
)(const void *)(line) == 1) && (__s1_len = strlen (line
), __s1_len < 4) ? (__builtin_constant_p (".clear") &&
((size_t)(const void *)((".clear") + 1) - (size_t)(const void
*)(".clear") == 1) ? __builtin_strcmp (line, ".clear") : (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (".clear"); int __result = (((const unsigned char *)
(const char *) (line))[0] - __s2[0]); if (__s1_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (line))[1] - __s2[1]); if (__s1_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (line))[2] - __s2[2]); if (__s1_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) (line))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p
(".clear") && ((size_t)(const void *)((".clear") + 1
) - (size_t)(const void *)(".clear") == 1) && (__s2_len
= strlen (".clear"), __s2_len < 4) ? (__builtin_constant_p
(line) && ((size_t)(const void *)((line) + 1) - (size_t
)(const void *)(line) == 1) ? __builtin_strcmp (line, ".clear"
) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (line); int __result = (((const unsigned
char *) (const char *) (".clear"))[0] - __s2[0]); if (__s2_len
> 0 && __result == 0) { __result = (((const unsigned
char *) (const char *) (".clear"))[1] - __s2[1]); if (__s2_len
> 1 && __result == 0) { __result = (((const unsigned
char *) (const char *) (".clear"))[2] - __s2[2]); if (__s2_len
> 2 && __result == 0) __result = (((const unsigned
char *) (const char *) (".clear"))[3] - __s2[3]); } } __result
; })))) : __builtin_strcmp (line, ".clear")))); })
)
809 {
810 for (list = mounts_list; list; list = list->next)
811 {
812 m = (Mount *) list->data;
813 g_free(m->directory);
814 g_free(m->device);
815 g_free(m->type);
816 g_free(m);
817 }
818 g_list_free(mounts_list);
819 mounts_list = NULL((void*)0);
820 }
821 else
822 {
823 m = g_new0(Mount, 1)(Mount *) (__extension__ ({ gsize __n = (gsize) (1); gsize __s
= sizeof (Mount); gpointer __p; if (__s == 1) __p = g_malloc0
(__n); else if (__builtin_constant_p (__n) && (__s ==
0 || __n <= (9223372036854775807L *2UL+1UL) / __s)) __p =
g_malloc0 (__n * __s); else __p = g_malloc0_n (__n, __s); __p
; }))
;
824 sscanf(line, "%127s %63s %63s %lu %lu %lu %lu", dir, dev, type,
825 &m->blocks, &m->bavail, &m->bfree, &m->bsize);
826 m->directory = g_strdup(dir);
827 m->device = g_strdup(dev);
828 m->type = g_strdup(type);
829 mounts_list = g_list_append(mounts_list, m);
830 }
831 }
832
833static void
834client_fs_line_from_server(gchar *line)
835 {
836 GList *list;
837 Mount *m;
838 gchar dir[128], dev[64];
839 gulong blocks, bavail, bfree, bsize;
840
841 sscanf(line, "%127s %63s %lu %lu %lu %lu", dir, dev,
842 &blocks, &bavail, &bfree, &bsize);
843 for (list = mounts_list; list; list = list->next)
844 {
845 m = (Mount *) list->data;
846 if (!strcmp(m->directory, dir)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(m->directory) && __builtin_constant_p (dir) &&
(__s1_len = strlen (m->directory), __s2_len = strlen (dir
), (!((size_t)(const void *)((m->directory) + 1) - (size_t
)(const void *)(m->directory) == 1) || __s1_len >= 4) &&
(!((size_t)(const void *)((dir) + 1) - (size_t)(const void *
)(dir) == 1) || __s2_len >= 4)) ? __builtin_strcmp (m->
directory, dir) : (__builtin_constant_p (m->directory) &&
((size_t)(const void *)((m->directory) + 1) - (size_t)(const
void *)(m->directory) == 1) && (__s1_len = strlen
(m->directory), __s1_len < 4) ? (__builtin_constant_p (
dir) && ((size_t)(const void *)((dir) + 1) - (size_t)
(const void *)(dir) == 1) ? __builtin_strcmp (m->directory
, dir) : (__extension__ ({ const unsigned char *__s2 = (const
unsigned char *) (const char *) (dir); int __result = (((const
unsigned char *) (const char *) (m->directory))[0] - __s2
[0]); if (__s1_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) (m->directory)
)[1] - __s2[1]); if (__s1_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (m->
directory))[2] - __s2[2]); if (__s1_len > 2 && __result
== 0) __result = (((const unsigned char *) (const char *) (m
->directory))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p
(dir) && ((size_t)(const void *)((dir) + 1) - (size_t
)(const void *)(dir) == 1) && (__s2_len = strlen (dir
), __s2_len < 4) ? (__builtin_constant_p (m->directory)
&& ((size_t)(const void *)((m->directory) + 1) - (
size_t)(const void *)(m->directory) == 1) ? __builtin_strcmp
(m->directory, dir) : (- (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) (m->directory
); int __result = (((const unsigned char *) (const char *) (dir
))[0] - __s2[0]); if (__s2_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) (dir)
)[1] - __s2[1]); if (__s2_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (dir)
)[2] - __s2[2]); if (__s2_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (dir))[
3] - __s2[3]); } } __result; })))) : __builtin_strcmp (m->
directory, dir)))); })
&& !strcmp(m->device, dev)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(m->device) && __builtin_constant_p (dev) &&
(__s1_len = strlen (m->device), __s2_len = strlen (dev), (
!((size_t)(const void *)((m->device) + 1) - (size_t)(const
void *)(m->device) == 1) || __s1_len >= 4) && (
!((size_t)(const void *)((dev) + 1) - (size_t)(const void *)(
dev) == 1) || __s2_len >= 4)) ? __builtin_strcmp (m->device
, dev) : (__builtin_constant_p (m->device) && ((size_t
)(const void *)((m->device) + 1) - (size_t)(const void *)(
m->device) == 1) && (__s1_len = strlen (m->device
), __s1_len < 4) ? (__builtin_constant_p (dev) && (
(size_t)(const void *)((dev) + 1) - (size_t)(const void *)(dev
) == 1) ? __builtin_strcmp (m->device, dev) : (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (dev); int __result = (((const unsigned char *) (const
char *) (m->device))[0] - __s2[0]); if (__s1_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (m->device))[1] - __s2[1]); if (__s1_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (m->device))[2] - __s2[2]); if (__s1_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) (m->device))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p
(dev) && ((size_t)(const void *)((dev) + 1) - (size_t
)(const void *)(dev) == 1) && (__s2_len = strlen (dev
), __s2_len < 4) ? (__builtin_constant_p (m->device) &&
((size_t)(const void *)((m->device) + 1) - (size_t)(const
void *)(m->device) == 1) ? __builtin_strcmp (m->device
, dev) : (- (__extension__ ({ const unsigned char *__s2 = (const
unsigned char *) (const char *) (m->device); int __result
= (((const unsigned char *) (const char *) (dev))[0] - __s2[
0]); if (__s2_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) (dev))[1] - __s2[
1]); if (__s2_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) (dev))[2] - __s2[
2]); if (__s2_len > 2 && __result == 0) __result =
(((const unsigned char *) (const char *) (dev))[3] - __s2[3]
); } } __result; })))) : __builtin_strcmp (m->device, dev)
))); })
)
847 {
848 m->blocks = blocks;
849 m->bavail = bavail;
850 m->bfree = bfree;
851 m->bsize = bsize;
852 break;
853 }
854 }
855 }
856
857static void
858get_fsusage(gpointer fs, gchar *dir)
859 {
860 GList *list;
861 Mount *m;
862
863 for (list = mounts_list; list; list = list->next)
864 {
865 m = (Mount *) list->data;
866 if (!strcmp(m->directory, dir)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(m->directory) && __builtin_constant_p (dir) &&
(__s1_len = strlen (m->directory), __s2_len = strlen (dir
), (!((size_t)(const void *)((m->directory) + 1) - (size_t
)(const void *)(m->directory) == 1) || __s1_len >= 4) &&
(!((size_t)(const void *)((dir) + 1) - (size_t)(const void *
)(dir) == 1) || __s2_len >= 4)) ? __builtin_strcmp (m->
directory, dir) : (__builtin_constant_p (m->directory) &&
((size_t)(const void *)((m->directory) + 1) - (size_t)(const
void *)(m->directory) == 1) && (__s1_len = strlen
(m->directory), __s1_len < 4) ? (__builtin_constant_p (
dir) && ((size_t)(const void *)((dir) + 1) - (size_t)
(const void *)(dir) == 1) ? __builtin_strcmp (m->directory
, dir) : (__extension__ ({ const unsigned char *__s2 = (const
unsigned char *) (const char *) (dir); int __result = (((const
unsigned char *) (const char *) (m->directory))[0] - __s2
[0]); if (__s1_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) (m->directory)
)[1] - __s2[1]); if (__s1_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (m->
directory))[2] - __s2[2]); if (__s1_len > 2 && __result
== 0) __result = (((const unsigned char *) (const char *) (m
->directory))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p
(dir) && ((size_t)(const void *)((dir) + 1) - (size_t
)(const void *)(dir) == 1) && (__s2_len = strlen (dir
), __s2_len < 4) ? (__builtin_constant_p (m->directory)
&& ((size_t)(const void *)((m->directory) + 1) - (
size_t)(const void *)(m->directory) == 1) ? __builtin_strcmp
(m->directory, dir) : (- (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) (m->directory
); int __result = (((const unsigned char *) (const char *) (dir
))[0] - __s2[0]); if (__s2_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) (dir)
)[1] - __s2[1]); if (__s2_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (dir)
)[2] - __s2[2]); if (__s2_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (dir))[
3] - __s2[3]); } } __result; })))) : __builtin_strcmp (m->
directory, dir)))); })
)
867 {
868 gkrellm_fs_assign_fsusage_data(fs, m->blocks, m->bavail,
869 m->bfree, m->bsize);
870 break;
871 }
872 }
873 }
874
875static void
876get_mounts_list(void)
877 {
878 GList *list;
879 Mount *m;
880
881 for (list = mounts_list; list; list = list->next)
882 {
883 m = (Mount *) list->data;
884 gkrellm_fs_add_to_mounts_list(m->directory, m->device, m->type);
885 }
886 }
887
888static void
889get_fstab_list(void)
890 {
891 GList *list;
892 Mount *m;
893
894 for (list = fstab_list; list; list = list->next)
895 {
896 m = (Mount *) list->data;
897 gkrellm_fs_add_to_fstab_list(m->directory, m->device,
898 m->type, "none" /* options NA since no mounting */ );
899 }
900 fstab_modified = FALSE(0);
901 }
902
903static gboolean
904get_fstab_modified(void)
905 {
906 return fstab_modified;
907 }
908
909static void
910client_sys_fs_init(void)
911 {
912 gkrellm_fs_client_divert(get_fsusage, get_mounts_list,
913 get_fstab_list, get_fstab_modified);
914 if (mounting_unsupported)
915 gkrellm_fs_mounting_unsupported();
916 }
917
918static void
919client_fs_setup(gchar *line)
920 {
921 if (!strcmp(line, "mounting_unsupported")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(line) && __builtin_constant_p ("mounting_unsupported"
) && (__s1_len = strlen (line), __s2_len = strlen ("mounting_unsupported"
), (!((size_t)(const void *)((line) + 1) - (size_t)(const void
*)(line) == 1) || __s1_len >= 4) && (!((size_t)(const
void *)(("mounting_unsupported") + 1) - (size_t)(const void *
)("mounting_unsupported") == 1) || __s2_len >= 4)) ? __builtin_strcmp
(line, "mounting_unsupported") : (__builtin_constant_p (line
) && ((size_t)(const void *)((line) + 1) - (size_t)(const
void *)(line) == 1) && (__s1_len = strlen (line), __s1_len
< 4) ? (__builtin_constant_p ("mounting_unsupported") &&
((size_t)(const void *)(("mounting_unsupported") + 1) - (size_t
)(const void *)("mounting_unsupported") == 1) ? __builtin_strcmp
(line, "mounting_unsupported") : (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) ("mounting_unsupported"
); int __result = (((const unsigned char *) (const char *) (line
))[0] - __s2[0]); if (__s1_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) (line
))[1] - __s2[1]); if (__s1_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (line
))[2] - __s2[2]); if (__s1_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (line))
[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("mounting_unsupported"
) && ((size_t)(const void *)(("mounting_unsupported")
+ 1) - (size_t)(const void *)("mounting_unsupported") == 1) &&
(__s2_len = strlen ("mounting_unsupported"), __s2_len < 4
) ? (__builtin_constant_p (line) && ((size_t)(const void
*)((line) + 1) - (size_t)(const void *)(line) == 1) ? __builtin_strcmp
(line, "mounting_unsupported") : (- (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) (line); int
__result = (((const unsigned char *) (const char *) ("mounting_unsupported"
))[0] - __s2[0]); if (__s2_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) ("mounting_unsupported"
))[1] - __s2[1]); if (__s2_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) ("mounting_unsupported"
))[2] - __s2[2]); if (__s2_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) ("mounting_unsupported"
))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (line
, "mounting_unsupported")))); })
)
922 mounting_unsupported = TRUE(!(0));
923 }
924
925/* ================================================================= */
926typedef struct
927 {
928 gchar *path;
929 gint total,
930 new;
931 gpointer mbox_ptr;
932 }
933 Mailbox;
934
935static GList *mailbox_list;
936
937static gboolean
938check_mail(Mailbox *mbox)
939 {
940 gkrellm_set_external_mbox_counts(mbox->mbox_ptr, mbox->total, mbox->new);
941 return TRUE(!(0));
942 }
943
944static void
945client_mail_line_from_server(gchar *line)
946 {
947 Mailbox *mbox = NULL((void*)0);
948 GList *list;
949 gchar path[256];
950// gchar *s;
951 gint total, new;
952
953 if (sscanf(line, "%255s %d %d", path, &total, &new) < 3)
954 return;
955 for (list = mailbox_list; list; list = list->next)
956 {
957 mbox = (Mailbox *) list->data;
958 if (!strcmp(path, mbox->path)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(path) && __builtin_constant_p (mbox->path) &&
(__s1_len = strlen (path), __s2_len = strlen (mbox->path)
, (!((size_t)(const void *)((path) + 1) - (size_t)(const void
*)(path) == 1) || __s1_len >= 4) && (!((size_t)(const
void *)((mbox->path) + 1) - (size_t)(const void *)(mbox->
path) == 1) || __s2_len >= 4)) ? __builtin_strcmp (path, mbox
->path) : (__builtin_constant_p (path) && ((size_t
)(const void *)((path) + 1) - (size_t)(const void *)(path) ==
1) && (__s1_len = strlen (path), __s1_len < 4) ? (
__builtin_constant_p (mbox->path) && ((size_t)(const
void *)((mbox->path) + 1) - (size_t)(const void *)(mbox->
path) == 1) ? __builtin_strcmp (path, mbox->path) : (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (mbox->path); int __result = (((const unsigned char
*) (const char *) (path))[0] - __s2[0]); if (__s1_len > 0
&& __result == 0) { __result = (((const unsigned char
*) (const char *) (path))[1] - __s2[1]); if (__s1_len > 1
&& __result == 0) { __result = (((const unsigned char
*) (const char *) (path))[2] - __s2[2]); if (__s1_len > 2
&& __result == 0) __result = (((const unsigned char *
) (const char *) (path))[3] - __s2[3]); } } __result; }))) : (
__builtin_constant_p (mbox->path) && ((size_t)(const
void *)((mbox->path) + 1) - (size_t)(const void *)(mbox->
path) == 1) && (__s2_len = strlen (mbox->path), __s2_len
< 4) ? (__builtin_constant_p (path) && ((size_t)(
const void *)((path) + 1) - (size_t)(const void *)(path) == 1
) ? __builtin_strcmp (path, mbox->path) : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (path); int __result = (((const unsigned char *) (const
char *) (mbox->path))[0] - __s2[0]); if (__s2_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (mbox->path))[1] - __s2[1]); if (__s2_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (mbox->path))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) (mbox->path))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp
(path, mbox->path)))); })
)
959 break;
960 }
961 if (!list)
962 {
963 mbox = g_new0(Mailbox, 1)(Mailbox *) (__extension__ ({ gsize __n = (gsize) (1); gsize __s
= sizeof (Mailbox); gpointer __p; if (__s == 1) __p = g_malloc0
(__n); else if (__builtin_constant_p (__n) && (__s ==
0 || __n <= (9223372036854775807L *2UL+1UL) / __s)) __p =
g_malloc0 (__n * __s); else __p = g_malloc0_n (__n, __s); __p
; }))
;
964 mbox->path = g_strdup(path);
965 mailbox_list = g_list_append(mailbox_list, mbox);
966 mbox->mbox_ptr =
967 gkrellm_add_external_mbox(check_mail, FALSE(0), mbox);
968 gkrellm_set_external_mbox_tooltip(mbox->mbox_ptr, mbox->path);
969
970// s = g_strdup_printf("%s:%s", _GK.server_hostname, mbox->path);
971// gkrellm_set_external_mbox_tooltip(mbox->mbox_ptr, s);
972// g_free(s);
973 }
974 if (mbox)
975 {
976 mbox->total = total;
977 mbox->new = new;
978 }
979 }
980
981static void
982client_sys_mail_init(void)
983 {
984 }
985
986static void
987client_mail_setup(gchar *line)
988 {
989 }
990
991/* ================================================================= */
992GList *battery_list;
993
994gboolean batteries_available;
995
996typedef struct
997 {
998 gint id;
999 gboolean present,
1000 on_line,
1001 charging;
1002 gint percent;
1003 gint time_left;
1004 }
1005 Battery;
1006
1007static Battery *composite_battery;
1008
1009static Battery *
1010battery_nth(gint n)
1011 {
1012 Battery *bat;
1013 static gint n_batteries;
1014
1015 if (n > 10)
1016 return NULL((void*)0);
1017 if (n < 0)
1018 {
1019 if (!composite_battery)
1020 {
1021 bat = g_new0(Battery, 1)(Battery *) (__extension__ ({ gsize __n = (gsize) (1); gsize __s
= sizeof (Battery); gpointer __p; if (__s == 1) __p = g_malloc0
(__n); else if (__builtin_constant_p (__n) && (__s ==
0 || __n <= (9223372036854775807L *2UL+1UL) / __s)) __p =
g_malloc0 (__n * __s); else __p = g_malloc0_n (__n, __s); __p
; }))
;
1022 battery_list = g_list_prepend(battery_list, bat);
1023 bat->id = GKRELLM_BATTERY_COMPOSITE_ID-1;
1024 composite_battery = bat;
1025 }
1026 return composite_battery;
1027 }
1028
1029 if (composite_battery)
1030 ++n;
1031
1032 while ((bat = (Battery *)g_list_nth_data(battery_list, n)) == NULL((void*)0))
1033 {
1034 bat = g_new0(Battery, 1)(Battery *) (__extension__ ({ gsize __n = (gsize) (1); gsize __s
= sizeof (Battery); gpointer __p; if (__s == 1) __p = g_malloc0
(__n); else if (__builtin_constant_p (__n) && (__s ==
0 || __n <= (9223372036854775807L *2UL+1UL) / __s)) __p =
g_malloc0 (__n * __s); else __p = g_malloc0_n (__n, __s); __p
; }))
;
1035 battery_list = g_list_append(battery_list, bat);
1036 bat->id = n_batteries++;
1037 }
1038 return bat;
1039 }
1040
1041
1042static void
1043client_battery_line_from_server(gchar *line)
1044 {
1045 Battery *bat;
1046 gboolean present, on_line, charging;
1047 gint percent, time_left, n = 0;
1048
1049 /* 2.1.9 adds 6th arg battery id number
1050 */
1051 if (sscanf(line, "%d %d %d %d %d %d",
1052 &present, &on_line, &charging, &percent, &time_left, &n) < 5)
1053 return;
1054
1055 bat = battery_nth(n);
1056 if (!bat)
1057 return;
1058 bat->present = present;
1059 bat->on_line = on_line;
1060 bat->charging = charging;
1061 bat->percent = percent;
1062 bat->time_left = time_left;
1063 }
1064
1065static void
1066read_battery_data(void)
1067 {
1068 GList *list;
1069 Battery *bat;
1070
1071 for (list = battery_list; list; list = list->next)
1072 {
1073 bat = (Battery *) list->data;
1074 gkrellm_battery_assign_data(bat->id, bat->present,
1075 bat->on_line, bat->charging,
1076 bat->percent, bat->time_left);
1077 }
1078 }
1079
1080static void
1081client_sys_battery_init(void)
1082 {
1083 if (batteries_available)
1084 gkrellm_battery_client_divert(read_battery_data);
1085 }
1086
1087static void
1088client_battery_setup(gchar *line)
1089 {
1090 if ( !strcmp(line, "apm_available")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(line) && __builtin_constant_p ("apm_available") &&
(__s1_len = strlen (line), __s2_len = strlen ("apm_available"
), (!((size_t)(const void *)((line) + 1) - (size_t)(const void
*)(line) == 1) || __s1_len >= 4) && (!((size_t)(const
void *)(("apm_available") + 1) - (size_t)(const void *)("apm_available"
) == 1) || __s2_len >= 4)) ? __builtin_strcmp (line, "apm_available"
) : (__builtin_constant_p (line) && ((size_t)(const void
*)((line) + 1) - (size_t)(const void *)(line) == 1) &&
(__s1_len = strlen (line), __s1_len < 4) ? (__builtin_constant_p
("apm_available") && ((size_t)(const void *)(("apm_available"
) + 1) - (size_t)(const void *)("apm_available") == 1) ? __builtin_strcmp
(line, "apm_available") : (__extension__ ({ const unsigned char
*__s2 = (const unsigned char *) (const char *) ("apm_available"
); int __result = (((const unsigned char *) (const char *) (line
))[0] - __s2[0]); if (__s1_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) (line
))[1] - __s2[1]); if (__s1_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (line
))[2] - __s2[2]); if (__s1_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (line))
[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("apm_available"
) && ((size_t)(const void *)(("apm_available") + 1) -
(size_t)(const void *)("apm_available") == 1) && (__s2_len
= strlen ("apm_available"), __s2_len < 4) ? (__builtin_constant_p
(line) && ((size_t)(const void *)((line) + 1) - (size_t
)(const void *)(line) == 1) ? __builtin_strcmp (line, "apm_available"
) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (line); int __result = (((const unsigned
char *) (const char *) ("apm_available"))[0] - __s2[0]); if (
__s2_len > 0 && __result == 0) { __result = (((const
unsigned char *) (const char *) ("apm_available"))[1] - __s2
[1]); if (__s2_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) ("apm_available")
)[2] - __s2[2]); if (__s2_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) ("apm_available"
))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (line
, "apm_available")))); })
1091 || !strcmp(line, "battery_available")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(line) && __builtin_constant_p ("battery_available")
&& (__s1_len = strlen (line), __s2_len = strlen ("battery_available"
), (!((size_t)(const void *)((line) + 1) - (size_t)(const void
*)(line) == 1) || __s1_len >= 4) && (!((size_t)(const
void *)(("battery_available") + 1) - (size_t)(const void *)(
"battery_available") == 1) || __s2_len >= 4)) ? __builtin_strcmp
(line, "battery_available") : (__builtin_constant_p (line) &&
((size_t)(const void *)((line) + 1) - (size_t)(const void *)
(line) == 1) && (__s1_len = strlen (line), __s1_len <
4) ? (__builtin_constant_p ("battery_available") && (
(size_t)(const void *)(("battery_available") + 1) - (size_t)(
const void *)("battery_available") == 1) ? __builtin_strcmp (
line, "battery_available") : (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) ("battery_available"
); int __result = (((const unsigned char *) (const char *) (line
))[0] - __s2[0]); if (__s1_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) (line
))[1] - __s2[1]); if (__s1_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (line
))[2] - __s2[2]); if (__s1_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (line))
[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("battery_available"
) && ((size_t)(const void *)(("battery_available") + 1
) - (size_t)(const void *)("battery_available") == 1) &&
(__s2_len = strlen ("battery_available"), __s2_len < 4) ?
(__builtin_constant_p (line) && ((size_t)(const void
*)((line) + 1) - (size_t)(const void *)(line) == 1) ? __builtin_strcmp
(line, "battery_available") : (- (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) (line); int
__result = (((const unsigned char *) (const char *) ("battery_available"
))[0] - __s2[0]); if (__s2_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) ("battery_available"
))[1] - __s2[1]); if (__s2_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) ("battery_available"
))[2] - __s2[2]); if (__s2_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) ("battery_available"
))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (line
, "battery_available")))); })
1092 )
1093 batteries_available = TRUE(!(0));
1094 }
1095
1096/* ================================================================= */
1097typedef struct
1098 {
1099 gint type;
1100
1101 gchar *basename;
1102 gint id;
1103 gint iodev;
1104 gint inter;
1105
1106 gint group;
1107
1108 gchar *vref;
1109 gchar *default_label;
1110
1111 gfloat factor;
1112 gfloat offset;
1113 gfloat raw_value;
1114 }
1115 Sensor;
1116
1117static GList *sensors_list;
1118
1119
1120static void
1121client_sensors_line_from_server(gchar *line)
1122 {
1123 GList *list;
1124 Sensor s, *sensor;
1125 gchar basename[128];
1126
1127 if (need_locale_fix)
1128 locale_fix(line);
1129 sscanf(line, "%d \"%127[^\"]\" %d %d %d %f",
1130 &s.type, basename, &s.id, &s.iodev, &s.inter, &s.raw_value);
1131 for (list = sensors_list; list; list = list->next)
1132 {
1133 sensor = (Sensor *) list->data;
1134 if ( sensor->type == s.type && !strcmp(sensor->basename, basename)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(sensor->basename) && __builtin_constant_p (basename
) && (__s1_len = strlen (sensor->basename), __s2_len
= strlen (basename), (!((size_t)(const void *)((sensor->basename
) + 1) - (size_t)(const void *)(sensor->basename) == 1) ||
__s1_len >= 4) && (!((size_t)(const void *)((basename
) + 1) - (size_t)(const void *)(basename) == 1) || __s2_len >=
4)) ? __builtin_strcmp (sensor->basename, basename) : (__builtin_constant_p
(sensor->basename) && ((size_t)(const void *)((sensor
->basename) + 1) - (size_t)(const void *)(sensor->basename
) == 1) && (__s1_len = strlen (sensor->basename), __s1_len
< 4) ? (__builtin_constant_p (basename) && ((size_t
)(const void *)((basename) + 1) - (size_t)(const void *)(basename
) == 1) ? __builtin_strcmp (sensor->basename, basename) : (
__extension__ ({ const unsigned char *__s2 = (const unsigned char
*) (const char *) (basename); int __result = (((const unsigned
char *) (const char *) (sensor->basename))[0] - __s2[0]);
if (__s1_len > 0 && __result == 0) { __result = (
((const unsigned char *) (const char *) (sensor->basename)
)[1] - __s2[1]); if (__s1_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (sensor
->basename))[2] - __s2[2]); if (__s1_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) (sensor->basename))[3] - __s2[3]); } } __result; }))) :
(__builtin_constant_p (basename) && ((size_t)(const void
*)((basename) + 1) - (size_t)(const void *)(basename) == 1) &&
(__s2_len = strlen (basename), __s2_len < 4) ? (__builtin_constant_p
(sensor->basename) && ((size_t)(const void *)((sensor
->basename) + 1) - (size_t)(const void *)(sensor->basename
) == 1) ? __builtin_strcmp (sensor->basename, basename) : (
- (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (sensor->basename); int __result =
(((const unsigned char *) (const char *) (basename))[0] - __s2
[0]); if (__s2_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) (basename))[1] - __s2
[1]); if (__s2_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) (basename))[2] - __s2
[2]); if (__s2_len > 2 && __result == 0) __result =
(((const unsigned char *) (const char *) (basename))[3] - __s2
[3]); } } __result; })))) : __builtin_strcmp (sensor->basename
, basename)))); })
1135 && sensor->id == s.id && sensor->iodev == s.iodev
1136 && sensor->inter == s.inter
1137 )
1138 {
1139 sensor->raw_value = s.raw_value;
1140 break;
1141 }
1142 }
1143 }
1144
1145static gboolean
1146get_temperature(gchar *path, gint id, gint iodev, gint inter, gfloat *value)
1147 {
1148 GList *list;
1149 Sensor *s;
1150
1151 for (list = sensors_list; list; list = list->next)
1152 {
1153 s = (Sensor *) list->data;
1154 if ( s->type == SENSOR_TEMPERATURE0 && !strcmp(s->basename, path)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(s->basename) && __builtin_constant_p (path) &&
(__s1_len = strlen (s->basename), __s2_len = strlen (path
), (!((size_t)(const void *)((s->basename) + 1) - (size_t)
(const void *)(s->basename) == 1) || __s1_len >= 4) &&
(!((size_t)(const void *)((path) + 1) - (size_t)(const void *
)(path) == 1) || __s2_len >= 4)) ? __builtin_strcmp (s->
basename, path) : (__builtin_constant_p (s->basename) &&
((size_t)(const void *)((s->basename) + 1) - (size_t)(const
void *)(s->basename) == 1) && (__s1_len = strlen (
s->basename), __s1_len < 4) ? (__builtin_constant_p (path
) && ((size_t)(const void *)((path) + 1) - (size_t)(const
void *)(path) == 1) ? __builtin_strcmp (s->basename, path
) : (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (path); int __result = (((const unsigned
char *) (const char *) (s->basename))[0] - __s2[0]); if (
__s1_len > 0 && __result == 0) { __result = (((const
unsigned char *) (const char *) (s->basename))[1] - __s2[
1]); if (__s1_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) (s->basename))
[2] - __s2[2]); if (__s1_len > 2 && __result == 0)
__result = (((const unsigned char *) (const char *) (s->basename
))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (
path) && ((size_t)(const void *)((path) + 1) - (size_t
)(const void *)(path) == 1) && (__s2_len = strlen (path
), __s2_len < 4) ? (__builtin_constant_p (s->basename) &&
((size_t)(const void *)((s->basename) + 1) - (size_t)(const
void *)(s->basename) == 1) ? __builtin_strcmp (s->basename
, path) : (- (__extension__ ({ const unsigned char *__s2 = (const
unsigned char *) (const char *) (s->basename); int __result
= (((const unsigned char *) (const char *) (path))[0] - __s2
[0]); if (__s2_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) (path))[1] - __s2
[1]); if (__s2_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) (path))[2] - __s2
[2]); if (__s2_len > 2 && __result == 0) __result =
(((const unsigned char *) (const char *) (path))[3] - __s2[3
]); } } __result; })))) : __builtin_strcmp (s->basename, path
)))); })
1155 && s->id == id && s->iodev == iodev && s->inter == inter
1156 )
1157 {
1158 *value = s->raw_value;
1159 return TRUE(!(0));
1160 }
1161 }
1162 return FALSE(0);
1163 }
1164
1165static gboolean
1166get_fan(gchar *path, gint id, gint iodev, gint inter, gfloat *value)
1167 {
1168 GList *list;
1169 Sensor *s;
1170
1171 for (list = sensors_list; list; list = list->next)
1172 {
1173 s = (Sensor *) list->data;
1174 if ( s->type == SENSOR_FAN1 && !strcmp(s->basename, path)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(s->basename) && __builtin_constant_p (path) &&
(__s1_len = strlen (s->basename), __s2_len = strlen (path
), (!((size_t)(const void *)((s->basename) + 1) - (size_t)
(const void *)(s->basename) == 1) || __s1_len >= 4) &&
(!((size_t)(const void *)((path) + 1) - (size_t)(const void *
)(path) == 1) || __s2_len >= 4)) ? __builtin_strcmp (s->
basename, path) : (__builtin_constant_p (s->basename) &&
((size_t)(const void *)((s->basename) + 1) - (size_t)(const
void *)(s->basename) == 1) && (__s1_len = strlen (
s->basename), __s1_len < 4) ? (__builtin_constant_p (path
) && ((size_t)(const void *)((path) + 1) - (size_t)(const
void *)(path) == 1) ? __builtin_strcmp (s->basename, path
) : (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (path); int __result = (((const unsigned
char *) (const char *) (s->basename))[0] - __s2[0]); if (
__s1_len > 0 && __result == 0) { __result = (((const
unsigned char *) (const char *) (s->basename))[1] - __s2[
1]); if (__s1_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) (s->basename))
[2] - __s2[2]); if (__s1_len > 2 && __result == 0)
__result = (((const unsigned char *) (const char *) (s->basename
))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (
path) && ((size_t)(const void *)((path) + 1) - (size_t
)(const void *)(path) == 1) && (__s2_len = strlen (path
), __s2_len < 4) ? (__builtin_constant_p (s->basename) &&
((size_t)(const void *)((s->basename) + 1) - (size_t)(const
void *)(s->basename) == 1) ? __builtin_strcmp (s->basename
, path) : (- (__extension__ ({ const unsigned char *__s2 = (const
unsigned char *) (const char *) (s->basename); int __result
= (((const unsigned char *) (const char *) (path))[0] - __s2
[0]); if (__s2_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) (path))[1] - __s2
[1]); if (__s2_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) (path))[2] - __s2
[2]); if (__s2_len > 2 && __result == 0) __result =
(((const unsigned char *) (const char *) (path))[3] - __s2[3
]); } } __result; })))) : __builtin_strcmp (s->basename, path
)))); })
1175 && s->id == id && s->iodev == iodev && s->inter == inter
1176 )
1177 {
1178 *value = s->raw_value;
1179 return TRUE(!(0));
1180 }
1181 }
1182 return FALSE(0);
1183 }
1184
1185static gboolean
1186get_voltage(gchar *path, gint id, gint iodev, gint inter, gfloat *value)
1187 {
1188 GList *list;
1189 Sensor *s;
1190
1191 for (list = sensors_list; list; list = list->next)
1192 {
1193 s = (Sensor *) list->data;
1194 if ( s->type == SENSOR_VOLTAGE2 && !strcmp(s->basename, path)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(s->basename) && __builtin_constant_p (path) &&
(__s1_len = strlen (s->basename), __s2_len = strlen (path
), (!((size_t)(const void *)((s->basename) + 1) - (size_t)
(const void *)(s->basename) == 1) || __s1_len >= 4) &&
(!((size_t)(const void *)((path) + 1) - (size_t)(const void *
)(path) == 1) || __s2_len >= 4)) ? __builtin_strcmp (s->
basename, path) : (__builtin_constant_p (s->basename) &&
((size_t)(const void *)((s->basename) + 1) - (size_t)(const
void *)(s->basename) == 1) && (__s1_len = strlen (
s->basename), __s1_len < 4) ? (__builtin_constant_p (path
) && ((size_t)(const void *)((path) + 1) - (size_t)(const
void *)(path) == 1) ? __builtin_strcmp (s->basename, path
) : (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (path); int __result = (((const unsigned
char *) (const char *) (s->basename))[0] - __s2[0]); if (
__s1_len > 0 && __result == 0) { __result = (((const
unsigned char *) (const char *) (s->basename))[1] - __s2[
1]); if (__s1_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) (s->basename))
[2] - __s2[2]); if (__s1_len > 2 && __result == 0)
__result = (((const unsigned char *) (const char *) (s->basename
))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (
path) && ((size_t)(const void *)((path) + 1) - (size_t
)(const void *)(path) == 1) && (__s2_len = strlen (path
), __s2_len < 4) ? (__builtin_constant_p (s->basename) &&
((size_t)(const void *)((s->basename) + 1) - (size_t)(const
void *)(s->basename) == 1) ? __builtin_strcmp (s->basename
, path) : (- (__extension__ ({ const unsigned char *__s2 = (const
unsigned char *) (const char *) (s->basename); int __result
= (((const unsigned char *) (const char *) (path))[0] - __s2
[0]); if (__s2_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) (path))[1] - __s2
[1]); if (__s2_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) (path))[2] - __s2
[2]); if (__s2_len > 2 && __result == 0) __result =
(((const unsigned char *) (const char *) (path))[3] - __s2[3
]); } } __result; })))) : __builtin_strcmp (s->basename, path
)))); })
1195 && s->id == id && s->iodev == iodev && s->inter == inter
1196 )
1197 {
1198 *value = s->raw_value;
1199 return TRUE(!(0));
1200 }
1201 }
1202 return FALSE(0);
1203 }
1204
1205static void
1206client_sys_sensors_init(void)
1207 {
1208 GList *list;
1209 Sensor *s;
1210 gpointer sr;
1211
1212 if (!sensors_list)
1213 return;
1214
1215 gkrellm_sensors_client_divert(get_temperature, get_fan, get_voltage);
1216 for (list = sensors_list; list; list = list->next)
1217 {
1218 s = (Sensor *) list->data;
1219
1220 /* The sysdep code in the server may be using the dir arg to get sensor
1221 | values, but dir is no longer needed.
1222 */
1223 sr = gkrellm_sensors_add_sensor(s->type, NULL((void*)0), s->basename,
1224 s->id, s->iodev, s->inter,
1225 s->factor, s->offset,
1226 s->vref, s->default_label);
1227 gkrellm_sensors_set_group(sr, s->group);
1228 }
1229 }
1230
1231static void
1232client_sensors_setup(gchar *line)
1233 {
1234 Sensor *s;
1235 gchar basename[128], vref[32], default_label[32];
1236
1237 if (need_locale_fix)
1238 locale_fix(line);
1239
1240 s = g_new0(Sensor, 1)(Sensor *) (__extension__ ({ gsize __n = (gsize) (1); gsize __s
= sizeof (Sensor); gpointer __p; if (__s == 1) __p = g_malloc0
(__n); else if (__builtin_constant_p (__n) && (__s ==
0 || __n <= (9223372036854775807L *2UL+1UL) / __s)) __p =
g_malloc0 (__n * __s); else __p = g_malloc0_n (__n, __s); __p
; }))
;
1241 s->group = SENSOR_GROUP_MAINBOARD0; /* Not in pre 2.2.0 versions */
1242 if (sscanf(line,
1243 "%d \"%127[^\"]\" %d %d %d %f %f \"%31[^\"]\" \"%31[^\"]\" %d",
1244 &s->type, basename, &s->id, &s->iodev, &s->inter,
1245 &s->factor, &s->offset, vref, default_label, &s->group) >= 9)
1246 {
1247 s->basename = g_strdup(basename);
1248 if (strcmp(vref, "NONE")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(vref) && __builtin_constant_p ("NONE") && (
__s1_len = strlen (vref), __s2_len = strlen ("NONE"), (!((size_t
)(const void *)((vref) + 1) - (size_t)(const void *)(vref) ==
1) || __s1_len >= 4) && (!((size_t)(const void *)
(("NONE") + 1) - (size_t)(const void *)("NONE") == 1) || __s2_len
>= 4)) ? __builtin_strcmp (vref, "NONE") : (__builtin_constant_p
(vref) && ((size_t)(const void *)((vref) + 1) - (size_t
)(const void *)(vref) == 1) && (__s1_len = strlen (vref
), __s1_len < 4) ? (__builtin_constant_p ("NONE") &&
((size_t)(const void *)(("NONE") + 1) - (size_t)(const void *
)("NONE") == 1) ? __builtin_strcmp (vref, "NONE") : (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) ("NONE"); int __result = (((const unsigned char *) (
const char *) (vref))[0] - __s2[0]); if (__s1_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (vref))[1] - __s2[1]); if (__s1_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (vref))[2] - __s2[2]); if (__s1_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) (vref))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p
("NONE") && ((size_t)(const void *)(("NONE") + 1) - (
size_t)(const void *)("NONE") == 1) && (__s2_len = strlen
("NONE"), __s2_len < 4) ? (__builtin_constant_p (vref) &&
((size_t)(const void *)((vref) + 1) - (size_t)(const void *)
(vref) == 1) ? __builtin_strcmp (vref, "NONE") : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (vref); int __result = (((const unsigned char *) (const
char *) ("NONE"))[0] - __s2[0]); if (__s2_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ("NONE"))[1] - __s2[1]); if (__s2_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) ("NONE"))[2] - __s2[2]); if (__s2_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) ("NONE"))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp
(vref, "NONE")))); })
)
1249 s->vref = g_strdup(vref);
1250 if (strcmp(default_label, "NONE")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(default_label) && __builtin_constant_p ("NONE") &&
(__s1_len = strlen (default_label), __s2_len = strlen ("NONE"
), (!((size_t)(const void *)((default_label) + 1) - (size_t)(
const void *)(default_label) == 1) || __s1_len >= 4) &&
(!((size_t)(const void *)(("NONE") + 1) - (size_t)(const void
*)("NONE") == 1) || __s2_len >= 4)) ? __builtin_strcmp (default_label
, "NONE") : (__builtin_constant_p (default_label) && (
(size_t)(const void *)((default_label) + 1) - (size_t)(const void
*)(default_label) == 1) && (__s1_len = strlen (default_label
), __s1_len < 4) ? (__builtin_constant_p ("NONE") &&
((size_t)(const void *)(("NONE") + 1) - (size_t)(const void *
)("NONE") == 1) ? __builtin_strcmp (default_label, "NONE") : (
__extension__ ({ const unsigned char *__s2 = (const unsigned char
*) (const char *) ("NONE"); int __result = (((const unsigned
char *) (const char *) (default_label))[0] - __s2[0]); if (__s1_len
> 0 && __result == 0) { __result = (((const unsigned
char *) (const char *) (default_label))[1] - __s2[1]); if (__s1_len
> 1 && __result == 0) { __result = (((const unsigned
char *) (const char *) (default_label))[2] - __s2[2]); if (__s1_len
> 2 && __result == 0) __result = (((const unsigned
char *) (const char *) (default_label))[3] - __s2[3]); } } __result
; }))) : (__builtin_constant_p ("NONE") && ((size_t)(
const void *)(("NONE") + 1) - (size_t)(const void *)("NONE") ==
1) && (__s2_len = strlen ("NONE"), __s2_len < 4) ?
(__builtin_constant_p (default_label) && ((size_t)(const
void *)((default_label) + 1) - (size_t)(const void *)(default_label
) == 1) ? __builtin_strcmp (default_label, "NONE") : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (default_label); int __result = (((const unsigned char
*) (const char *) ("NONE"))[0] - __s2[0]); if (__s2_len >
0 && __result == 0) { __result = (((const unsigned char
*) (const char *) ("NONE"))[1] - __s2[1]); if (__s2_len >
1 && __result == 0) { __result = (((const unsigned char
*) (const char *) ("NONE"))[2] - __s2[2]); if (__s2_len >
2 && __result == 0) __result = (((const unsigned char
*) (const char *) ("NONE"))[3] - __s2[3]); } } __result; }))
)) : __builtin_strcmp (default_label, "NONE")))); })
)
1251 s->default_label = g_strdup(default_label);
1252
1253 sensors_list = g_list_append(sensors_list, s);
1254 }
1255 else
1256 g_free(s);
1257 }
1258
1259/* ================================================================= */
1260static time_t server_uptime;
1261
1262static void
1263client_uptime_line_from_server(gchar *s)
1264 {
1265 gulong up_minutes;
1266
1267 sscanf(s, "%lu", &up_minutes);
1268 server_uptime = ((time_t) up_minutes) * 60;
1269 }
1270
1271static time_t
1272client_read_uptime(void)
1273 {
1274 return server_uptime;
1275 }
1276
1277static void
1278client_sys_uptime_init(void)
1279 {
1280 gkrellm_uptime_client_divert(client_read_uptime);
1281 }
1282
1283/* ================================================================= */
1284static struct tm server_time;
1285
1286 /* clock monitor doesn't have a sysdep interface, so it needs a hook
1287 | to get server system time when in client mode.
1288 */
1289struct tm *
1290gkrellm_client_server_time(void)
1291 {
1292 return &server_time;
1293 }
1294
1295static void
1296client_time_line_from_server(gchar *s)
1297 {
1298 struct tm *t;
1299
1300 t = &server_time;
1301 sscanf(s, "%d %d %d %d %d %d %d %d %d",
1302 &t->tm_sec, &t->tm_min, &t->tm_hour,
1303 &t->tm_mday, &t->tm_mon, &t->tm_year,
1304 &t->tm_wday, &t->tm_yday, &t->tm_isdst);
1305 }
1306
1307/* ================================================================= */
1308static void
1309client_server_version_setup(gchar *line)
1310 {
1311 sscanf(line, "%*s %d.%d.%d", &server_major_version,
1312 &server_minor_version, &server_rev_version);
1313 }
1314
1315static void
1316client_hostname_setup(gchar *s)
1317 {
1318 g_free(_GK.server_hostname);
1319 _GK.server_hostname = g_strdup(s);
1320 }
1321
1322static void
1323client_sysname_setup(gchar *s)
1324 {
1325 g_free(_GK.server_sysname);
1326 _GK.server_sysname = g_strdup(s);
1327 }
1328
1329
1330KeyTable monitor_table[] =
1331 {
1332 {"sensors", client_sys_sensors_init },
1333 {"cpu", client_sys_cpu_init },
1334 {"proc", client_sys_proc_init },
1335 {"disk", client_sys_disk_init },
1336 {"net", client_sys_net_init },
1337 {"inet", client_sys_inet_init },
1338 {"mem", client_sys_mem_init },
1339 {"fs", client_sys_fs_init },
1340 {"mail", client_sys_mail_init },
1341 {"apm", client_sys_battery_init },
1342 {"battery", client_sys_battery_init },
1343 {"uptime", client_sys_uptime_init },
1344 };
1345
1346
1347static gboolean setup_done; /* only one sys init */
1348
1349
1350 /* Setup lines are received before monitor init functions are called, so
1351 | for plugins must save the strings until plugins are loaded.
1352 */
1353static GList *client_plugin_setup_line_list;
1354
1355static void
1356client_plugin_add_setup_line(gchar *line)
1357 {
1358 client_plugin_setup_line_list
1359 = g_list_append(client_plugin_setup_line_list, g_strdup(line));
1360 }
1361
1362 /* Plugins should call this in their gkrellm_init_plugin() function.
1363 */
1364void
1365gkrellm_client_plugin_get_setup(gchar *key_name,
1366 void (*setup_func_cb)(gchar *str))
1367 {
1368 GList *list;
1369 gchar *line, *s;
1370 gint n;
1371
1372 if (!_GK.client_mode || !key_name || !setup_func_cb)
1373 return;
1374 for (list = client_plugin_setup_line_list; list; list = list->next)
1375 {
1376 line = (gchar *) list->data;
1377 n = strlen(key_name);
1378 s = line + n;
1379 if (!strncmp(line, key_name, n)(__extension__ (__builtin_constant_p (n) && ((__builtin_constant_p
(line) && strlen (line) < ((size_t) (n))) || (__builtin_constant_p
(key_name) && strlen (key_name) < ((size_t) (n)))
) ? __extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(line) && __builtin_constant_p (key_name) &&
(__s1_len = strlen (line), __s2_len = strlen (key_name), (!(
(size_t)(const void *)((line) + 1) - (size_t)(const void *)(line
) == 1) || __s1_len >= 4) && (!((size_t)(const void
*)((key_name) + 1) - (size_t)(const void *)(key_name) == 1) ||
__s2_len >= 4)) ? __builtin_strcmp (line, key_name) : (__builtin_constant_p
(line) && ((size_t)(const void *)((line) + 1) - (size_t
)(const void *)(line) == 1) && (__s1_len = strlen (line
), __s1_len < 4) ? (__builtin_constant_p (key_name) &&
((size_t)(const void *)((key_name) + 1) - (size_t)(const void
*)(key_name) == 1) ? __builtin_strcmp (line, key_name) : (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (key_name); int __result = (((const unsigned char *)
(const char *) (line))[0] - __s2[0]); if (__s1_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (line))[1] - __s2[1]); if (__s1_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (line))[2] - __s2[2]); if (__s1_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) (line))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p
(key_name) && ((size_t)(const void *)((key_name) + 1
) - (size_t)(const void *)(key_name) == 1) && (__s2_len
= strlen (key_name), __s2_len < 4) ? (__builtin_constant_p
(line) && ((size_t)(const void *)((line) + 1) - (size_t
)(const void *)(line) == 1) ? __builtin_strcmp (line, key_name
) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (line); int __result = (((const unsigned
char *) (const char *) (key_name))[0] - __s2[0]); if (__s2_len
> 0 && __result == 0) { __result = (((const unsigned
char *) (const char *) (key_name))[1] - __s2[1]); if (__s2_len
> 1 && __result == 0) { __result = (((const unsigned
char *) (const char *) (key_name))[2] - __s2[2]); if (__s2_len
> 2 && __result == 0) __result = (((const unsigned
char *) (const char *) (key_name))[3] - __s2[3]); } } __result
; })))) : __builtin_strcmp (line, key_name)))); }) : strncmp (
line, key_name, n)))
&& *s == ' ')
1380 {
1381 while (*s == ' ')
1382 ++s;
1383 (*setup_func_cb)(s);
1384 }
1385 }
1386 }
1387
1388static void
1389client_monitor_setup(gchar *line)
1390 {
1391 void (*func)();
1392 gchar buf[64];
1393 gint i;
1394 gboolean found_builtin = FALSE(0);
1395
1396 if (!*line || setup_done)
1397 return;
1398 for (i = 0; i < sizeof(monitor_table) / sizeof(KeyTable); ++i)
1399 {
1400 if (!strcmp(line, monitor_table[i].key)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(line) && __builtin_constant_p (monitor_table[i].key
) && (__s1_len = strlen (line), __s2_len = strlen (monitor_table
[i].key), (!((size_t)(const void *)((line) + 1) - (size_t)(const
void *)(line) == 1) || __s1_len >= 4) && (!((size_t
)(const void *)((monitor_table[i].key) + 1) - (size_t)(const void
*)(monitor_table[i].key) == 1) || __s2_len >= 4)) ? __builtin_strcmp
(line, monitor_table[i].key) : (__builtin_constant_p (line) &&
((size_t)(const void *)((line) + 1) - (size_t)(const void *)
(line) == 1) && (__s1_len = strlen (line), __s1_len <
4) ? (__builtin_constant_p (monitor_table[i].key) &&
((size_t)(const void *)((monitor_table[i].key) + 1) - (size_t
)(const void *)(monitor_table[i].key) == 1) ? __builtin_strcmp
(line, monitor_table[i].key) : (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) (monitor_table
[i].key); int __result = (((const unsigned char *) (const char
*) (line))[0] - __s2[0]); if (__s1_len > 0 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
line))[1] - __s2[1]); if (__s1_len > 1 && __result
== 0) { __result = (((const unsigned char *) (const char *) (
line))[2] - __s2[2]); if (__s1_len > 2 && __result
== 0) __result = (((const unsigned char *) (const char *) (line
))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (
monitor_table[i].key) && ((size_t)(const void *)((monitor_table
[i].key) + 1) - (size_t)(const void *)(monitor_table[i].key) ==
1) && (__s2_len = strlen (monitor_table[i].key), __s2_len
< 4) ? (__builtin_constant_p (line) && ((size_t)(
const void *)((line) + 1) - (size_t)(const void *)(line) == 1
) ? __builtin_strcmp (line, monitor_table[i].key) : (- (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (line); int __result = (((const unsigned char *) (const
char *) (monitor_table[i].key))[0] - __s2[0]); if (__s2_len >
0 && __result == 0) { __result = (((const unsigned char
*) (const char *) (monitor_table[i].key))[1] - __s2[1]); if (
__s2_len > 1 && __result == 0) { __result = (((const
unsigned char *) (const char *) (monitor_table[i].key))[2] -
__s2[2]); if (__s2_len > 2 && __result == 0) __result
= (((const unsigned char *) (const char *) (monitor_table[i]
.key))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (
line, monitor_table[i].key)))); })
)
1401 {
1402 func = monitor_table[i].func;
1403 (*func)();
1404 found_builtin = TRUE(!(0));
1405 break;
1406 }
1407 }
1408 /* The client mode init work of a plugin must be defered since they
1409 | aren't loaded yet. Set up so they will can get an "available" flag.
1410 */
1411 if (!found_builtin)
1412 {
1413 snprintf(buf, sizeof(buf), "%s available", line);
1414 client_plugin_add_setup_line(buf);
1415 }
1416 }
1417
1418static void
1419client_server_error(gchar *line)
1420 {
1421 fprintf(stderrstderr, "gkrellmd error: %s\n", line);
1422 exit(0);
1423 }
1424
1425
1426static void
1427locale_sync(void)
1428 {
1429 struct lconv *lc;
1430
1431 lc = localeconv();
1432 locale_decimal_point = *lc->decimal_point;
1433 if (locale_decimal_point != server_decimal_point)
1434 need_locale_fix = TRUE(!(0));
1435 }
1436
1437static void
1438client_server_decimal_point(gchar *line)
1439 {
1440 sscanf(line, "%c", &server_decimal_point);
1441 locale_sync();
1442 }
1443
1444static void
1445client_server_io_timeout(gchar *line)
1446 {
1447 sscanf(line, "%d", &_GK.client_server_io_timeout);
1448 if (_GK.client_server_io_timeout < 2)
1449 _GK.client_server_io_timeout = 0;
1450 }
1451
1452static void
1453client_server_reconnect_timeout(gchar *line)
1454 {
1455 sscanf(line, "%d", &_GK.client_server_reconnect_timeout);
1456 if (_GK.client_server_reconnect_timeout < 2)
1457 _GK.client_server_reconnect_timeout = 0;
1458 }
1459
1460
1461/* ================================================================= */
1462KeyTable setup_table[] =
1463 {
1464 {"<version>", client_server_version_setup },
1465 {"<sensors_setup>", client_sensors_setup },
1466 {"<hostname>", client_hostname_setup },
1467 {"<sysname>", client_sysname_setup },
1468 {"<cpu_setup>", client_cpu_setup },
1469 {"<disk_setup>", client_disk_setup },
1470 {"<inet_setup>", client_inet_setup },
1471 {"<net_setup>", client_net_setup },
1472 {"<fs_setup>", client_fs_setup },
1473 {"<mail_setup>", client_mail_setup },
1474 {"<apm_setup>", client_battery_setup },
1475 {"<battery_setup>", client_battery_setup },
1476 {"<time>", client_time_line_from_server},
1477 {"<monitors>", client_monitor_setup },
1478 {"<decimal_point>", client_server_decimal_point },
1479 {"<error>", client_server_error },
1480 {"<io_timeout>", client_server_io_timeout},
1481 {"<reconnect_timeout>", client_server_reconnect_timeout},
1482
1483 {"<plugin_setup>", client_plugin_add_setup_line},
1484 };
1485
1486
1487typedef struct
1488 {
1489 GkrellmMonitor *mon;
1490 gchar *key_name;
1491 void (*func_cb)(gchar *line);
1492 }
1493 ClientPlugin;
1494
1495static GList *client_plugin_serve_data_list;
1496static GList *plugin_initial_update_list;
1497
1498static GkrellmFunc
1499client_plugin_func(gchar *line)
1500 {
1501 GList *list;
1502 ClientPlugin *plug;
1503 void (*func)() = NULL((void*)0);
1504 gchar *s;
1505 gint n;
1506
1507 for (list = client_plugin_serve_data_list; list; list = list->next)
1508 {
1509 plug = (ClientPlugin *) list->data;
1510 if (!plug->key_name)
1511 continue;
1512 n = strlen(plug->key_name);
1513 s = line + n;
1514 if (*s == '>' && !strncmp(plug->key_name, line, n)(__extension__ (__builtin_constant_p (n) && ((__builtin_constant_p
(plug->key_name) && strlen (plug->key_name) <
((size_t) (n))) || (__builtin_constant_p (line) && strlen
(line) < ((size_t) (n)))) ? __extension__ ({ size_t __s1_len
, __s2_len; (__builtin_constant_p (plug->key_name) &&
__builtin_constant_p (line) && (__s1_len = strlen (plug
->key_name), __s2_len = strlen (line), (!((size_t)(const void
*)((plug->key_name) + 1) - (size_t)(const void *)(plug->
key_name) == 1) || __s1_len >= 4) && (!((size_t)(const
void *)((line) + 1) - (size_t)(const void *)(line) == 1) || __s2_len
>= 4)) ? __builtin_strcmp (plug->key_name, line) : (__builtin_constant_p
(plug->key_name) && ((size_t)(const void *)((plug
->key_name) + 1) - (size_t)(const void *)(plug->key_name
) == 1) && (__s1_len = strlen (plug->key_name), __s1_len
< 4) ? (__builtin_constant_p (line) && ((size_t)(
const void *)((line) + 1) - (size_t)(const void *)(line) == 1
) ? __builtin_strcmp (plug->key_name, line) : (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (line); int __result = (((const unsigned char *) (const
char *) (plug->key_name))[0] - __s2[0]); if (__s1_len >
0 && __result == 0) { __result = (((const unsigned char
*) (const char *) (plug->key_name))[1] - __s2[1]); if (__s1_len
> 1 && __result == 0) { __result = (((const unsigned
char *) (const char *) (plug->key_name))[2] - __s2[2]); if
(__s1_len > 2 && __result == 0) __result = (((const
unsigned char *) (const char *) (plug->key_name))[3] - __s2
[3]); } } __result; }))) : (__builtin_constant_p (line) &&
((size_t)(const void *)((line) + 1) - (size_t)(const void *)
(line) == 1) && (__s2_len = strlen (line), __s2_len <
4) ? (__builtin_constant_p (plug->key_name) && ((
size_t)(const void *)((plug->key_name) + 1) - (size_t)(const
void *)(plug->key_name) == 1) ? __builtin_strcmp (plug->
key_name, line) : (- (__extension__ ({ const unsigned char *__s2
= (const unsigned char *) (const char *) (plug->key_name)
; int __result = (((const unsigned char *) (const char *) (line
))[0] - __s2[0]); if (__s2_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) (line
))[1] - __s2[1]); if (__s2_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (line
))[2] - __s2[2]); if (__s2_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (line))
[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (plug->
key_name, line)))); }) : strncmp (plug->key_name, line, n)
))
)
1515 {
1516 func = plug->func_cb;
1517 break;
1518 }
1519 }
1520 return func;
1521 }
1522
1523static void
1524client_plugin_initial_update(ClientPlugin *plug)
1525 {
1526 GList *list;
1527 void (*func)(gchar *);
1528 gchar *line, *serve_name;
1529
1530 func = NULL((void*)0);
1531 serve_name = g_strdup_printf("<%s>", plug->key_name);
1532 for (list = plugin_initial_update_list; list; list = list->next)
1533 {
1534 line = (gchar *) list->data;
1535 if (*line == '<')
1536 {
1537 func = NULL((void*)0);
1538 if (!strcmp(line, serve_name)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(line) && __builtin_constant_p (serve_name) &&
(__s1_len = strlen (line), __s2_len = strlen (serve_name), (
!((size_t)(const void *)((line) + 1) - (size_t)(const void *)
(line) == 1) || __s1_len >= 4) && (!((size_t)(const
void *)((serve_name) + 1) - (size_t)(const void *)(serve_name
) == 1) || __s2_len >= 4)) ? __builtin_strcmp (line, serve_name
) : (__builtin_constant_p (line) && ((size_t)(const void
*)((line) + 1) - (size_t)(const void *)(line) == 1) &&
(__s1_len = strlen (line), __s1_len < 4) ? (__builtin_constant_p
(serve_name) && ((size_t)(const void *)((serve_name)
+ 1) - (size_t)(const void *)(serve_name) == 1) ? __builtin_strcmp
(line, serve_name) : (__extension__ ({ const unsigned char *
__s2 = (const unsigned char *) (const char *) (serve_name); int
__result = (((const unsigned char *) (const char *) (line))[
0] - __s2[0]); if (__s1_len > 0 && __result == 0) {
__result = (((const unsigned char *) (const char *) (line))[
1] - __s2[1]); if (__s1_len > 1 && __result == 0) {
__result = (((const unsigned char *) (const char *) (line))[
2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result
= (((const unsigned char *) (const char *) (line))[3] - __s2
[3]); } } __result; }))) : (__builtin_constant_p (serve_name)
&& ((size_t)(const void *)((serve_name) + 1) - (size_t
)(const void *)(serve_name) == 1) && (__s2_len = strlen
(serve_name), __s2_len < 4) ? (__builtin_constant_p (line
) && ((size_t)(const void *)((line) + 1) - (size_t)(const
void *)(line) == 1) ? __builtin_strcmp (line, serve_name) : (
- (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (line); int __result = (((const unsigned
char *) (const char *) (serve_name))[0] - __s2[0]); if (__s2_len
> 0 && __result == 0) { __result = (((const unsigned
char *) (const char *) (serve_name))[1] - __s2[1]); if (__s2_len
> 1 && __result == 0) { __result = (((const unsigned
char *) (const char *) (serve_name))[2] - __s2[2]); if (__s2_len
> 2 && __result == 0) __result = (((const unsigned
char *) (const char *) (serve_name))[3] - __s2[3]); } } __result
; })))) : __builtin_strcmp (line, serve_name)))); })
)
1539 func = plug->func_cb;
1540 }
1541 else if (func)
1542 (*func)(line);
1543 }
1544 g_free(serve_name);
1545 }
1546
1547void
1548gkrellm_client_plugin_serve_data_connect(GkrellmMonitor *mon,
1549 gchar *key_name, void (*func_cb)(gchar *line))
1550 {
1551 ClientPlugin *plug;
1552
1553 if (!mon || !key_name || !func_cb)
1554 return;
1555 plug = g_new0(ClientPlugin, 1)(ClientPlugin *) (__extension__ ({ gsize __n = (gsize) (1); gsize
__s = sizeof (ClientPlugin); gpointer __p; if (__s == 1) __p
= g_malloc0 (__n); else if (__builtin_constant_p (__n) &&
(__s == 0 || __n <= (9223372036854775807L *2UL+1UL) / __s
)) __p = g_malloc0 (__n * __s); else __p = g_malloc0_n (__n, __s
); __p; }))
;
1556 plug->mon = mon;
1557 plug->key_name = g_strdup(key_name);
1558 plug->func_cb = func_cb;
1559 client_plugin_serve_data_list
1560 = g_list_append(client_plugin_serve_data_list, plug);
1561
1562 client_plugin_initial_update(plug);
1563 }
1564
1565static gboolean
1566client_send_to_server(gchar *buf)
1567 {
1568 gint n;
1569
1570 if (!server_alive || client_fd < 0 || !buf)
1571 return FALSE(0);
1572#if defined(MSG_NOSIGNALMSG_NOSIGNAL)
1573 n = send(client_fd, buf, strlen(buf), MSG_NOSIGNALMSG_NOSIGNAL);
1574#else
1575 n = send(client_fd, buf, strlen(buf), 0);
1576#endif
1577 if (n < 0 && errno(*__errno_location ()) == EPIPE32)
1578 {
1579 gkrellm_debug(DEBUG_CLIENT0x1000, "Write on closed pipe to gkrellmd " \
1580 "server, marking server-connection as dead\n");
1581 server_alive = FALSE(0);
1582 return FALSE(0);
1583 }
1584 return TRUE(!(0));
1585 }
1586
1587gboolean
1588gkrellm_client_send_to_server(gchar *key_name, gchar *line)
1589 {
1590 gchar *str;
1591 gboolean result;
1592
1593 if (!key_name || !line || !*line)
1594 return FALSE(0);
1595 str = g_strdup_printf("<%s>\n", key_name);
1596 client_send_to_server(str);
1597 g_free(str);
1598 if (line[strlen(line) - 1] != '\n')
1599 {
1600 str = g_strdup_printf("%s\n", line);
1601 result = client_send_to_server(str);
1602 g_free(str);
1603 }
1604 else
1605 result = client_send_to_server(line);
1606
1607 return result;
1608 }
1609
1610KeyTable update_table[] =
1611 {
1612 {"<cpu>", client_cpu_line_from_server},
1613 {"<proc>", client_proc_line_from_server},
1614 {"<disk>", client_disk_line_from_server},
1615 {"<net>", client_net_line_from_server},
1616 {"<net_routed>", client_net_routed_line_from_server},
1617 {"<net_timer>", client_net_timer_line_from_server},
1618 {"<mem>", client_mem_line_from_server},
1619 {"<swap>", client_swap_line_from_server},
1620 {"<fs>", client_fs_line_from_server},
1621 {"<fs_fstab>", client_fstab_line_from_server},
1622 {"<fs_mounts>", client_mounts_line_from_server},
1623 {"<inet>", client_inet_line_from_server},
1624 {"<mail>", client_mail_line_from_server},
1625 {"<apm>", client_battery_line_from_server},
1626 {"<battery>", client_battery_line_from_server},
1627 {"<sensors>", client_sensors_line_from_server},
1628 {"<time>", client_time_line_from_server},
1629 {"<uptime>", client_uptime_line_from_server},
1630
1631// {"<>", client__line_from_server},
1632 };
1633
1634
1635
1636/* TODO: Port to GInputStream */
1637static gint
1638gkrellm_getline(gint fd, gchar *buf, gint len)
1639 {
1640 fd_set read_fds;
1641 struct timeval tv;
1642 gchar *s;
1643 gint result, n, nread = 0;
1644
1645 FD_ZERO(&read_fds)do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq"
: "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) /
sizeof (__fd_mask)), "1" (&((&read_fds)->fds_bits
)[0]) : "memory"); } while (0)
;
1646 FD_SET(fd, &read_fds)((void) (((&read_fds)->fds_bits)[((fd) / (8 * (int) sizeof
(__fd_mask)))] |= ((__fd_mask) (1UL << ((fd) % (8 * (int
) sizeof (__fd_mask)))))))
;
1647 tv.tv_usec = 0;
1648 tv.tv_sec = 15;
1649 s = buf;
1650 *s = '\0';
1651 for (n = 0; n < len - 1; ++n)
1652 {
1653 nread = 0;
1654 result = select(fd + 1, &read_fds, NULL((void*)0), NULL((void*)0), &tv);
1655 if (result <= 0 || (nread = recv(fd, s, 1, 0)) != 1)
1656 break;
1657 if (*s == '\n')
1658 {
1659 *s = '\0';
1660 break;
1661 }
1662 *++s = '\0';
1663 }
1664 if (nread < 0 && errno(*__errno_location ()) != EINTR4)
1665 {
1666 g_warning("Broken server connection\n");
1667 exit(0);
1668 }
1669 gkrellm_debug(DEBUG_CLIENT0x1000, "%s\n", buf);
1670 return n;
1671 }
1672
1673static void
1674process_server_line(KeyTable *table, gint table_size, gchar *line)
1675 {
1676 static void (*func)(gchar *);
1677 gint i;
1678
1679 if (!*line || *line == '#')
1680 return;
1681
1682 if (*line == '<')
1683 {
1684 func = NULL((void*)0);
1685 if (line[1] == '.')
1686 {
1687 server_time.tm_sec = atoi(line + 2);
1688 return;
1689 }
1690 for (i = 0; i < table_size; ++i)
1691 {
1692 if (!strcmp(table[i].key, line)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(table[i].key) && __builtin_constant_p (line) &&
(__s1_len = strlen (table[i].key), __s2_len = strlen (line),
(!((size_t)(const void *)((table[i].key) + 1) - (size_t)(const
void *)(table[i].key) == 1) || __s1_len >= 4) && (
!((size_t)(const void *)((line) + 1) - (size_t)(const void *)
(line) == 1) || __s2_len >= 4)) ? __builtin_strcmp (table[
i].key, line) : (__builtin_constant_p (table[i].key) &&
((size_t)(const void *)((table[i].key) + 1) - (size_t)(const
void *)(table[i].key) == 1) && (__s1_len = strlen (table
[i].key), __s1_len < 4) ? (__builtin_constant_p (line) &&
((size_t)(const void *)((line) + 1) - (size_t)(const void *)
(line) == 1) ? __builtin_strcmp (table[i].key, line) : (__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (line); int __result = (((const unsigned char *) (const
char *) (table[i].key))[0] - __s2[0]); if (__s1_len > 0 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (table[i].key))[1] - __s2[1]); if (__s1_len > 1 &&
__result == 0) { __result = (((const unsigned char *) (const
char *) (table[i].key))[2] - __s2[2]); if (__s1_len > 2 &&
__result == 0) __result = (((const unsigned char *) (const char
*) (table[i].key))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p
(line) && ((size_t)(const void *)((line) + 1) - (size_t
)(const void *)(line) == 1) && (__s2_len = strlen (line
), __s2_len < 4) ? (__builtin_constant_p (table[i].key) &&
((size_t)(const void *)((table[i].key) + 1) - (size_t)(const
void *)(table[i].key) == 1) ? __builtin_strcmp (table[i].key
, line) : (- (__extension__ ({ const unsigned char *__s2 = (const
unsigned char *) (const char *) (table[i].key); int __result
= (((const unsigned char *) (const char *) (line))[0] - __s2
[0]); if (__s2_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) (line))[1] - __s2
[1]); if (__s2_len > 1 && __result == 0) { __result
= (((const unsigned char *) (const char *) (line))[2] - __s2
[2]); if (__s2_len > 2 && __result == 0) __result =
(((const unsigned char *) (const char *) (line))[3] - __s2[3
]); } } __result; })))) : __builtin_strcmp (table[i].key, line
)))); })
)
1693 {
1694 func = table[i].func;
1695 break;
1696 }
1697 }
1698 if (!func)
1699 func = client_plugin_func(line + 1);
1700 }
1701 else if (func)
1702 (*func)(line);
1703 if (!func && !setup_done)
1704 plugin_initial_update_list
1705 = g_list_append(plugin_initial_update_list, g_strdup(line));
1706 }
1707
1708
1709 /* Read setup info from gkrellmd server. Stuff needed before the
1710 | client_init calls must be read here.
1711 */
1712static gboolean
1713read_server_setup(gint fd)
1714 {
1715 gchar buf[4097]; /* TODO: Use dynamic receive buffer */
1716 gint table_size;
1717
1718 gkrellm_debug(DEBUG_CLIENT0x1000, "read_server_setup()\n");
1719
1720 /* Pre 2.1.6 gkrellmd does not send <decimal_point>, so put a fallback
1721 | locale_sync() here.
1722 */
1723 locale_sync();
1724 _GK.client_server_read_time = time(0);
1725 table_size = sizeof(setup_table) / sizeof(KeyTable);
1726
1727 gkrellm_free_glist_and_data(&client_plugin_setup_line_list);
1728
1729 gint rs;
1730
1731 while (1)
1732 {
1733 rs = gkrellm_getline(fd, buf, sizeof(buf));
1734 if (rs < 0)
1735 return FALSE(0);
1736 if (!strcmp(buf, "</gkrellmd_setup>")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(buf) && __builtin_constant_p ("</gkrellmd_setup>"
) && (__s1_len = strlen (buf), __s2_len = strlen ("</gkrellmd_setup>"
), (!((size_t)(const void *)((buf) + 1) - (size_t)(const void
*)(buf) == 1) || __s1_len >= 4) && (!((size_t)(const
void *)(("</gkrellmd_setup>") + 1) - (size_t)(const void
*)("</gkrellmd_setup>") == 1) || __s2_len >= 4)) ? __builtin_strcmp
(buf, "</gkrellmd_setup>") : (__builtin_constant_p (buf
) && ((size_t)(const void *)((buf) + 1) - (size_t)(const
void *)(buf) == 1) && (__s1_len = strlen (buf), __s1_len
< 4) ? (__builtin_constant_p ("</gkrellmd_setup>") &&
((size_t)(const void *)(("</gkrellmd_setup>") + 1) - (
size_t)(const void *)("</gkrellmd_setup>") == 1) ? __builtin_strcmp
(buf, "</gkrellmd_setup>") : (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) ("</gkrellmd_setup>"
); int __result = (((const unsigned char *) (const char *) (buf
))[0] - __s2[0]); if (__s1_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) (buf)
)[1] - __s2[1]); if (__s1_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (buf)
)[2] - __s2[2]); if (__s1_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (buf))[
3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("</gkrellmd_setup>"
) && ((size_t)(const void *)(("</gkrellmd_setup>"
) + 1) - (size_t)(const void *)("</gkrellmd_setup>") ==
1) && (__s2_len = strlen ("</gkrellmd_setup>")
, __s2_len < 4) ? (__builtin_constant_p (buf) && (
(size_t)(const void *)((buf) + 1) - (size_t)(const void *)(buf
) == 1) ? __builtin_strcmp (buf, "</gkrellmd_setup>") :
(- (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (buf); int __result = (((const unsigned
char *) (const char *) ("</gkrellmd_setup>"))[0] - __s2
[0]); if (__s2_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) ("</gkrellmd_setup>"
))[1] - __s2[1]); if (__s2_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) ("</gkrellmd_setup>"
))[2] - __s2[2]); if (__s2_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) ("</gkrellmd_setup>"
))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (buf
, "</gkrellmd_setup>")))); })
)
1737 break;
1738 process_server_line(&setup_table[0], table_size, buf);
1739 }
1740
1741 /* Reset any data that is not cumulative. gkrellmd sends .clear tags
1742 | for fstab and mounts, but inet does not. So fix it here.
1743 */
1744 client_inet_reset();
1745
1746 /* Read the initial update data
1747 */
1748 table_size = sizeof(update_table) / sizeof(KeyTable);
1749 while (1)
1750 {
1751 rs = gkrellm_getline(fd, buf, sizeof(buf));
1752 if (rs < 0)
1753 return FALSE(0);
1754 if (!strcmp(buf, "</initial_update>")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p
(buf) && __builtin_constant_p ("</initial_update>"
) && (__s1_len = strlen (buf), __s2_len = strlen ("</initial_update>"
), (!((size_t)(const void *)((buf) + 1) - (size_t)(const void
*)(buf) == 1) || __s1_len >= 4) && (!((size_t)(const
void *)(("</initial_update>") + 1) - (size_t)(const void
*)("</initial_update>") == 1) || __s2_len >= 4)) ? __builtin_strcmp
(buf, "</initial_update>") : (__builtin_constant_p (buf
) && ((size_t)(const void *)((buf) + 1) - (size_t)(const
void *)(buf) == 1) && (__s1_len = strlen (buf), __s1_len
< 4) ? (__builtin_constant_p ("</initial_update>") &&
((size_t)(const void *)(("</initial_update>") + 1) - (
size_t)(const void *)("</initial_update>") == 1) ? __builtin_strcmp
(buf, "</initial_update>") : (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) ("</initial_update>"
); int __result = (((const unsigned char *) (const char *) (buf
))[0] - __s2[0]); if (__s1_len > 0 && __result == 0
) { __result = (((const unsigned char *) (const char *) (buf)
)[1] - __s2[1]); if (__s1_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) (buf)
)[2] - __s2[2]); if (__s1_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) (buf))[
3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ("</initial_update>"
) && ((size_t)(const void *)(("</initial_update>"
) + 1) - (size_t)(const void *)("</initial_update>") ==
1) && (__s2_len = strlen ("</initial_update>")
, __s2_len < 4) ? (__builtin_constant_p (buf) && (
(size_t)(const void *)((buf) + 1) - (size_t)(const void *)(buf
) == 1) ? __builtin_strcmp (buf, "</initial_update>") :
(- (__extension__ ({ const unsigned char *__s2 = (const unsigned
char *) (const char *) (buf); int __result = (((const unsigned
char *) (const char *) ("</initial_update>"))[0] - __s2
[0]); if (__s2_len > 0 && __result == 0) { __result
= (((const unsigned char *) (const char *) ("</initial_update>"
))[1] - __s2[1]); if (__s2_len > 1 && __result == 0
) { __result = (((const unsigned char *) (const char *) ("</initial_update>"
))[2] - __s2[2]); if (__s2_len > 2 && __result == 0
) __result = (((const unsigned char *) (const char *) ("</initial_update>"
))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (buf
, "</initial_update>")))); })
)
1755 break;
1756 process_server_line(&update_table[0], table_size, buf);
1757 }
1758 setup_done = TRUE(!(0));
1759 return TRUE(!(0));
1760 }
1761
1762void
1763gkrellm_client_mode_disconnect(void)
1764 {
1765 if (client_fd >= 0)
1766 {
1767 gkrellm_debug(DEBUG_CLIENT0x1000, "gkrellm_client_mode_disconnect(); " \
1768 "closing connection to server\n");
1769 close(client_fd);
1770 }
1771 client_fd = -1;
1772 server_alive = FALSE(0);
1773 gdk_input_remove(client_input_id);
1774 client_input_id = 0;
1775 }
1776
1777static void
1778read_server_input(gpointer data, gint fd, GdkInputCondition condition)
1779 {
1780 gchar *line, *eol;
1781 gint count, n, table_size;
1782
1783 n = sizeof(server_buf) - buf_index - 1;
1784 count = recv(fd, server_buf + buf_index, n, 0);
1785 if (count <= 0)
1786 {
1787 gkrellm_debug(DEBUG_CLIENT0x1000, "read_server_input(); recv() " \
1788 "returned error, disconnecting from server\n", count);
1789 gkrellm_client_mode_disconnect();
1790 return;
1791 }
1792 if (_GK.time_now > 0)
1793 _GK.client_server_read_time = _GK.time_now;
1794 server_buf[buf_index + count] = '\0';
1795 line = server_buf;
1796 table_size = sizeof(update_table) / sizeof(KeyTable);
1797 while (*line && (eol = strchr(line, '\n')(__extension__ (__builtin_constant_p ('\n') && !__builtin_constant_p
(line) && ('\n') == '\0' ? (char *) __rawmemchr (line
, '\n') : __builtin_strchr (line, '\n')))
) != NULL((void*)0))
1798 {
1799 *eol = '\0';
1800 gkrellm_debug(DEBUG_CLIENT0x1000, "%s\n", line);
1801 process_server_line(&update_table[0], table_size, line);
1802 line = eol + 1;
1803 }
1804 if (line != server_buf && *line)
1805 {
1806 buf_index = strlen(line);
1807 memmove(server_buf, line, buf_index);
1808 }
1809 else if (!*line)
1810 buf_index = 0;
1811 else
1812 {
1813 buf_index += count;
1814 if (buf_index >= sizeof(server_buf) - 2)
1815 buf_index = 0;
1816 }
1817
1818 server_buf[buf_index] = '\0';
1819 }
1820
1821
1822gint
1823gkrellm_connect_to(gchar *server, gint server_port)
1824 {
1825 gint fd = -1;
1826#ifdef HAVE_GETADDRINFO1
1827 gint rv = 0;
1828 struct addrinfo hints, *res, *res0;
1829 gchar portnumber[6];
1830#else
1831 struct hostent *addr;
1832 struct sockaddr_in s;
1833#endif
1834
1835#ifdef HAVE_GETADDRINFO1
1836 snprintf (portnumber, sizeof(portnumber), "%d", server_port);
1837 memset(&hints, 0, sizeof(hints));
1838 hints.ai_family = PF_UNSPEC0;
1839 hints.ai_socktype = SOCK_STREAMSOCK_STREAM;
1840 hints.ai_protocol = 0;
1841 if ((rv = getaddrinfo(server, portnumber, &hints, &res0)) != 0)
1842 return -1;
1843
1844 for (res = res0; res; res = res->ai_next)
1845 {
1846 if ((fd = socket(res->ai_family, res->ai_socktype,
1847 res->ai_protocol)) < 0)
1848 continue;
1849 gkrellm_debug(DEBUG_CLIENT0x1000, "\t[gkrellm_connect_to: (%d,%d,%d) %s:%d]\n",
1850 res->ai_family, res->ai_socktype,
1851 res->ai_protocol, server, server_port);
1852 if (connect(fd, res->ai_addr, res->ai_addrlen) >= 0)
1853 break;
1854#ifdef WIN32
1855 closesocket(fd);
1856#else
1857 close(fd);
1858#endif
1859 fd = -1;
1860 }
1861 freeaddrinfo(res0);
1862#else
1863 gkrellm_debug(DEBUG_CLIENT0x1000, "\t[gkrellm_connect_to: %s:%d]\n", server,
1864 server_port);
1865 addr = gethostbyname(server);
1866 if (addr)
1867 {
1868 fd = socket(AF_INET2, SOCK_STREAMSOCK_STREAM, 0);
1869 if (fd >= 0)
1870 {
1871 memset(&s, 0, sizeof(s));
1872 memcpy(&s.sin_addr.s_addr, addr->h_addrh_addr_list[0], addr->h_length);
1873 s.sin_family = AF_INET2;
1874 s.sin_port = htons(server_port)(__extension__ ({ unsigned short int __v, __x = (unsigned short
int) (server_port); if (__builtin_constant_p (__x)) __v = ((
unsigned short int) ((((__x) >> 8) & 0xff) | (((__x
) & 0xff) << 8))); else __asm__ ("rorw $8, %w0" : "=r"
(__v) : "0" (__x) : "cc"); __v; }))
;
1875 if (connect(fd, (struct sockaddr *)&s, sizeof (s)) < 0)
1876 {
1877 gkrellm_debug(DEBUG_CLIENT0x1000, "gkrellm_connect_to(); connect() failed\n");
1878#ifdef WIN32
1879 closesocket(fd);
1880#else
1881 close(fd);
1882#endif
1883 fd = -1;
1884 }
1885 }
1886 }
1887 else
1888 {
1889 gkrellm_debug(DEBUG_CLIENT0x1000, "gkrellm_connect_to(); gethostbyname() failed\n");
1890 }
1891#endif
1892 if (fd < 0)
1893 return -1;
1894
1895 return fd;
1896 }
1897
1898enum GkrellmConnectResult
1899gkrellm_client_mode_connect(void)
1900 {
1901 gchar buf[128];
1902
1903 if (_GK.server_port == 0)
1904 _GK.server_port = GKRELLMD_SERVER_PORT19150;
1905
1906 client_fd = gkrellm_connect_to(_GK.server, _GK.server_port);
1907 if (client_fd < 0)
1908 return BAD_CONNECT;
1909
1910 snprintf(buf, sizeof(buf), "gkrellm %d.%d.%d%s\n",
1911 GKRELLM_VERSION_MAJOR2, GKRELLM_VERSION_MINOR3,
1912 GKRELLM_VERSION_REV5, GKRELLM_EXTRAVERSION"");
1913 send(client_fd, buf, strlen(buf), 0);
1914
1915 /* Initial setup lines from server are read in blocking mode.
1916 */
1917 if(!read_server_setup(client_fd))
1918 {
1919 close(client_fd);
1920 return BAD_SETUP;
1921 }
1922
1923 /* Extra stuff not handled in read_server_setup()
1924 */
1925 gkrellm_mail_local_unsupported();
1926
1927 /* Now switch to non blocking and set up a read handler.
1928 */
1929#ifndef WIN32
1930 fcntl(client_fd, F_SETFL4, O_NONBLOCK04000);
1931#endif
1932 client_input_id = gdk_input_add(client_fd, GDK_INPUT_READ,
1933 (GdkInputFunction) read_server_input, NULL((void*)0));
1934
1935 server_alive = TRUE(!(0));
1936
1937 return GOOD_CONNECT;
1938 }
1939
1940
1941static gboolean client_mode_thread_busy;
1942
1943enum GkrellmConnectState
1944gkrellm_client_server_connect_state(void)
1945 {
1946 if (client_mode_thread_busy) /* reconnect in progress? */
1947 return CONNECTING;
1948 if (_GK.client_mode && client_input_id > 0) /* Currently connected? */
1949 return CONNECTED;
1950 else if (_GK.client_mode)
1951 return DISCONNECTED;
1952 else
1953 return NO_CLIENT;
1954 }
1955
1956static gpointer
1957client_mode_connect_thread(void *data)
1958 {
1959 gkrellm_client_mode_connect();
1960 client_mode_thread_busy = FALSE(0);
1961 return NULL((void*)0);
1962 }
1963
1964void
1965gkrellm_client_mode_connect_thread(void)
1966 {
1967 if (client_mode_thread_busy || !_GK.client_mode)
1968 return;
1969 client_mode_thread_busy = TRUE(!(0));
1970 g_thread_new("client_mode_connect", client_mode_connect_thread, NULL((void*)0));
1971 }
1972
1973
1974gboolean
1975gkrellm_client_mode(void)
1976 {
1977 return _GK.client_mode;
1978 }