This file is indexed.

/var/lib/pcp/testsuite/src/pmdaqueue.c is in pcp-testsuite 3.8.12ubuntu1.

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
#include <pcp/pmapi.h>
#include <pcp/impl.h>
#include <pcp/pmda.h>

/*
 * Make a dummy event, timestamped now
 */
void *make_event(size_t size, struct timeval *tv)
{
    void *buffer = malloc(size);
    if (buffer)
	memset(buffer, 0xA, size);
    gettimeofday(tv, NULL);
    return buffer;
}

/*
 * Simple filter based on event size, also report whenever called
 */
int apply_filter(void *data, void *event, size_t size)
{
    size_t filter = *(size_t *)data;

    fprintf(stderr, "=> apply-filter(%d<%d) -> %d\n",
	    (int)filter, (int)size, size >= filter);
    return (size >= filter);
}

/*
 * Client context ended, ensure release method is called
 */
void release_filter(void *data)
{
    size_t filter = *(size_t *)data;
    fprintf(stderr, "=> release filter(%d)\n", (int)filter);
}

/*
 * Report stats about the state of given queue identifier
 */
void queue_statistics(int q)
{
    pmAtomValue count, bytes, clients, memory;

    pmdaEventQueueCounter(q, &count);
    pmdaEventQueueBytes(q, &bytes);
    pmdaEventQueueClients(q, &clients);
    pmdaEventQueueMemory(q, &memory);

    fprintf(stderr, "event queue#%d count=%d, bytes=%d, clients=%d, mem=%lld\n",
	    q, (int)count.ul, (int)bytes.ull, (int)clients.ul,
	    (long long)memory.ull);
}

/*
 * Report and check contents of events in a given queue identifier
 * decode_event is a callback, called once per-event.
 */

int decode_event(int key, void *event, size_t size,
		 struct timeval *timestamp, void *data)
{
    char *buffer = (char *)event;
    int *datap = (int *)data;
    int queueid = datap[0];
    int context = datap[1];
    int i, ok = 1;

    for (i = 0; i < size; i++)
	if (buffer[i] != 0xA)
	    ok = 0;
    fprintf(stderr, "queue#%d client#%d event: %p, size=%d check=%s\n",
	    queueid, context, event, (int)size, ok? "ok" : "bad");
    return 0;
}

void queue_events(int q, int context)
{
    pmAtomValue records;
    int data[2] = { q, context };

    fprintf(stderr, "walking queue#%d events for client#%d\n", q, context);
    pmdaEventQueueRecords(q, &records, context, decode_event, &data);
    fprintf(stderr, "end walk queue#%d\n", q);
}

