/var/lib/pcp/testsuite/src/indom.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 310 | /*
* indom - exercise pmGetInDom, pmNameInDom and pmLookupInDom
*/
#include <pcp/pmapi.h>
#include <pcp/impl.h>
static int type;
static int inst;
int
dometric(char *name)
{
pmID pmid;
pmDesc desc;
int sts;
char *iname;
int *ilist;
char **nlist;
if ((sts = pmLookupName(1, &name, &pmid)) < 0)
return sts;
if ((sts = pmLookupDesc(pmid, &desc)) < 0)
return sts;
iname = "no match";
printf("pm*InDom: inst=[%d]", inst);
if ((sts = pmNameInDom(desc.indom, inst, &iname)) < 0)
printf(" {%s}\n", pmErrStr(sts));
else {
printf(" iname=<%s> reverse lookup:", iname);
if ((sts = pmLookupInDom(desc.indom, iname)) < 0)
printf(" {%s}\n", pmErrStr(sts));
else
printf(" inst=[%d]\n", sts);
}
if (type == PM_CONTEXT_ARCHIVE) {
iname = "no match";
printf("pm*InDomArchive: inst=[%d]", inst);
if ((sts = pmNameInDomArchive(desc.indom, inst, &iname)) < 0)
printf(" {%s}\n", pmErrStr(sts));
else {
printf(" iname=<%s> reverse lookup:", iname);
if ((sts = pmLookupInDomArchive(desc.indom, iname)) < 0)
printf(" {%s}\n", pmErrStr(sts));
else
printf(" inst=[%d]\n", sts);
}
}
if ((sts = pmGetInDom(desc.indom, &ilist, &nlist)) < 0)
printf("pmGetInDom: {%s}\n", pmErrStr(sts));
else {
int i;
printf("pmGetInDom:\n");
for (i = 0; i < sts; i++) {
if (ilist[i] == inst) {
printf(" [%d] <%s>\n", ilist[i], nlist[i]);
break;
}
}
free(ilist);
free(nlist);
}
if (type == PM_CONTEXT_ARCHIVE) {
if ((sts = pmGetInDomArchive(desc.indom, &ilist, &nlist)) < 0)
printf("pmGetInDomArchive: {%s}\n", pmErrStr(sts));
else {
int i;
printf("pmGetInDomArchive:\n");
for (i = 0; i < sts; i++) {
if (i == inst) {
printf(" [%d] <%s>\n", ilist[i], nlist[i]);
break;
}
}
free(ilist);
free(nlist);
}
}
return sts;
}
int
main(int argc, char **argv)
{
int c;
int sts;
int errflag = 0;
int force = 0;
int verbose = 0;
char *host = NULL; /* pander to gcc */
char *configfile = (char *)0;
char *logfile = (char *)0;
pmLogLabel label; /* get hostname for archives */
int zflag = 0; /* for -z */
char *tz = (char *)0; /* for -Z timezone */
int tzh; /* initial timezone handle */
char local[MAXHOSTNAMELEN];
char *namespace = PM_NS_DEFAULT;
int samples = -1;
double delta = 1.0;
char *endnum;
__pmSetProgname(argv[0]);
while ((c = getopt(argc, argv, "a:c:D:fh:i:l:n:s:t:VzZ:?")) != 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;
case 'c': /* configfile */
if (configfile != (char *)0) {
fprintf(stderr, "%s: at most one -c option allowed\n", pmProgname);
errflag++;
}
configfile = 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 'f': /* force */
force++;
break;
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 'i': /* instance */
inst = (int)strtol(optarg, &endnum, 10);
if (*endnum != '\0' || inst < 0) {
fprintf(stderr, "%s: -i requires numeric argument\n", pmProgname);
errflag++;
}
break;
case 'l': /* logfile */
logfile = optarg;
break;
case 'n': /* alternative name space file */
namespace = optarg;
break;
case 's': /* sample count */
samples = (int)strtol(optarg, &endnum, 10);
if (*endnum != '\0' || samples < 0) {
fprintf(stderr, "%s: -s requires numeric argument\n", pmProgname);
errflag++;
}
break;
case 't': /* delta seconds (double) */
delta = strtod(optarg, &endnum);
if (*endnum != '\0' || delta <= 0.0) {
fprintf(stderr, "%s: -t requires floating point argument\n", pmProgname);
errflag++;
}
break;
case 'V': /* verbose */
verbose++;
break;
case 'z': /* timezone from host */
if (tz != (char *)0) {
fprintf(stderr, "%s: at most one of -Z and/or -z allowed\n", pmProgname);
errflag++;
}
zflag++;
break;
case 'Z': /* $TZ timezone */
if (zflag) {
fprintf(stderr, "%s: at most one of -Z and/or -z allowed\n", pmProgname);
errflag++;
}
tz = optarg;
break;
case '?':
default:
errflag++;
break;
}
}
if (zflag && type == 0) {
fprintf(stderr, "%s: -z requires an explicit -a or -h option\n", pmProgname);
errflag++;
}
if (errflag) {
fprintf(stderr,
"Usage: %s options ...\n\
\n\
Options\n\
-a archive metrics source is an archive log\n\
-c configfile file to load configuration from\n\
-D debug standard PCP debug flag\n\
-f force .. \n\
-h host metrics source is PMCD on host\n\
-l logfile redirect diagnostics and trace output\n\
-n namespace use an alternative PMNS\n\
-s samples terminate after this many iterations\n\
-t delta sample interval in seconds(float) [default 1.0]\n\
-V verbose/diagnostic output\n\
-z set reporting timezone to local time for host from -a or -h\n\
-Z timezone set reporting timezone\n",
pmProgname);
exit(1);
}
if (logfile != (char *)0) {
__pmOpenLog(pmProgname, logfile, stderr, &sts);
if (sts < 0) {
fprintf(stderr, "%s: Could not open logfile \"%s\"\n", pmProgname, logfile);
}
}
if ((sts = pmLoadNameSpace(namespace)) < 0) {
printf("%s: Cannot load namespace from \"%s\": %s\n", pmProgname, namespace, pmErrStr(sts));
exit(1);
}
if (type == 0) {
type = PM_CONTEXT_HOST;
gethostname(local, sizeof(local));
host = local;
}
if ((sts = 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);
}
if (type == PM_CONTEXT_ARCHIVE) {
if ((sts = pmGetArchiveLabel(&label)) < 0) {
fprintf(stderr, "%s: Cannot get archive label record: %s\n",
pmProgname, pmErrStr(sts));
exit(1);
}
}
if (zflag) {
if ((tzh = pmNewContextZone()) < 0) {
fprintf(stderr, "%s: Cannot set context timezone: %s\n",
pmProgname, pmErrStr(tzh));
exit(1);
}
if (type == PM_CONTEXT_ARCHIVE)
printf("Note: timezone set to local timezone of host \"%s\" from archive\n\n",
label.ll_hostname);
else
printf("Note: timezone set to local timezone of host \"%s\"\n\n", host);
}
else if (tz != (char *)0) {
if ((tzh = pmNewZone(tz)) < 0) {
fprintf(stderr, "%s: Cannot set timezone to \"%s\": %s\n",
pmProgname, tz, pmErrStr(tzh));
exit(1);
}
printf("Note: timezone set to \"TZ=%s\"\n\n", tz);
}
else
tzh = pmNewContextZone();
/* non-flag args are argv[optind] ... argv[argc-1] */
while (optind < argc) {
printf("%s:\n", argv[optind]);
sts = dometric(argv[optind]);
if (sts < 0)
printf("Error: %s\n", pmErrStr(sts));
optind++;
}
exit(0);
}
|