This file is indexed.

/var/lib/pcp/testsuite/src/defctx.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
/*
 * Copyright (c) 1997-2001 Silicon Graphics, Inc.  All Rights Reserved.
 */

/*
 * play with default contexts of various sorts
 */

#include <unistd.h>
#include <pcp/pmapi.h>
#include <pcp/impl.h>

int
main(int argc, char **argv)
{
    int		c;
    int		ctx0 = -1;
    int		ctx1 = -1;
    int		sts;
    int		inst;
    int		errflag = 0;
    int		type = 0;
    char	*host = NULL;	/* pander to gcc */
    char	*namespace = PM_NS_DEFAULT;
    pmDesc	desc;
    pmID	pmid;
    char	*name = "sample.colour";
    pmResult	*resp;

    __pmSetProgname(argv[0]);

    while ((c = getopt(argc, argv, "a:D:h:n:s:")) != EOF) {
	switch (c) {

	case 'a':	/* archive name */
	    if (type != 0) {
		fprintf(stderr, "%s: at most one of -a and/or -h allowed\n", pmProgname);
		errflag++;
	    }
	    type = PM_CONTEXT_ARCHIVE;
	    host = optarg;
	    break;

#ifdef PCP_DEBUG
	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;
#endif

	case 'h':	/* contact PMCD on this hostname */
	    if (type != 0) {
		fprintf(stderr, "%s: at most one of -a and/or -h allowed\n", pmProgname);
		errflag++;
	    }
	    host = optarg;
	    type = PM_CONTEXT_HOST;
	    break;

	case 'n':	/* alternative name space file */
	    namespace = optarg;
	    break;

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

    if (errflag) {
	fprintf(stderr,
"Usage: %s options ...\n\
\n\
Options:\n\
  -a archive	use archive log, not host source\n\
  -D N		set pmDebug debugging flag to N\n\
  -h hostname	connect to PMCD on this host\n\
  -n namespace	alternative PMNS specification file\n",
		pmProgname);
	exit(1);
    }

    if ((sts = pmLoadNameSpace(namespace)) < 0) {
	printf("%s: Cannot load namespace from \"%s\": %s\n", pmProgname, namespace, pmErrStr(sts));
	exit(1);
    }

    if (type != 0) {
	/* create an explicit context */
	if ((ctx0 = pmNewContext(type, host)) < 0) {
	    if (type == PM_CONTEXT_HOST)
		fprintf(stderr, "%s: Cannot connect to PMCD on host \"%s\": %s\n",
		    pmProgname, host, pmErrStr(sts));
	    else
		fprintf(stderr, "%s: Cannot open archive \"%s\": %s\n",
		    pmProgname, host, pmErrStr(sts));
	    exit(1);
	}
    }

    /*
     * Add to profile, fetch, ...
     */
    if ((sts = pmLookupName(1, &name, &pmid)) < 0) {
	printf("%s: pmLookupName(%s): %s\n", pmProgname, name, pmErrStr(sts));
	exit(1);
    }
    if ((sts = pmLookupDesc(pmid, &desc)) < 0) {
	printf("%s: pmLookupDesc(%s): %s\n", pmProgname, pmIDStr(pmid), pmErrStr(sts));
	exit(1);
    }

    if (type == PM_CONTEXT_ARCHIVE) {
	if ((inst = pmLookupInDomArchive(desc.indom, "green")) < 0) {
	    printf("%s: pmLookupInDomArchive(%s): %s\n", pmProgname, pmInDomStr(desc.indom), pmErrStr(inst));
	    exit(1);
	}
    }
    else {
	if ((inst = pmLookupInDom(desc.indom, "green")) < 0) {
	    printf("%s: pmLookupInDom(%s): %s\n", pmProgname, pmInDomStr(desc.indom), pmErrStr(inst));
	    exit(1);
	}
    }

    if ((sts = pmDelProfile(PM_INDOM_NULL, 1, (int *)0)) < 0) {
	printf("%s: pmDelProfile: %s\n", pmProgname, pmErrStr(sts));
	exit(1);
    }
    if ((sts = pmAddProfile(desc.indom, 1, &inst)) < 0) {
	printf("%s: pmAddProfile: %s\n", pmProgname, pmErrStr(sts));
	exit(1);
    }
    if ((sts = pmFetch(1, &pmid, &resp)) < 0) {
	printf("%s: pmFetch: %s\n", pmProgname, pmErrStr(sts));
    }
    else {
	printf("first pmFetch is OK\n");
	__pmDumpResult(stdout, resp);
	pmFreeResult(resp);
    }
    
    /*
     * Now destroy context and try again, ... should see an invalid context
     */
    if ((sts = pmDestroyContext(ctx0)) < 0)
	printf("%s: pmDestroyContext: %s\n", pmProgname, pmErrStr(sts));

    if ((sts = pmDelProfile(PM_INDOM_NULL, 1, (int *)0)) < 0) {
	printf("%s: pmDelProfile: %s\n", pmProgname, pmErrStr(sts));
    }
    if ((sts = pmAddProfile(desc.indom, 1, &inst)) < 0) {
	printf("%s: pmAddProfile: %s\n", pmProgname, pmErrStr(sts));
    }
    if ((sts = pmFetch(1, &pmid, &resp)) < 0) {
	printf("%s: pmFetch: %s\n", pmProgname, pmErrStr(sts));
    }
    else {
	printf("second pmFetch is OK\n");
	__pmDumpResult(stdout, resp);
	pmFreeResult(resp);
    }

    /*
     * destroy that one
     */
    if ((ctx0 = pmWhichContext()) < 0)
	printf("%s: pmWhichContext: %s\n", pmProgname, pmErrStr(ctx0));
    else
	if ((sts = pmDestroyContext(ctx0)) < 0)
	    printf("%s: pmDestroyContext: %s\n", pmProgname, pmErrStr(sts));

    if (type != 0) {
	/* play some more games */
	if ((ctx0 = pmNewContext(type, host)) < 0) {
	    if (type == PM_CONTEXT_HOST)
		fprintf(stderr, "%s: Cannot connect to PMCD on host \"%s\": %s\n",
		    pmProgname, host, pmErrStr(sts));
	    else
		fprintf(stderr, "%s: Cannot open archive \"%s\": %s\n",
		    pmProgname, host, pmErrStr(sts));
	    exit(1);
	}
	printf("NewContext: %d\n", ctx0);
	if ((ctx1 = pmNewContext(type, host)) < 0) {
	    if (type == PM_CONTEXT_HOST)
		fprintf(stderr, "%s: Cannot connect to PMCD on host \"%s\": %s\n",
		    pmProgname, host, pmErrStr(sts));
	    else
		fprintf(stderr, "%s: Cannot open archive \"%s\": %s\n",
		    pmProgname, host, pmErrStr(sts));
	    exit(1);
	}
	printf("NewContext: %d\n", ctx1);
	if ((sts = pmDestroyContext(ctx0)) < 0)
	    printf("%s: pmDestroyContext: %s\n", pmProgname, pmErrStr(sts));
	else
	    printf("Destroy(%d)\n", ctx0);
	if ((sts = pmWhichContext()) < 0)
	    printf("%s: pmWhichContext: %s\n", pmProgname, pmErrStr(sts));
	else
	    printf("WhichContext: %d\n", sts);

	if ((ctx0 = pmNewContext(type, host)) < 0) {
	    if (type == PM_CONTEXT_HOST)
		fprintf(stderr, "%s: Cannot connect to PMCD on host \"%s\": %s\n",
		    pmProgname, host, pmErrStr(sts));
	    else
		fprintf(stderr, "%s: Cannot open archive \"%s\": %s\n",
		    pmProgname, host, pmErrStr(sts));
	    exit(1);
	}
	printf("NewContext: %d\n", ctx0);
	if ((sts = pmDestroyContext(ctx0)) < 0)
	    printf("%s: pmDestroyContext: %s\n", pmProgname, pmErrStr(sts));
	else
	    printf("Destroy(%d)\n", ctx0);
	if ((sts = pmDestroyContext(ctx1)) < 0)
	    printf("%s: pmDestroyContext: %s\n", pmProgname, pmErrStr(sts));
	else
	    printf("Destroy(%d)\n", ctx1);
    }

    exit(0);
}