int
main(int argc, char **argv)
{
    int	c, sts;
    int errflag = 0;
    int context, queueid;
    size_t size;
    size_t filter_size;
    struct timeval tv;
    char *s, *name;
    void *event;

    __pmSetProgname(argv[0]);

    while ((c = getopt(argc, argv, "A:a:C:c:D:E:e:F:f:q:s:S:")) != EOF) {
	switch (c) {

	case 'a':	/* disallow a clients queue access */
	case 'A':	/* allow a clients queue access */
	    s = optarg;
	    name = strsep(&s, ",");
	    if (!s) {
		fprintf(stderr, "%s: invalid client queue access specification (%s)\n",
			pmProgname, optarg);
		errflag++;
		break;
	    }
	    context = atoi(name);
	    queueid = pmdaEventQueueHandle(s);

	    sts = pmdaEventSetAccess(context, queueid, (c == 'A'));
	    fprintf(stderr, "enable queue#%d access(%d) -> %d",
			    queueid, context, (c == 'A'));
	    if (sts < 0) fprintf(stderr, " %s", pmErrStr(sts));
	    fputc('\n', stderr);
	    break;

	case 'c':	/* new client: ID */
	    context = atoi(optarg);
	    sts = pmdaEventNewClient(context);
	    fprintf(stderr, "new client(%d) -> %d", context, sts);
	    if (sts < 0) fprintf(stderr, " %s", pmErrStr(sts));
	    fputc('\n', stderr);
	    break;

	case 'C':	/* remove client: ID */
	    context = atoi(optarg);
	    sts = pmdaEventEndClient(context);
	    fprintf(stderr, "end client(%d) -> %d", context, sts);
	    if (sts < 0) fprintf(stderr, " %s", pmErrStr(sts));
	    fputc('\n', stderr);
	    break;

	case 'D':	/* debug flag */
	    sts = __pmParseDebug(optarg);
	    if (sts < 0) {
		fprintf(stderr, "%s: unrecognized debug flag specification (%s)\n",
		    pmProgname, optarg);
		errflag++;
	    }
	    else
		pmDebug |= sts;
	    break;

	case 'e':	/* create an event on named queue of given size */
	    s = optarg;
	    name = strsep(&s, ",");
	    if (!s) {
		fprintf(stderr, "%s: invalid event size specification (%s)\n",
			pmProgname, optarg);
		errflag++;
		break;
	    }
	    size = atoi(s);
	    queueid = pmdaEventQueueHandle(name);
	    if (queueid < 0) {
		fprintf(stderr, "%s: invalid event queue specification (%s)\n",
			pmProgname, name);
		errflag++;
		break;
	    }
	    event = make_event(size, &tv);
	    sts = pmdaEventQueueAppend(queueid, event, size, &tv);
	    fprintf(stderr, "add event(%s,%d) -> %d ", name, (int)size, sts);
	    if (sts < 0) fprintf(stderr, "%s", pmErrStr(sts));
	    else __pmPrintStamp(stderr, &tv);
	    fputc('\n', stderr);
	    break;

	case 'E':	/* create an event on queue ID of given size */
	    s = optarg;
	    name = strsep(&s, ",");
	    if (!s) {
		fprintf(stderr, "%s: invalid event size specification (%s)\n",
			pmProgname, optarg);
		errflag++;
		break;
	    }
	    queueid = atoi(name);
	    size = atoi(s);
	    event = make_event(size, &tv);
	    sts = pmdaEventQueueAppend(queueid, event, size, &tv);
	    fprintf(stderr, "add queue#%d event(%s,%d) -> %d ",
		    queueid, name, (int)size, sts);
	    if (sts < 0) fprintf(stderr, "%s", pmErrStr(sts));
	    else __pmPrintStamp(stderr, &tv);
	    fputc('\n', stderr);
	    break;

	case 'q':	/* create queue with name and a max memory size */
	    s = optarg;
	    name = strsep(&s, ",");
	    if (!s) {
		fprintf(stderr, "%s: invalid queue memory specification (%s)\n",
			pmProgname, optarg);
		errflag++;
		break;
	    }
	    size = atoi(s);
	    sts = pmdaEventNewQueue(name, size);
	    fprintf(stderr, "new queue(%s,%d) -> %d", name, (int)size, sts);
	    if (sts < 0) fprintf(stderr, " %s", pmErrStr(sts));
	    fputc('\n', stderr);
	    break;

	case 'f':	/* create client filter, limits size */
	    s = optarg;
	    name = strsep(&s, ",");
	    if (!s) {
		fprintf(stderr, "%s: invalid client filter queue specification (%s)\n",
			pmProgname, optarg);
		errflag++;
		break;
	    }
	    context = atoi(name);
	    name = strsep(&s, ",");
	    if (!s) {
		fprintf(stderr, "%s: invalid client filter size specification (%s)\n",
			pmProgname, optarg);
		errflag++;
		break;
	    }
	    queueid = pmdaEventQueueHandle(name);
	    filter_size = atoi(s);
	    sts = pmdaEventSetFilter(context, queueid, (void *)&filter_size,
				     apply_filter, release_filter);
	    fprintf(stderr, "client#%d set filter(sz<%d) on queue#%d-> %d",
		    context, (int)filter_size, queueid, sts);
	    if (sts < 0) fprintf(stderr, " %s", pmErrStr(sts));
	    fputc('\n', stderr);
	    break;

	case 'F':	/* remove a clients filter */
	    s = optarg;
	    name = strsep(&s, ",");
	    if (!s) {
		fprintf(stderr, "%s: invalid client filter queue specification (%s)\n",
			pmProgname, optarg);
		errflag++;
		break;
	    }
	    context = atoi(name);
	    queueid = pmdaEventQueueHandle(s);

	    sts = pmdaEventSetFilter(context, queueid, NULL, NULL, NULL);
	    fprintf(stderr, "end queue#%d filter(%d) -> %d", queueid, context, sts);
	    if (sts < 0) fprintf(stderr, " %s", pmErrStr(sts));
	    fputc('\n', stderr);
	    break;

	case 's':	/* dump queue, events, clients counters */
	    name = optarg;
	    queueid = pmdaEventQueueHandle(name);
	    if (queueid < 0) {
		fprintf(stderr, "%s: invalid queue specification (%s)\n",
			pmProgname, name);
		errflag++;
		break;
	    }
	    queue_statistics(queueid);
	    break;

	case 'S':	/* dump queue contents, check events */
	    s = optarg;
	    name = strsep(&s, ",");
	    if (!s) {
		fprintf(stderr, "%s: invalid client filter queue specification (%s)\n",
			pmProgname, optarg);
		errflag++;
		break;
	    }
	    context = atoi(name);
	    queueid = pmdaEventQueueHandle(s);
	    queue_events(queueid, context);
	    break;

	case '?':
	default:
	    errflag++;
	    break;
	}
    }

    if (errflag) {
	fprintf(stderr, "Usage: %s ...\n", pmProgname);
	fprintf(stderr, "Options:\n");
	fprintf(stderr, "  -a id,name     disable a clients access\n");
	fprintf(stderr, "  -A id,name     enable a clients access\n");
	fprintf(stderr, "  -c id          create a new client\n");
	fprintf(stderr, "  -C id          remove a client by id\n");
	fprintf(stderr, "  -e name,size   append an event of size on queue\n");
	fprintf(stderr, "  -E id,size     append an event of size on queue\n");
	fprintf(stderr, "  -q name,size   create a new queue with max size\n");
	fprintf(stderr, "  -f id,name,sz  client queue filter, limit size\n");
	fprintf(stderr, "  -F id,name     remove a clients queue filter\n");
	fprintf(stderr, "  -D debug\n");
	fprintf(stderr, "  -s name        report statistics for a queue\n");
	fprintf(stderr, "  -S id,name     report clients events in a queue\n");
	exit(1);
    }

    return 0;
}