This file is indexed.

/usr/include/statgrab.h is in libstatgrab-dev 0.91-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
/*
 * i-scream libstatgrab
 * http://www.i-scream.org
 * Copyright (C) 2000-2013 i-scream
 * Copyright (C) 2010-2013 Jens Rehsack
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 *
 * $Id$
 */

#ifndef STATGRAB_H
#define STATGRAB_H

#ifdef __cplusplus
extern "C" {
#endif

#include <sys/types.h>
#include <time.h>

#if 0
#define __sg_export 
#define __sg_import 
#define __sg_private 
#else
#define __sg_export
#define __sg_import
#define __sg_private
#endif

#ifdef BUILD_LIBSTATGRAB
#define __sg_public __sg_export
#else
#define __sg_public __sg_import
#endif

/* FIXME typedefs for 32/64-bit types */
/* FIXME maybe tidy up field names? */
/* FIXME comments for less obvious fields */

typedef enum {
	SG_ERROR_NONE = 0,
	SG_ERROR_INVALID_ARGUMENT,
	SG_ERROR_ASPRINTF,
	SG_ERROR_SPRINTF,
	SG_ERROR_DEVICES,
	SG_ERROR_DEVSTAT_GETDEVS,
	SG_ERROR_DEVSTAT_SELECTDEVS,
	SG_ERROR_DISKINFO,
	SG_ERROR_ENOENT,
	SG_ERROR_GETIFADDRS,
	SG_ERROR_GETMNTINFO,
	SG_ERROR_GETPAGESIZE,
	SG_ERROR_HOST,
	SG_ERROR_KSTAT_DATA_LOOKUP,
	SG_ERROR_KSTAT_LOOKUP,
	SG_ERROR_KSTAT_OPEN,
	SG_ERROR_KSTAT_READ,
	SG_ERROR_KVM_GETSWAPINFO,
	SG_ERROR_KVM_OPENFILES,
	SG_ERROR_MALLOC,
	SG_ERROR_MEMSTATUS,
	SG_ERROR_OPEN,
	SG_ERROR_OPENDIR,
	SG_ERROR_READDIR,
	SG_ERROR_PARSE,
	SG_ERROR_PDHADD,
	SG_ERROR_PDHCOLLECT,
	SG_ERROR_PDHOPEN,
	SG_ERROR_PDHREAD,
	SG_ERROR_PERMISSION,
	SG_ERROR_PSTAT,
	SG_ERROR_SETEGID,
	SG_ERROR_SETEUID,
	SG_ERROR_SETMNTENT,
	SG_ERROR_SOCKET,
	SG_ERROR_SWAPCTL,
	SG_ERROR_SYSCONF,
	SG_ERROR_SYSCTL,
	SG_ERROR_SYSCTLBYNAME,
	SG_ERROR_SYSCTLNAMETOMIB,
	SG_ERROR_SYSINFO,
	SG_ERROR_MACHCALL,
	SG_ERROR_IOKIT,
	SG_ERROR_UNAME,
	SG_ERROR_UNSUPPORTED,
	SG_ERROR_XSW_VER_MISMATCH,
	SG_ERROR_GETMSG,
	SG_ERROR_PUTMSG,
	SG_ERROR_INITIALISATION,
	SG_ERROR_MUTEX_LOCK,
	SG_ERROR_MUTEX_UNLOCK
} sg_error;

typedef struct sg_error_details {
	sg_error error;
	int errno_value;
	const char *error_arg;
} sg_error_details;

__sg_public sg_error sg_get_error(void);
__sg_public const char *sg_get_error_arg(void);
__sg_public int sg_get_error_errno(void);
__sg_public sg_error sg_get_error_details(sg_error_details *err_details);
__sg_public const char * sg_str_error(sg_error code);
__sg_public char *sg_strperror(char **buf, const sg_error_details * const err_details);

/*
 * initializes libstatgrab
 * @param ignore_init_errors - set to a true value to ignore initialization
 *   errors of component initializations (e.g. permission problems for kvm
 *   on freebsd)
 * XXX requires each component to provide a get_<comp>_init_error() and a
 *   reinit_<comp>()
 */
__sg_public sg_error sg_init(int ignore_init_errors);
__sg_public sg_error sg_snapshot(void);
__sg_public sg_error sg_shutdown(void);
__sg_public sg_error sg_drop_privileges(void);

__sg_public size_t sg_get_nelements(const void *data);
__sg_public sg_error sg_free_stats_buf(void *data);
#if 1
#define SG_SUPPORT_THREADS
__sg_public sg_error sg_lock_mutex(const char *mutex_name);
__sg_public sg_error sg_unlock_mutex(const char *mutex_name);
#else
#define sg_lock_mutex(name) SG_ERROR_NONE
#define sg_unlock_mutex(name) SG_ERROR_NONE
#endif

typedef enum {
	sg_unknown_configuration = 0,
	sg_physical_host,
	sg_virtual_machine,
	sg_paravirtual_machine,
	sg_hardware_virtualized
} sg_host_state;

typedef struct {
	char *os_name;
	char *os_release;
	char *os_version;
	char *platform;
	char *hostname;
	unsigned bitwidth;
	sg_host_state host_state;
	unsigned ncpus;
	unsigned maxcpus;
	time_t uptime;
	time_t systime;
} sg_host_info;

__sg_public sg_host_info *sg_get_host_info(size_t *entries);
__sg_public sg_host_info *sg_get_host_info_r(size_t *entries);
#define sg_free_host_info(data) sg_free_stats_buf(data);

typedef struct {
	unsigned long long user;
	unsigned long long kernel;
	unsigned long long idle;
	unsigned long long iowait;
	unsigned long long swap;
	unsigned long long nice;
	unsigned long long total;

	unsigned long long context_switches;
	unsigned long long voluntary_context_switches;
	unsigned long long involuntary_context_switches;
	unsigned long long syscalls;
	unsigned long long interrupts;
	unsigned long long soft_interrupts;

	time_t systime;
} sg_cpu_stats;

__sg_public sg_cpu_stats *sg_get_cpu_stats(size_t *entries);
__sg_public sg_cpu_stats *sg_get_cpu_stats_diff(size_t *entries);
__sg_public sg_cpu_stats *sg_get_cpu_stats_r(size_t *entries);
__sg_public sg_cpu_stats *sg_get_cpu_stats_diff_between(const sg_cpu_stats *cpu_now, const sg_cpu_stats *cpu_last, size_t *entries);
#define sg_free_cpu_stats(data) sg_free_stats_buf(data);

typedef struct {
	double user;
	double kernel;
	double idle;
	double iowait;
	double swap;
	double nice;
	time_t time_taken;
} sg_cpu_percents;

typedef enum sg_cpu_percent_source {
	sg_entire_cpu_percent,
	sg_last_diff_cpu_percent,
	sg_new_diff_cpu_percent
} sg_cpu_percent_source;

__sg_public sg_cpu_percents *sg_get_cpu_percents_of(sg_cpu_percent_source cps, size_t *entries);
__sg_public sg_cpu_percents *sg_get_cpu_percents_r(sg_cpu_stats const * whereof, size_t *entries);
#define sg_free_cpu_percents(data) sg_free_stats_buf(data);

#define sg_get_cpu_percents(entries) sg_get_cpu_percents_of(sg_new_diff_cpu_percent, entries)

typedef struct {
	unsigned long long total;
	unsigned long long free;
	unsigned long long used;
	unsigned long long cache;
	time_t systime;
} sg_mem_stats;

__sg_public sg_mem_stats *sg_get_mem_stats(size_t *entries);
__sg_public sg_mem_stats *sg_get_mem_stats_r(size_t *entries);
#define sg_free_mem_stats(data) sg_free_stats_buf(data);

typedef struct {
	double min1;
	double min5;
	double min15;
	time_t systime;
} sg_load_stats;

__sg_public sg_load_stats *sg_get_load_stats(size_t *entries);
__sg_public sg_load_stats *sg_get_load_stats_r(size_t *entries);
#define sg_free_load_stats(data) sg_free_stats_buf(data);

typedef struct {
	char *login_name;
	char *record_id;
	size_t record_id_size;
	char *device;
	char *hostname;
	pid_t pid; /* XXX sugesting to ad a uid here, too (padding + lookup-cache?) */
	time_t login_time;
	time_t systime;
} sg_user_stats;

__sg_public sg_user_stats *sg_get_user_stats(size_t *entries);
__sg_public sg_user_stats *sg_get_user_stats_r(size_t *entries);
#define sg_free_user_stats(data) sg_free_stats_buf(data);

typedef struct {
	unsigned long long total;
	unsigned long long used;
	unsigned long long free;
	time_t systime;
} sg_swap_stats;

__sg_public sg_swap_stats *sg_get_swap_stats(size_t *entries);
__sg_public sg_swap_stats *sg_get_swap_stats_r(size_t *entries);
#define sg_free_swap_stats(data) sg_free_stats_buf(data);

typedef enum {
	sg_fs_unknown  = 0,
	sg_fs_regular  = 1 << 0,
	sg_fs_special  = 1 << 1,
	sg_fs_loopback = 1 << 2,
	sg_fs_remote   = 1 << 3,
	sg_fs_local    = (sg_fs_regular | sg_fs_special),
	sg_fs_alltypes = (sg_fs_regular | sg_fs_special | sg_fs_loopback | sg_fs_remote)
} sg_fs_device_type;

typedef struct {
	char *device_name;
	char *device_canonical;
	char *fs_type;
	char *mnt_point;
	sg_fs_device_type device_type; /* XXX this isn't an enum, it's a bit-mask */
	unsigned long long size;
	unsigned long long used;
	unsigned long long free;
	unsigned long long avail;
	unsigned long long total_inodes;
	unsigned long long used_inodes;
	unsigned long long free_inodes;
	unsigned long long avail_inodes;
	unsigned long long io_size;
	unsigned long long block_size;
	unsigned long long total_blocks;
	unsigned long long free_blocks;
	unsigned long long used_blocks;
	unsigned long long avail_blocks;
	time_t systime;
} sg_fs_stats;

__sg_public const char **sg_get_valid_filesystems(size_t *entries);
__sg_public sg_error sg_set_valid_filesystems(const char *valid_fs[]);

__sg_public sg_fs_stats *sg_get_fs_stats(size_t *entries);
__sg_public sg_fs_stats *sg_get_fs_stats_r(size_t *entries);
__sg_public sg_fs_stats *sg_get_fs_stats_diff(size_t *entries);
__sg_public sg_fs_stats *sg_get_fs_stats_diff_between(const sg_fs_stats *cur, const sg_fs_stats *last, size_t *entries);
#define sg_free_fs_stats(data) sg_free_stats_buf(data);

__sg_public int sg_fs_compare_device_name(const void *va, const void *vb);
__sg_public int sg_fs_compare_mnt_point(const void *va, const void *vb);

typedef struct {
	char *disk_name;
	unsigned long long read_bytes;
	unsigned long long write_bytes;
	time_t systime;
} sg_disk_io_stats;

__sg_public sg_disk_io_stats *sg_get_disk_io_stats(size_t *entries);
__sg_public sg_disk_io_stats *sg_get_disk_io_stats_r(size_t *entries);
__sg_public sg_disk_io_stats *sg_get_disk_io_stats_diff(size_t *entries);
__sg_public sg_disk_io_stats *sg_get_disk_io_stats_diff_between(const sg_disk_io_stats *cur, const sg_disk_io_stats *last, size_t *entries);
#define sg_free_disk_io_stats(data) sg_free_stats_buf(data);

__sg_public int sg_disk_io_compare_name(const void *va, const void *vb);
__sg_public int sg_disk_io_compare_traffic(const void *va, const void *vb);

typedef struct {
	char *interface_name;
	unsigned long long tx;
	unsigned long long rx;
	unsigned long long ipackets;
	unsigned long long opackets;
	unsigned long long ierrors;
	unsigned long long oerrors;
	unsigned long long collisions;
	time_t systime;
} sg_network_io_stats;

__sg_public sg_network_io_stats *sg_get_network_io_stats(size_t *entries);
__sg_public sg_network_io_stats *sg_get_network_io_stats_r(size_t *entries);
__sg_public sg_network_io_stats *sg_get_network_io_stats_diff(size_t *entries);
__sg_public sg_network_io_stats *sg_get_network_io_stats_diff_between(const sg_network_io_stats *cur, const sg_network_io_stats *last, size_t *entries);
#define sg_free_network_io_stats(data) sg_free_stats_buf(data);

__sg_public int sg_network_io_compare_name(const void *va, const void *vb);

typedef enum {
	SG_IFACE_DUPLEX_FULL,
	SG_IFACE_DUPLEX_HALF,
	SG_IFACE_DUPLEX_UNKNOWN
} sg_iface_duplex;

typedef enum {
	SG_IFACE_DOWN = 0,
	SG_IFACE_UP
} sg_iface_updown;

typedef struct {
	char *interface_name;
	unsigned long long speed;	/* In factor/sec */
	unsigned long long factor;
	sg_iface_duplex duplex;
	sg_iface_updown up;
	time_t systime;
} sg_network_iface_stats;

__sg_public sg_network_iface_stats *sg_get_network_iface_stats(size_t *entries);
__sg_public sg_network_iface_stats *sg_get_network_iface_stats_r(size_t *entries);
#define sg_free_network_iface_stats(data) sg_free_stats_buf(data);

__sg_public int sg_network_iface_compare_name(const void *va, const void *vb);

typedef struct {
	unsigned long long pages_pagein;
	unsigned long long pages_pageout;
	time_t systime;
} sg_page_stats;

__sg_public sg_page_stats *sg_get_page_stats(size_t *entries);
__sg_public sg_page_stats *sg_get_page_stats_r(size_t *entries);
__sg_public sg_page_stats *sg_get_page_stats_diff(size_t *entries);
__sg_public sg_page_stats *sg_get_page_stats_diff_between(const sg_page_stats *now, const sg_page_stats *last, size_t *entries);
#define sg_free_page_stats(data) sg_free_stats_buf(data);

/* Recommend to add SG_PROCESS_STATE_IDLE */
typedef enum {
	SG_PROCESS_STATE_RUNNING,
	SG_PROCESS_STATE_SLEEPING,
	SG_PROCESS_STATE_STOPPED,
	SG_PROCESS_STATE_ZOMBIE,
	SG_PROCESS_STATE_UNKNOWN
} sg_process_state;

typedef struct {
	char *process_name;
	char *proctitle;

	pid_t pid;
	pid_t parent; /* Parent pid */
	pid_t pgid;   /* process id of process group leader */
	pid_t sessid; /* session id of the session the process belongs to */


/* Windows does not have uid_t or gid_t types */
#ifndef WIN32
	uid_t uid;
	uid_t euid;
	gid_t gid;
	gid_t egid;
#else
	int uid;
	int euid;
	int gid;
	int egid;
#endif

	unsigned long long context_switches;
	unsigned long long voluntary_context_switches;
	unsigned long long involuntary_context_switches;
	unsigned long long proc_size; /* in bytes */
	unsigned long long proc_resident; /* in bytes */
	time_t start_time; /* When was the process started */
	time_t time_spent; /* time running in seconds */
	double cpu_percent;
	int nice;
	sg_process_state state;

	time_t systime;
} sg_process_stats;

__sg_public sg_process_stats *sg_get_process_stats(size_t *entries);
__sg_public sg_process_stats *sg_get_process_stats_r(size_t *entries);
#define sg_free_process_stats(data) sg_free_stats_buf(data);

__sg_public int sg_process_compare_name(const void *va, const void *vb);
__sg_public int sg_process_compare_pid(const void *va, const void *vb);
__sg_public int sg_process_compare_uid(const void *va, const void *vb);
__sg_public int sg_process_compare_gid(const void *va, const void *vb);
__sg_public int sg_process_compare_size(const void *va, const void *vb);
__sg_public int sg_process_compare_res(const void *va, const void *vb);
__sg_public int sg_process_compare_cpu(const void *va, const void *vb);
__sg_public int sg_process_compare_time(const void *va, const void *vb);

typedef struct {
	unsigned long long total;
	unsigned long long running;
	unsigned long long sleeping;
	unsigned long long stopped;
	unsigned long long zombie;
	unsigned long long unknown;
	time_t systime;
} sg_process_count;

typedef enum sg_process_count_source {
	sg_entire_process_count,
	sg_last_process_count
} sg_process_count_source;

__sg_public sg_process_count *sg_get_process_count_of(sg_process_count_source pcs);
__sg_public sg_process_count *sg_get_process_count_r(sg_process_stats const * whereof);
#define sg_get_process_count() sg_get_process_count_of(sg_entire_process_count)
#define sg_free_process_count(data) sg_free_stats_buf(data);

#if 0
void sg_log_init(const char *properties_pfx, const char *env_name, const char *argv0);
#else
#define sg_log_init(properties_pfx, env_name, argv0) \
	do { (void)(properties_pfx); (void)(env_name); (void)(argv0); } while(0);
#endif

#ifdef __cplusplus
}
#endif

#endif