This file is indexed.

/var/lib/pcp/testsuite/src/pmnsinarchives.c is in pcp-testsuite 3.9.10.

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

/*
 * main - test the code which adds PMNS to archives
 */

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

void
parse_args(int argc, char **argv)
{
    extern char	*optarg;
    extern int	optind;
    int		errflag = 0;
    int		c;
    int		sts;
    static char	*usage = "[-v]";

#ifdef PCP_DEBUG
    static char	*debug = "[-D N]";
#else
    static char	*debug = "";
#endif

    __pmSetProgname(argv[0]);

    while ((c = getopt(argc, argv, "D:?")) != EOF) {
	switch (c) {
#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 '?':
	default:
	    errflag++;
	    break;
	}
    }

    if (errflag) {
	printf("Usage: %s %s%s\n", pmProgname, debug, usage);
	exit(1);
    }


}

typedef struct {
  char *name;
  pmID pmid;
}Metric;

static Metric metric_list[] = {
  {"abc.def.ghi", 100},
  {"abc.def.jkl", 200},
  {"abc.mno", 300},
  {"pqr.rst.uvw", 400},
  {"pqr.xyz", 500}
};
static char *parents[] = {
  "abc", "pqr", "abc.def", "def", "abc.def.ghi"
};

const int num_metrics = sizeof(metric_list) / sizeof(Metric);
const int num_parents = sizeof(parents) / sizeof(char*);

int
main(int argc, char **argv)
{
  int sts = 0;
  int i = 0;
  __pmnsTree *pmns = NULL;

  parse_args(argc, argv);


  printf("\n*** Build up the PMNS from metrics... ***\n");
  printf("Number of metrics = %d\n", num_metrics);

  if ((sts = __pmNewPMNS(&pmns)) < 0) {
      fprintf(stderr, "%s: __pmNewPMNS: %s\n", pmProgname, pmErrStr(sts));
      exit(1);
  }

  for(i = 0; i < num_metrics; i++) {
      pmID pmid = metric_list[i].pmid;
      char *name = metric_list[i].name;
      sts = __pmAddPMNSNode(pmns, pmid, name);
      printf("Adding node: \"%s\"[%d]\n", name, pmid);
      if (sts < 0) {
	  fprintf(stderr, "%s: __pmAddPMNSNode: %s\n", 
		  pmProgname, pmErrStr(sts));
	  exit(1);
      }
  } 

  if ((sts = __pmFixPMNSHashTab(pmns, num_metrics, 1)) < 0) {
      fprintf(stderr, "%s: __pmFixPMNSHashTab: %s\n", 
	      pmProgname, pmErrStr(sts));
      exit(1);
  }
  __pmUsePMNS(pmns);


  printf("\n*** Check PMNS is ok ***\n");

  printf("\n--- Dump out PMNS ---\n");
  __pmDumpNameSpace(stdout, 1);

  printf("\n--- Test out pmLookupName ---\n");
  for(i = 0; i < num_metrics; i++) {
      pmID pmid = metric_list[i].pmid;
      char *name = metric_list[i].name;
      pmID thepmid = 0;

      if ((sts = pmLookupName(1, &name, &thepmid)) < 0) {
	  fprintf(stderr, "%s: _pmLookupName: %s\n", 
		  pmProgname, pmErrStr(sts));
      }
      if (thepmid == pmid) {
	  printf("%d matches for name lookup\n", pmid);
      }
      else {
	  printf("%d does not match with %d\n", pmid, thepmid);
      }
  }

  printf("\n--- Test out pmNameID for matches ---\n");
  for(i = 0; i < num_metrics; i++) {
      pmID pmid = metric_list[i].pmid;
      char *name = metric_list[i].name;
      char *thename = NULL;

      if ((sts = pmNameID(pmid, &thename)) < 0) {
	  fprintf(stderr, "%s: _pmNameID: %s\n", 
		  pmProgname, pmErrStr(sts));
      }
      if (strcmp(name, thename) == 0) {
	  printf("%s matches for id lookup\n", name);
      }
      else {
	  printf("%s does not match with %s\n", name, thename);
      }
  }

  printf("\n--- Test out pmGetChildren ---\n");
  for (i = 0; i < num_parents; i++) {
      char *parent = parents[i]; 
      int num_childs = 0;
      int j;
      char **offspring = NULL;

      printf("Children of %s:\n", parent);
      if ((sts = pmGetChildren(parent, &offspring)) < 0) {
	  fprintf(stderr, "%s: _pmGetChildren: %s\n", 
		  pmProgname, pmErrStr(sts));
      }
      num_childs = sts;
      for (j = 0; j < num_childs; j++) {
	printf("  %s\n", offspring[j]);
      }
  }/*for*/

  exit(0);
}