This file is indexed.

/var/lib/pcp/testsuite/src/mergelabelsets.c is in pcp-testsuite 4.0.1-1.

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
/*
 * Copyright (c) 2017 Red Hat.
 *
 * Test program for exercising pmMergeLabelSets(3).
 */

#include <ctype.h>
#include <assert.h>
#include <pcp/pmapi.h>

#define LOCATION \
    "{\"datacenter\":\"torquay\",\"environment\":\"production\"}"

static pmLabel location_labels[] = {
    { .name = 2,   .namelen = 10,
      .value = 14, .valuelen = 9,
      .flags = PM_LABEL_CONTEXT|PM_LABEL_OPTIONAL },
    { .name = 25,  .namelen = 11,
      .value = 38, .valuelen = 12,
      .flags = PM_LABEL_CONTEXT },
};
static pmLabelSet location = {
    .nlabels = 2,
    .json = LOCATION,
    .jsonlen = sizeof(LOCATION),
    .labels = location_labels,
};

#define SERVICES \
    "{\"services\":[\"indexer\",\"database\"]}"

static pmLabel services_labels[] = {
    { .name = 2,   .namelen = 8,
      .value = 12, .valuelen = 22,
      .flags = PM_LABEL_DOMAIN },
};
static pmLabelSet services = {
    .nlabels = 1,
    .json = SERVICES,
    .jsonlen = sizeof(SERVICES),
    .labels = services_labels,
};

#define TESTING \
    "{\"more\":{\"all\":false,\"none\":true},\"none\":none,\"some\":[1,2,3]}"

static pmLabel testing_labels[] = {
    { .name = 2,   .namelen = 4,
      .value = 8, .valuelen = 25,
      .flags = PM_LABEL_ITEM|PM_LABEL_OPTIONAL },
    { .name = 35,  .namelen = 4,
      .value = 41, .valuelen = 4,
      .flags = PM_LABEL_ITEM|PM_LABEL_OPTIONAL },
    { .name = 47,  .namelen = 4,
      .value = 53, .valuelen = 7,
      .flags = PM_LABEL_ITEM|PM_LABEL_OPTIONAL },
};

static pmLabelSet testing = {
    .nlabels = 3,
    .json = TESTING,
    .jsonlen = sizeof(TESTING),
    .labels = testing_labels,
};

#define EMPTY "{}"
static pmLabel empty_labels[1];
static pmLabelSet empty = {
    .nlabels = 0,
    .json = EMPTY,
    .jsonlen = sizeof(EMPTY),
    .labels = empty_labels,
};

static int
cull_optional(const pmLabel *lp, const char *json, void *arg)
{
    char	*testcase = (char *)arg;
    int		filter = !(lp->flags & PM_LABEL_OPTIONAL);

    if (pmDebugOptions.labels)
	fprintf(stderr, "%s cull_optional label %.*s(%.*s): %s\n",
		testcase,
		lp->namelen, &json[lp->name],
		lp->valuelen, &json[lp->value],
		filter ? "yes" : "no");

    return filter;
}

static int
cull_none(const pmLabel *lp, const char *json, void *arg)
{
    char	*testcase = (char *)arg;
    int		filter = 0;

    if (lp->valuelen == 4)
	filter = (strncmp(&json[lp->value], "none", 4) != 0);

    if (pmDebugOptions.labels)
	fprintf(stderr, "%s cull_none label %.*s(%.*s): %s\n",
		testcase,
		lp->namelen, &json[lp->name],
		lp->valuelen, &json[lp->value],
		filter ? "yes" : "no");

    return filter;
}


int
main(int argc, char **argv)
{
    int		c;
    int		sts;
    int		errflag = 0;
    char	json[PM_MAXLABELJSONLEN];
    void	*test;
    pmLabelSet	*sets[5];

    pmSetProgname(argv[0]);

    while ((c = getopt(argc, argv, "D:?")) != EOF) {
	switch (c) {
	case 'D':	/* debug flag */
	    if ((sts = pmSetDebug(optarg)) < 0) {
		fprintf(stderr, "%s: unrecognized debug flag specification (%s)\n",
		    pmGetProgname(), optarg);
		errflag++;
	    }
	    break;

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

    if (errflag)
	exit(1);

    sets[0] = &testing;
    sets[1] = &services;
    sets[2] = &location;
    test = (void *)"test-1";
    sts = pmMergeLabelSets(sets, 3, json, sizeof(json), NULL, test);
    if (sts < 0)
	fprintf(stderr, "pmMergeLabelSets: %s\n", pmErrStr(sts));
    else
	printf("Merged testing/services/location (no filter)\n%s\n\n", json);

    sets[0] = &services;
    sets[1] = &location;
    test = (void *)"test-2";
    sts = pmMergeLabelSets(sets, 2, json, sizeof(json), cull_optional, test);
    if (sts < 0)
	fprintf(stderr, "pmMergeLabelSets: %s\n", pmErrStr(sts));
    else
	printf("Merged services/location (cull optional)\n%s\n\n", json);

    sets[0] = &services;
    sets[1] = NULL;
    sets[2] = &location;
    sets[3] = &empty;
    test = (void *)"test-3";
    sts = pmMergeLabelSets(sets, 4, json, sizeof(json), cull_none, test);
    if (sts < 0)
	fprintf(stderr, "pmMergeLabelSets: %s\n", pmErrStr(sts));
    else
	printf("Merged services/NULL/location/empty (cull none)\n%s\n\n", json);

    exit(0);
}