1 /* lib.c */
2 /* This is a generated file.  Please modify `lib.pl' */
3 
4 #include <config.h>
5 
6 #include <glibtop.h>
7 #include <glibtop/error.h>
8 #include <glibtop/open.h>
9 
10 #include <glibtop/sysdeps.h>
11 #include <glibtop/union.h>
12 #include <glib/gi18n-lib.h>
13 
14 #include <glibtop/command.h>
15 
16 /* Some required fields are missing. */
17 
18 static void
_glibtop_missing_feature(glibtop * server,const char * feature,const guint64 present,guint64 * required)19 _glibtop_missing_feature (glibtop *server, const char *feature,
20 			  const guint64 present, guint64 *required)
21 {
22 	guint64 old_required = *required;
23 
24 	/* Return if we have all required fields. */
25 	if ((~present & old_required) == 0)
26 		return;
27 
28 	switch (server->error_method) {
29 	case GLIBTOP_ERROR_METHOD_WARN_ONCE:
30 		*required &= present;
31 	case GLIBTOP_ERROR_METHOD_WARN:
32 		glibtop_warn_r (server,
33 				_("glibtop_get_%s (): Client requested "
34 				  "field mask %05lx, but only have %05lx."),
35 				 feature, (unsigned long) old_required,
36 				 (unsigned long) present);
37 		break;
38 	case GLIBTOP_ERROR_METHOD_ABORT:
39 		glibtop_error_r (server,
40 				 _("glibtop_get_%s (): Client requested "
41 				  "field mask %05lx, but only have %05lx."),
42 				 feature, (unsigned long) old_required,
43 				 (unsigned long) present);
44 		break;
45 	}
46 }
47 
48 /* Library functions. */
49 
50 void
glibtop_get_cpu_l(glibtop * server,glibtop_cpu * buf)51 glibtop_get_cpu_l (glibtop *server, glibtop_cpu *buf)
52 {
53 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_CPU), 0);
54 
55 	/* If neccessary, we ask the server for the requested
56 	 * feature. If not, we call the sysdeps function. */
57 
58 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
59 	    (server->features & (1 << GLIBTOP_SYSDEPS_CPU)))
60 	{
61 		const void *send_ptr = NULL;
62 		const size_t send_size = 0;
63 
64 		glibtop_call_l (server, GLIBTOP_CMND_CPU,
65 				send_size, send_ptr,
66 				sizeof (glibtop_cpu), buf);
67 	} else {
68 #if (!GLIBTOP_SUID_CPU)
69 		glibtop_get_cpu_s (server, buf);
70 #else
71 		errno = ENOSYS;
72 		glibtop_error_io_r (server, "glibtop_get_cpu");
73 #endif
74 	}
75 
76 	/* Make sure that all required fields are present. */
77 
78 	if (buf->flags & server->required.cpu)
79 		_glibtop_missing_feature (server, "cpu", buf->flags,
80 					  &server->required.cpu);
81 }
82 
83 void
glibtop_get_mem_l(glibtop * server,glibtop_mem * buf)84 glibtop_get_mem_l (glibtop *server, glibtop_mem *buf)
85 {
86 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_MEM), 0);
87 
88 	/* If neccessary, we ask the server for the requested
89 	 * feature. If not, we call the sysdeps function. */
90 
91 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
92 	    (server->features & (1 << GLIBTOP_SYSDEPS_MEM)))
93 	{
94 		const void *send_ptr = NULL;
95 		const size_t send_size = 0;
96 
97 		glibtop_call_l (server, GLIBTOP_CMND_MEM,
98 				send_size, send_ptr,
99 				sizeof (glibtop_mem), buf);
100 	} else {
101 #if (!GLIBTOP_SUID_MEM)
102 		glibtop_get_mem_s (server, buf);
103 #else
104 		errno = ENOSYS;
105 		glibtop_error_io_r (server, "glibtop_get_mem");
106 #endif
107 	}
108 
109 	/* Make sure that all required fields are present. */
110 
111 	if (buf->flags & server->required.mem)
112 		_glibtop_missing_feature (server, "mem", buf->flags,
113 					  &server->required.mem);
114 }
115 
116 void
glibtop_get_swap_l(glibtop * server,glibtop_swap * buf)117 glibtop_get_swap_l (glibtop *server, glibtop_swap *buf)
118 {
119 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_SWAP), 0);
120 
121 	/* If neccessary, we ask the server for the requested
122 	 * feature. If not, we call the sysdeps function. */
123 
124 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
125 	    (server->features & (1 << GLIBTOP_SYSDEPS_SWAP)))
126 	{
127 		const void *send_ptr = NULL;
128 		const size_t send_size = 0;
129 
130 		glibtop_call_l (server, GLIBTOP_CMND_SWAP,
131 				send_size, send_ptr,
132 				sizeof (glibtop_swap), buf);
133 	} else {
134 #if (!GLIBTOP_SUID_SWAP)
135 		glibtop_get_swap_s (server, buf);
136 #else
137 		errno = ENOSYS;
138 		glibtop_error_io_r (server, "glibtop_get_swap");
139 #endif
140 	}
141 
142 	/* Make sure that all required fields are present. */
143 
144 	if (buf->flags & server->required.swap)
145 		_glibtop_missing_feature (server, "swap", buf->flags,
146 					  &server->required.swap);
147 }
148 
149 void
glibtop_get_uptime_l(glibtop * server,glibtop_uptime * buf)150 glibtop_get_uptime_l (glibtop *server, glibtop_uptime *buf)
151 {
152 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_UPTIME), 0);
153 
154 	/* If neccessary, we ask the server for the requested
155 	 * feature. If not, we call the sysdeps function. */
156 
157 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
158 	    (server->features & (1 << GLIBTOP_SYSDEPS_UPTIME)))
159 	{
160 		const void *send_ptr = NULL;
161 		const size_t send_size = 0;
162 
163 		glibtop_call_l (server, GLIBTOP_CMND_UPTIME,
164 				send_size, send_ptr,
165 				sizeof (glibtop_uptime), buf);
166 	} else {
167 #if (!GLIBTOP_SUID_UPTIME)
168 		glibtop_get_uptime_s (server, buf);
169 #else
170 		errno = ENOSYS;
171 		glibtop_error_io_r (server, "glibtop_get_uptime");
172 #endif
173 	}
174 
175 	/* Make sure that all required fields are present. */
176 
177 	if (buf->flags & server->required.uptime)
178 		_glibtop_missing_feature (server, "uptime", buf->flags,
179 					  &server->required.uptime);
180 }
181 
182 void
glibtop_get_loadavg_l(glibtop * server,glibtop_loadavg * buf)183 glibtop_get_loadavg_l (glibtop *server, glibtop_loadavg *buf)
184 {
185 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_LOADAVG), 0);
186 
187 	/* If neccessary, we ask the server for the requested
188 	 * feature. If not, we call the sysdeps function. */
189 
190 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
191 	    (server->features & (1 << GLIBTOP_SYSDEPS_LOADAVG)))
192 	{
193 		const void *send_ptr = NULL;
194 		const size_t send_size = 0;
195 
196 		glibtop_call_l (server, GLIBTOP_CMND_LOADAVG,
197 				send_size, send_ptr,
198 				sizeof (glibtop_loadavg), buf);
199 	} else {
200 #if (!GLIBTOP_SUID_LOADAVG)
201 		glibtop_get_loadavg_s (server, buf);
202 #else
203 		errno = ENOSYS;
204 		glibtop_error_io_r (server, "glibtop_get_loadavg");
205 #endif
206 	}
207 
208 	/* Make sure that all required fields are present. */
209 
210 	if (buf->flags & server->required.loadavg)
211 		_glibtop_missing_feature (server, "loadavg", buf->flags,
212 					  &server->required.loadavg);
213 }
214 
215 void
glibtop_get_shm_limits_l(glibtop * server,glibtop_shm_limits * buf)216 glibtop_get_shm_limits_l (glibtop *server, glibtop_shm_limits *buf)
217 {
218 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_SHM_LIMITS), 0);
219 
220 	/* If neccessary, we ask the server for the requested
221 	 * feature. If not, we call the sysdeps function. */
222 
223 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
224 	    (server->features & (1 << GLIBTOP_SYSDEPS_SHM_LIMITS)))
225 	{
226 		const void *send_ptr = NULL;
227 		const size_t send_size = 0;
228 
229 		glibtop_call_l (server, GLIBTOP_CMND_SHM_LIMITS,
230 				send_size, send_ptr,
231 				sizeof (glibtop_shm_limits), buf);
232 	} else {
233 #if (!GLIBTOP_SUID_SHM_LIMITS)
234 		glibtop_get_shm_limits_s (server, buf);
235 #else
236 		errno = ENOSYS;
237 		glibtop_error_io_r (server, "glibtop_get_shm_limits");
238 #endif
239 	}
240 
241 	/* Make sure that all required fields are present. */
242 
243 	if (buf->flags & server->required.shm_limits)
244 		_glibtop_missing_feature (server, "shm_limits", buf->flags,
245 					  &server->required.shm_limits);
246 }
247 
248 void
glibtop_get_msg_limits_l(glibtop * server,glibtop_msg_limits * buf)249 glibtop_get_msg_limits_l (glibtop *server, glibtop_msg_limits *buf)
250 {
251 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_MSG_LIMITS), 0);
252 
253 	/* If neccessary, we ask the server for the requested
254 	 * feature. If not, we call the sysdeps function. */
255 
256 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
257 	    (server->features & (1 << GLIBTOP_SYSDEPS_MSG_LIMITS)))
258 	{
259 		const void *send_ptr = NULL;
260 		const size_t send_size = 0;
261 
262 		glibtop_call_l (server, GLIBTOP_CMND_MSG_LIMITS,
263 				send_size, send_ptr,
264 				sizeof (glibtop_msg_limits), buf);
265 	} else {
266 #if (!GLIBTOP_SUID_MSG_LIMITS)
267 		glibtop_get_msg_limits_s (server, buf);
268 #else
269 		errno = ENOSYS;
270 		glibtop_error_io_r (server, "glibtop_get_msg_limits");
271 #endif
272 	}
273 
274 	/* Make sure that all required fields are present. */
275 
276 	if (buf->flags & server->required.msg_limits)
277 		_glibtop_missing_feature (server, "msg_limits", buf->flags,
278 					  &server->required.msg_limits);
279 }
280 
281 void
glibtop_get_sem_limits_l(glibtop * server,glibtop_sem_limits * buf)282 glibtop_get_sem_limits_l (glibtop *server, glibtop_sem_limits *buf)
283 {
284 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_SEM_LIMITS), 0);
285 
286 	/* If neccessary, we ask the server for the requested
287 	 * feature. If not, we call the sysdeps function. */
288 
289 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
290 	    (server->features & (1 << GLIBTOP_SYSDEPS_SEM_LIMITS)))
291 	{
292 		const void *send_ptr = NULL;
293 		const size_t send_size = 0;
294 
295 		glibtop_call_l (server, GLIBTOP_CMND_SEM_LIMITS,
296 				send_size, send_ptr,
297 				sizeof (glibtop_sem_limits), buf);
298 	} else {
299 #if (!GLIBTOP_SUID_SEM_LIMITS)
300 		glibtop_get_sem_limits_s (server, buf);
301 #else
302 		errno = ENOSYS;
303 		glibtop_error_io_r (server, "glibtop_get_sem_limits");
304 #endif
305 	}
306 
307 	/* Make sure that all required fields are present. */
308 
309 	if (buf->flags & server->required.sem_limits)
310 		_glibtop_missing_feature (server, "sem_limits", buf->flags,
311 					  &server->required.sem_limits);
312 }
313 
314 pid_t*
glibtop_get_proclist_l(glibtop * server,glibtop_proclist * buf,gint64 which,gint64 arg)315 glibtop_get_proclist_l (glibtop *server, glibtop_proclist *buf,
316                         gint64 which, gint64 arg)
317 {
318 	pid_t* retval = (pid_t*) 0;
319 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_PROCLIST), 0);
320 
321 	/* If neccessary, we ask the server for the requested
322 	 * feature. If not, we call the sysdeps function. */
323 
324 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
325 	    (server->features & (1 << GLIBTOP_SYSDEPS_PROCLIST)))
326 	{
327 		struct {
328 			gint64 buf_which;
329 			gint64 buf_arg;
330 		} param_buf;
331 
332 		param_buf.buf_which = which;
333 		param_buf.buf_arg = arg;
334 
335 		const void *send_ptr = &param_buf;
336 		const size_t send_size = sizeof param_buf;
337 
338 		retval = glibtop_call_l (server, GLIBTOP_CMND_PROCLIST,
339 				         send_size, send_ptr,
340 				         sizeof (glibtop_proclist), buf);
341 	} else {
342 #if (!GLIBTOP_SUID_PROCLIST)
343 		retval = glibtop_get_proclist_s (server, buf, which, arg);
344 #else
345 		errno = ENOSYS;
346 		glibtop_error_io_r (server, "glibtop_get_proclist");
347 #endif
348 	}
349 
350 	/* Make sure that all required fields are present. */
351 
352 	if (buf->flags & server->required.proclist)
353 		_glibtop_missing_feature (server, "proclist", buf->flags,
354 					  &server->required.proclist);
355 
356 	/* Now we can return. */
357 
358 	return retval;
359 }
360 
361 void
glibtop_get_proc_state_l(glibtop * server,glibtop_proc_state * buf,pid_t pid)362 glibtop_get_proc_state_l (glibtop *server, glibtop_proc_state *buf,
363                           pid_t pid)
364 {
365 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_PROC_STATE), 0);
366 
367 	/* If neccessary, we ask the server for the requested
368 	 * feature. If not, we call the sysdeps function. */
369 
370 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
371 	    (server->features & (1 << GLIBTOP_SYSDEPS_PROC_STATE)))
372 	{
373 		struct {
374 			pid_t buf_pid;
375 		} param_buf;
376 
377 		param_buf.buf_pid = pid;
378 
379 		const void *send_ptr = &param_buf;
380 		const size_t send_size = sizeof param_buf;
381 
382 		glibtop_call_l (server, GLIBTOP_CMND_PROC_STATE,
383 				send_size, send_ptr,
384 				sizeof (glibtop_proc_state), buf);
385 	} else {
386 #if (!GLIBTOP_SUID_PROC_STATE)
387 		glibtop_get_proc_state_s (server, buf, pid);
388 #else
389 		errno = ENOSYS;
390 		glibtop_error_io_r (server, "glibtop_get_proc_state");
391 #endif
392 	}
393 
394 	/* Make sure that all required fields are present. */
395 
396 	if (buf->flags & server->required.proc_state)
397 		_glibtop_missing_feature (server, "proc_state", buf->flags,
398 					  &server->required.proc_state);
399 }
400 
401 void
glibtop_get_proc_uid_l(glibtop * server,glibtop_proc_uid * buf,pid_t pid)402 glibtop_get_proc_uid_l (glibtop *server, glibtop_proc_uid *buf,
403                         pid_t pid)
404 {
405 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_PROC_UID), 0);
406 
407 	/* If neccessary, we ask the server for the requested
408 	 * feature. If not, we call the sysdeps function. */
409 
410 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
411 	    (server->features & (1 << GLIBTOP_SYSDEPS_PROC_UID)))
412 	{
413 		struct {
414 			pid_t buf_pid;
415 		} param_buf;
416 
417 		param_buf.buf_pid = pid;
418 
419 		const void *send_ptr = &param_buf;
420 		const size_t send_size = sizeof param_buf;
421 
422 		glibtop_call_l (server, GLIBTOP_CMND_PROC_UID,
423 				send_size, send_ptr,
424 				sizeof (glibtop_proc_uid), buf);
425 	} else {
426 #if (!GLIBTOP_SUID_PROC_UID)
427 		glibtop_get_proc_uid_s (server, buf, pid);
428 #else
429 		errno = ENOSYS;
430 		glibtop_error_io_r (server, "glibtop_get_proc_uid");
431 #endif
432 	}
433 
434 	/* Make sure that all required fields are present. */
435 
436 	if (buf->flags & server->required.proc_uid)
437 		_glibtop_missing_feature (server, "proc_uid", buf->flags,
438 					  &server->required.proc_uid);
439 }
440 
441 void
glibtop_get_proc_mem_l(glibtop * server,glibtop_proc_mem * buf,pid_t pid)442 glibtop_get_proc_mem_l (glibtop *server, glibtop_proc_mem *buf,
443                         pid_t pid)
444 {
445 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_PROC_MEM), 0);
446 
447 	/* If neccessary, we ask the server for the requested
448 	 * feature. If not, we call the sysdeps function. */
449 
450 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
451 	    (server->features & (1 << GLIBTOP_SYSDEPS_PROC_MEM)))
452 	{
453 		struct {
454 			pid_t buf_pid;
455 		} param_buf;
456 
457 		param_buf.buf_pid = pid;
458 
459 		const void *send_ptr = &param_buf;
460 		const size_t send_size = sizeof param_buf;
461 
462 		glibtop_call_l (server, GLIBTOP_CMND_PROC_MEM,
463 				send_size, send_ptr,
464 				sizeof (glibtop_proc_mem), buf);
465 	} else {
466 #if (!GLIBTOP_SUID_PROC_MEM)
467 		glibtop_get_proc_mem_s (server, buf, pid);
468 #else
469 		errno = ENOSYS;
470 		glibtop_error_io_r (server, "glibtop_get_proc_mem");
471 #endif
472 	}
473 
474 	/* Make sure that all required fields are present. */
475 
476 	if (buf->flags & server->required.proc_mem)
477 		_glibtop_missing_feature (server, "proc_mem", buf->flags,
478 					  &server->required.proc_mem);
479 }
480 
481 void
glibtop_get_proc_time_l(glibtop * server,glibtop_proc_time * buf,pid_t pid)482 glibtop_get_proc_time_l (glibtop *server, glibtop_proc_time *buf,
483                          pid_t pid)
484 {
485 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_PROC_TIME), 0);
486 
487 	/* If neccessary, we ask the server for the requested
488 	 * feature. If not, we call the sysdeps function. */
489 
490 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
491 	    (server->features & (1 << GLIBTOP_SYSDEPS_PROC_TIME)))
492 	{
493 		struct {
494 			pid_t buf_pid;
495 		} param_buf;
496 
497 		param_buf.buf_pid = pid;
498 
499 		const void *send_ptr = &param_buf;
500 		const size_t send_size = sizeof param_buf;
501 
502 		glibtop_call_l (server, GLIBTOP_CMND_PROC_TIME,
503 				send_size, send_ptr,
504 				sizeof (glibtop_proc_time), buf);
505 	} else {
506 #if (!GLIBTOP_SUID_PROC_TIME)
507 		glibtop_get_proc_time_s (server, buf, pid);
508 #else
509 		errno = ENOSYS;
510 		glibtop_error_io_r (server, "glibtop_get_proc_time");
511 #endif
512 	}
513 
514 	/* Make sure that all required fields are present. */
515 
516 	if (buf->flags & server->required.proc_time)
517 		_glibtop_missing_feature (server, "proc_time", buf->flags,
518 					  &server->required.proc_time);
519 }
520 
521 void
glibtop_get_proc_signal_l(glibtop * server,glibtop_proc_signal * buf,pid_t pid)522 glibtop_get_proc_signal_l (glibtop *server, glibtop_proc_signal *buf,
523                            pid_t pid)
524 {
525 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_PROC_SIGNAL), 0);
526 
527 	/* If neccessary, we ask the server for the requested
528 	 * feature. If not, we call the sysdeps function. */
529 
530 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
531 	    (server->features & (1 << GLIBTOP_SYSDEPS_PROC_SIGNAL)))
532 	{
533 		struct {
534 			pid_t buf_pid;
535 		} param_buf;
536 
537 		param_buf.buf_pid = pid;
538 
539 		const void *send_ptr = &param_buf;
540 		const size_t send_size = sizeof param_buf;
541 
542 		glibtop_call_l (server, GLIBTOP_CMND_PROC_SIGNAL,
543 				send_size, send_ptr,
544 				sizeof (glibtop_proc_signal), buf);
545 	} else {
546 #if (!GLIBTOP_SUID_PROC_SIGNAL)
547 		glibtop_get_proc_signal_s (server, buf, pid);
548 #else
549 		errno = ENOSYS;
550 		glibtop_error_io_r (server, "glibtop_get_proc_signal");
551 #endif
552 	}
553 
554 	/* Make sure that all required fields are present. */
555 
556 	if (buf->flags & server->required.proc_signal)
557 		_glibtop_missing_feature (server, "proc_signal", buf->flags,
558 					  &server->required.proc_signal);
559 }
560 
561 void
glibtop_get_proc_kernel_l(glibtop * server,glibtop_proc_kernel * buf,pid_t pid)562 glibtop_get_proc_kernel_l (glibtop *server, glibtop_proc_kernel *buf,
563                            pid_t pid)
564 {
565 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_PROC_KERNEL), 0);
566 
567 	/* If neccessary, we ask the server for the requested
568 	 * feature. If not, we call the sysdeps function. */
569 
570 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
571 	    (server->features & (1 << GLIBTOP_SYSDEPS_PROC_KERNEL)))
572 	{
573 		struct {
574 			pid_t buf_pid;
575 		} param_buf;
576 
577 		param_buf.buf_pid = pid;
578 
579 		const void *send_ptr = &param_buf;
580 		const size_t send_size = sizeof param_buf;
581 
582 		glibtop_call_l (server, GLIBTOP_CMND_PROC_KERNEL,
583 				send_size, send_ptr,
584 				sizeof (glibtop_proc_kernel), buf);
585 	} else {
586 #if (!GLIBTOP_SUID_PROC_KERNEL)
587 		glibtop_get_proc_kernel_s (server, buf, pid);
588 #else
589 		errno = ENOSYS;
590 		glibtop_error_io_r (server, "glibtop_get_proc_kernel");
591 #endif
592 	}
593 
594 	/* Make sure that all required fields are present. */
595 
596 	if (buf->flags & server->required.proc_kernel)
597 		_glibtop_missing_feature (server, "proc_kernel", buf->flags,
598 					  &server->required.proc_kernel);
599 }
600 
601 void
glibtop_get_proc_segment_l(glibtop * server,glibtop_proc_segment * buf,pid_t pid)602 glibtop_get_proc_segment_l (glibtop *server, glibtop_proc_segment *buf,
603                             pid_t pid)
604 {
605 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_PROC_SEGMENT), 0);
606 
607 	/* If neccessary, we ask the server for the requested
608 	 * feature. If not, we call the sysdeps function. */
609 
610 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
611 	    (server->features & (1 << GLIBTOP_SYSDEPS_PROC_SEGMENT)))
612 	{
613 		struct {
614 			pid_t buf_pid;
615 		} param_buf;
616 
617 		param_buf.buf_pid = pid;
618 
619 		const void *send_ptr = &param_buf;
620 		const size_t send_size = sizeof param_buf;
621 
622 		glibtop_call_l (server, GLIBTOP_CMND_PROC_SEGMENT,
623 				send_size, send_ptr,
624 				sizeof (glibtop_proc_segment), buf);
625 	} else {
626 #if (!GLIBTOP_SUID_PROC_SEGMENT)
627 		glibtop_get_proc_segment_s (server, buf, pid);
628 #else
629 		errno = ENOSYS;
630 		glibtop_error_io_r (server, "glibtop_get_proc_segment");
631 #endif
632 	}
633 
634 	/* Make sure that all required fields are present. */
635 
636 	if (buf->flags & server->required.proc_segment)
637 		_glibtop_missing_feature (server, "proc_segment", buf->flags,
638 					  &server->required.proc_segment);
639 }
640 
641 char *
glibtop_get_proc_args_l(glibtop * server,glibtop_proc_args * buf,pid_t pid,unsigned max_len)642 glibtop_get_proc_args_l (glibtop *server, glibtop_proc_args *buf,
643                          pid_t pid, unsigned max_len)
644 {
645 	char * retval = (char *) 0;
646 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_PROC_ARGS), 0);
647 
648 	/* If neccessary, we ask the server for the requested
649 	 * feature. If not, we call the sysdeps function. */
650 
651 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
652 	    (server->features & (1 << GLIBTOP_SYSDEPS_PROC_ARGS)))
653 	{
654 		struct {
655 			pid_t buf_pid;
656 			unsigned buf_max_len;
657 		} param_buf;
658 
659 		param_buf.buf_pid = pid;
660 		param_buf.buf_max_len = max_len;
661 
662 		const void *send_ptr = &param_buf;
663 		const size_t send_size = sizeof param_buf;
664 
665 		retval = glibtop_call_l (server, GLIBTOP_CMND_PROC_ARGS,
666 				         send_size, send_ptr,
667 				         sizeof (glibtop_proc_args), buf);
668 	} else {
669 #if (!GLIBTOP_SUID_PROC_ARGS)
670 		retval = glibtop_get_proc_args_s (server, buf, pid, max_len);
671 #else
672 		errno = ENOSYS;
673 		glibtop_error_io_r (server, "glibtop_get_proc_args");
674 #endif
675 	}
676 
677 	/* Make sure that all required fields are present. */
678 
679 	if (buf->flags & server->required.proc_args)
680 		_glibtop_missing_feature (server, "proc_args", buf->flags,
681 					  &server->required.proc_args);
682 
683 	/* Now we can return. */
684 
685 	return retval;
686 }
687 
688 glibtop_map_entry *
glibtop_get_proc_map_l(glibtop * server,glibtop_proc_map * buf,pid_t pid)689 glibtop_get_proc_map_l (glibtop *server, glibtop_proc_map *buf,
690                         pid_t pid)
691 {
692 	glibtop_map_entry * retval = (glibtop_map_entry *) 0;
693 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_PROC_MAP), 0);
694 
695 	/* If neccessary, we ask the server for the requested
696 	 * feature. If not, we call the sysdeps function. */
697 
698 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
699 	    (server->features & (1 << GLIBTOP_SYSDEPS_PROC_MAP)))
700 	{
701 		struct {
702 			pid_t buf_pid;
703 		} param_buf;
704 
705 		param_buf.buf_pid = pid;
706 
707 		const void *send_ptr = &param_buf;
708 		const size_t send_size = sizeof param_buf;
709 
710 		retval = glibtop_call_l (server, GLIBTOP_CMND_PROC_MAP,
711 				         send_size, send_ptr,
712 				         sizeof (glibtop_proc_map), buf);
713 	} else {
714 #if (!GLIBTOP_SUID_PROC_MAP)
715 		retval = glibtop_get_proc_map_s (server, buf, pid);
716 #else
717 		errno = ENOSYS;
718 		glibtop_error_io_r (server, "glibtop_get_proc_map");
719 #endif
720 	}
721 
722 	/* Make sure that all required fields are present. */
723 
724 	if (buf->flags & server->required.proc_map)
725 		_glibtop_missing_feature (server, "proc_map", buf->flags,
726 					  &server->required.proc_map);
727 
728 	/* Now we can return. */
729 
730 	return retval;
731 }
732 
733 glibtop_open_files_entry *
glibtop_get_proc_open_files_l(glibtop * server,glibtop_proc_open_files * buf,pid_t pid)734 glibtop_get_proc_open_files_l (glibtop *server, glibtop_proc_open_files *buf,
735                                pid_t pid)
736 {
737 	glibtop_open_files_entry * retval = (glibtop_open_files_entry *) 0;
738 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_PROC_OPEN_FILES), 0);
739 
740 	/* If neccessary, we ask the server for the requested
741 	 * feature. If not, we call the sysdeps function. */
742 
743 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
744 	    (server->features & (1 << GLIBTOP_SYSDEPS_PROC_OPEN_FILES)))
745 	{
746 		struct {
747 			pid_t buf_pid;
748 		} param_buf;
749 
750 		param_buf.buf_pid = pid;
751 
752 		const void *send_ptr = &param_buf;
753 		const size_t send_size = sizeof param_buf;
754 
755 		retval = glibtop_call_l (server, GLIBTOP_CMND_PROC_OPEN_FILES,
756 				         send_size, send_ptr,
757 				         sizeof (glibtop_proc_open_files), buf);
758 	} else {
759 #if (!GLIBTOP_SUID_PROC_OPEN_FILES)
760 		retval = glibtop_get_proc_open_files_s (server, buf, pid);
761 #else
762 		errno = ENOSYS;
763 		glibtop_error_io_r (server, "glibtop_get_proc_open_files");
764 #endif
765 	}
766 
767 	/* Make sure that all required fields are present. */
768 
769 	if (buf->flags & server->required.proc_open_files)
770 		_glibtop_missing_feature (server, "proc_open_files", buf->flags,
771 					  &server->required.proc_open_files);
772 
773 	/* Now we can return. */
774 
775 	return retval;
776 }
777 
778 glibtop_mountentry *
glibtop_get_mountlist_l(glibtop * server,glibtop_mountlist * buf,int all_fs)779 glibtop_get_mountlist_l (glibtop *server, glibtop_mountlist *buf,
780                          int all_fs)
781 {
782 	glibtop_mountentry * retval = (glibtop_mountentry *) 0;
783 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_MOUNTLIST), 0);
784 
785 	/* If neccessary, we ask the server for the requested
786 	 * feature. If not, we call the sysdeps function. */
787 
788 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
789 	    (server->features & (1 << GLIBTOP_SYSDEPS_MOUNTLIST)))
790 	{
791 		struct {
792 			int buf_all_fs;
793 		} param_buf;
794 
795 		param_buf.buf_all_fs = all_fs;
796 
797 		const void *send_ptr = &param_buf;
798 		const size_t send_size = sizeof param_buf;
799 
800 		retval = glibtop_call_l (server, GLIBTOP_CMND_MOUNTLIST,
801 				         send_size, send_ptr,
802 				         sizeof (glibtop_mountlist), buf);
803 	} else {
804 		retval = glibtop_get_mountlist_s (server, buf, all_fs);
805 	}
806 
807 	/* Make sure that all required fields are present. */
808 
809 	if (buf->flags & server->required.mountlist)
810 		_glibtop_missing_feature (server, "mountlist", buf->flags,
811 					  &server->required.mountlist);
812 
813 	/* Now we can return. */
814 
815 	return retval;
816 }
817 
818 void
glibtop_get_fsusage_l(glibtop * server,glibtop_fsusage * buf,const char * mount_dir)819 glibtop_get_fsusage_l (glibtop *server, glibtop_fsusage *buf,
820                        const char *mount_dir)
821 {
822 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_FSUSAGE), 0);
823 
824 	/* If neccessary, we ask the server for the requested
825 	 * feature. If not, we call the sysdeps function. */
826 
827 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
828 	    (server->features & (1 << GLIBTOP_SYSDEPS_FSUSAGE)))
829 	{
830 
831 	const void *send_ptr = mount_dir;
832 
833 	const size_t send_size =
834 		strlen (mount_dir) + 1;
835 
836 		glibtop_call_l (server, GLIBTOP_CMND_FSUSAGE,
837 				send_size, send_ptr,
838 				sizeof (glibtop_fsusage), buf);
839 	} else {
840 		glibtop_get_fsusage_s (server, buf, mount_dir);
841 	}
842 
843 	/* Make sure that all required fields are present. */
844 
845 	if (buf->flags & server->required.fsusage)
846 		_glibtop_missing_feature (server, "fsusage", buf->flags,
847 					  &server->required.fsusage);
848 }
849 
850 void
glibtop_get_netload_l(glibtop * server,glibtop_netload * buf,const char * interface)851 glibtop_get_netload_l (glibtop *server, glibtop_netload *buf,
852                        const char *interface)
853 {
854 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_NETLOAD), 0);
855 
856 	/* If neccessary, we ask the server for the requested
857 	 * feature. If not, we call the sysdeps function. */
858 
859 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
860 	    (server->features & (1 << GLIBTOP_SYSDEPS_NETLOAD)))
861 	{
862 
863 	const void *send_ptr = interface;
864 
865 	const size_t send_size =
866 		strlen (interface) + 1;
867 
868 		glibtop_call_l (server, GLIBTOP_CMND_NETLOAD,
869 				send_size, send_ptr,
870 				sizeof (glibtop_netload), buf);
871 	} else {
872 #if (!GLIBTOP_SUID_NETLOAD)
873 		glibtop_get_netload_s (server, buf, interface);
874 #else
875 		errno = ENOSYS;
876 		glibtop_error_io_r (server, "glibtop_get_netload");
877 #endif
878 	}
879 
880 	/* Make sure that all required fields are present. */
881 
882 	if (buf->flags & server->required.netload)
883 		_glibtop_missing_feature (server, "netload", buf->flags,
884 					  &server->required.netload);
885 }
886 
887 void
glibtop_get_ppp_l(glibtop * server,glibtop_ppp * buf,unsigned short device)888 glibtop_get_ppp_l (glibtop *server, glibtop_ppp *buf,
889                    unsigned short device)
890 {
891 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_PPP), 0);
892 
893 	/* If neccessary, we ask the server for the requested
894 	 * feature. If not, we call the sysdeps function. */
895 
896 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
897 	    (server->features & (1 << GLIBTOP_SYSDEPS_PPP)))
898 	{
899 		struct {
900 			unsigned short buf_device;
901 		} param_buf;
902 
903 		param_buf.buf_device = device;
904 
905 		const void *send_ptr = &param_buf;
906 		const size_t send_size = sizeof param_buf;
907 
908 		glibtop_call_l (server, GLIBTOP_CMND_PPP,
909 				send_size, send_ptr,
910 				sizeof (glibtop_ppp), buf);
911 	} else {
912 #if (!GLIBTOP_SUID_PPP)
913 		glibtop_get_ppp_s (server, buf, device);
914 #else
915 		errno = ENOSYS;
916 		glibtop_error_io_r (server, "glibtop_get_ppp");
917 #endif
918 	}
919 
920 	/* Make sure that all required fields are present. */
921 
922 	if (buf->flags & server->required.ppp)
923 		_glibtop_missing_feature (server, "ppp", buf->flags,
924 					  &server->required.ppp);
925 }
926 
927 char **
glibtop_get_netlist_l(glibtop * server,glibtop_netlist * buf)928 glibtop_get_netlist_l (glibtop *server, glibtop_netlist *buf)
929 {
930 	char ** retval = (char **) 0;
931 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_NETLIST), 0);
932 
933 	/* If neccessary, we ask the server for the requested
934 	 * feature. If not, we call the sysdeps function. */
935 
936 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
937 	    (server->features & (1 << GLIBTOP_SYSDEPS_NETLIST)))
938 	{
939 		const void *send_ptr = NULL;
940 		const size_t send_size = 0;
941 
942 		retval = glibtop_call_l (server, GLIBTOP_CMND_NETLIST,
943 				         send_size, send_ptr,
944 				         sizeof (glibtop_netlist), buf);
945 	} else {
946 #if (!GLIBTOP_SUID_NETLIST)
947 		retval = glibtop_get_netlist_s (server, buf);
948 #else
949 		errno = ENOSYS;
950 		glibtop_error_io_r (server, "glibtop_get_netlist");
951 #endif
952 	}
953 
954 	/* Make sure that all required fields are present. */
955 
956 	if (buf->flags & server->required.netlist)
957 		_glibtop_missing_feature (server, "netlist", buf->flags,
958 					  &server->required.netlist);
959 
960 	/* Now we can return. */
961 
962 	return retval;
963 }
964 
965 char **
glibtop_get_proc_wd_l(glibtop * server,glibtop_proc_wd * buf,pid_t pid)966 glibtop_get_proc_wd_l (glibtop *server, glibtop_proc_wd *buf,
967                        pid_t pid)
968 {
969 	char ** retval = (char **) 0;
970 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_PROC_WD), 0);
971 
972 	/* If neccessary, we ask the server for the requested
973 	 * feature. If not, we call the sysdeps function. */
974 
975 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
976 	    (server->features & (1 << GLIBTOP_SYSDEPS_PROC_WD)))
977 	{
978 		struct {
979 			pid_t buf_pid;
980 		} param_buf;
981 
982 		param_buf.buf_pid = pid;
983 
984 		const void *send_ptr = &param_buf;
985 		const size_t send_size = sizeof param_buf;
986 
987 		retval = glibtop_call_l (server, GLIBTOP_CMND_PROC_WD,
988 				         send_size, send_ptr,
989 				         sizeof (glibtop_proc_wd), buf);
990 	} else {
991 #if (!GLIBTOP_SUID_PROC_WD)
992 		retval = glibtop_get_proc_wd_s (server, buf, pid);
993 #else
994 		errno = ENOSYS;
995 		glibtop_error_io_r (server, "glibtop_get_proc_wd");
996 #endif
997 	}
998 
999 	/* Make sure that all required fields are present. */
1000 
1001 	if (buf->flags & server->required.proc_wd)
1002 		_glibtop_missing_feature (server, "proc_wd", buf->flags,
1003 					  &server->required.proc_wd);
1004 
1005 	/* Now we can return. */
1006 
1007 	return retval;
1008 }
1009 
1010 guint16*
glibtop_get_proc_affinity_l(glibtop * server,glibtop_proc_affinity * buf,pid_t pid)1011 glibtop_get_proc_affinity_l (glibtop *server, glibtop_proc_affinity *buf,
1012                              pid_t pid)
1013 {
1014 	guint16* retval = (guint16*) 0;
1015 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_PROC_AFFINITY), 0);
1016 
1017 	/* If neccessary, we ask the server for the requested
1018 	 * feature. If not, we call the sysdeps function. */
1019 
1020 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
1021 	    (server->features & (1 << GLIBTOP_SYSDEPS_PROC_AFFINITY)))
1022 	{
1023 		struct {
1024 			pid_t buf_pid;
1025 		} param_buf;
1026 
1027 		param_buf.buf_pid = pid;
1028 
1029 		const void *send_ptr = &param_buf;
1030 		const size_t send_size = sizeof param_buf;
1031 
1032 		retval = glibtop_call_l (server, GLIBTOP_CMND_PROC_AFFINITY,
1033 				         send_size, send_ptr,
1034 				         sizeof (glibtop_proc_affinity), buf);
1035 	} else {
1036 #if (!GLIBTOP_SUID_PROC_AFFINITY)
1037 		retval = glibtop_get_proc_affinity_s (server, buf, pid);
1038 #else
1039 		errno = ENOSYS;
1040 		glibtop_error_io_r (server, "glibtop_get_proc_affinity");
1041 #endif
1042 	}
1043 
1044 	/* Make sure that all required fields are present. */
1045 
1046 	if (buf->flags & server->required.proc_affinity)
1047 		_glibtop_missing_feature (server, "proc_affinity", buf->flags,
1048 					  &server->required.proc_affinity);
1049 
1050 	/* Now we can return. */
1051 
1052 	return retval;
1053 }
1054 
1055 void
glibtop_get_proc_io_l(glibtop * server,glibtop_proc_io * buf,pid_t pid)1056 glibtop_get_proc_io_l (glibtop *server, glibtop_proc_io *buf,
1057                        pid_t pid)
1058 {
1059 	glibtop_init_r (&server, (1 << GLIBTOP_SYSDEPS_PROC_IO), 0);
1060 
1061 	/* If neccessary, we ask the server for the requested
1062 	 * feature. If not, we call the sysdeps function. */
1063 
1064 	if ((server->flags & _GLIBTOP_INIT_STATE_SERVER) &&
1065 	    (server->features & (1 << GLIBTOP_SYSDEPS_PROC_IO)))
1066 	{
1067 		struct {
1068 			pid_t buf_pid;
1069 		} param_buf;
1070 
1071 		param_buf.buf_pid = pid;
1072 
1073 		const void *send_ptr = &param_buf;
1074 		const size_t send_size = sizeof param_buf;
1075 
1076 		glibtop_call_l (server, GLIBTOP_CMND_PROC_IO,
1077 				send_size, send_ptr,
1078 				sizeof (glibtop_proc_io), buf);
1079 	} else {
1080 #if (!GLIBTOP_SUID_PROC_IO)
1081 		glibtop_get_proc_io_s (server, buf, pid);
1082 #else
1083 		errno = ENOSYS;
1084 		glibtop_error_io_r (server, "glibtop_get_proc_io");
1085 #endif
1086 	}
1087 
1088 	/* Make sure that all required fields are present. */
1089 
1090 	if (buf->flags & server->required.proc_io)
1091 		_glibtop_missing_feature (server, "proc_io", buf->flags,
1092 					  &server->required.proc_io);
1093 }
1094 
1095