/var/lib/pcp/testsuite/src/chktrim.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 | /*
* Copyright (c) 1997-2001 Silicon Graphics, Inc. All Rights Reserved.
*/
/*
* Check new functionality of pmTrimNameSpace
*/
#include <ctype.h>
#include <string.h>
#include <pcp/pmapi.h>
extern int errno;
static char tag;
static void
dometric(const char *name)
{
printf("%c %s\n", tag, name);
}
int
main(argc, argv)
int argc;
char *argv[];
{
int c;
int sts;
int errflag = 0;
char *namespace = PM_NS_DEFAULT;
int ctx = -1; /* context for host */
static char *usage = "[-D debugspec] [-n namespace] [-a archive] [-h host] [-L]";
pmSetProgname(argv[0]);
while ((c = getopt(argc, argv, "a:D:h:Ln:")) != EOF) {
switch (c) {
case 'a':
if ((sts = pmNewContext(PM_CONTEXT_ARCHIVE, optarg)) < 0) {
printf("%s: pmNewContext(archive %s): %s\n", pmGetProgname(), optarg, pmErrStr(sts));
exit(1);
}
break;
case 'D': /* debug options */
sts = pmSetDebug(optarg);
if (sts < 0) {
fprintf(stderr, "%s: unrecognized debug options specification (%s)\n",
pmGetProgname(), optarg);
errflag++;
}
break;
case 'h':
if ((ctx = pmNewContext(PM_CONTEXT_HOST, optarg)) < 0) {
printf("%s: pmNewContext(host %s): %s\n", pmGetProgname(), optarg, pmErrStr(ctx));
exit(1);
}
break;
case 'L':
putenv("PMDA_LOCAL_SAMPLE="); /* sampledso needed */
if ((sts = pmNewContext(PM_CONTEXT_LOCAL, NULL)) < 0) {
printf("%s: pmNewContext(host %s): %s\n", pmGetProgname(), optarg, pmErrStr(sts));
exit(1);
}
break;
case 'n': /* alternative name space file */
namespace = optarg;
break;
case '?':
default:
errflag++;
break;
}
}
if (errflag || optind != argc) {
fprintf(stderr, "Usage: %s %s\n", pmGetProgname(), usage);
exit(1);
}
if (namespace != PM_NS_DEFAULT && (sts = pmLoadASCIINameSpace(namespace, 1)) < 0) {
printf("%s: Cannot load namespace from \"%s\": %s\n", pmGetProgname(), namespace, pmErrStr(sts));
exit(1);
}
printf("0 Initial NameSpace below sampledso ...\n");
tag = '0';
sts = pmTraversePMNS("sampledso", dometric);
if (sts < 0) {
printf("Error: pmTraversePMNS: %s\n", pmErrStr(sts));
}
printf("1\n1 Trimmed NameSpace below sampledso for current context ...\n");
sts = pmTrimNameSpace();
if (sts == 0) {
tag = '1';
sts = pmTraversePMNS("sampledso", dometric);
if (sts < 0) {
printf("Error: pmTraversePMNS: %s\n", pmErrStr(sts));
}
}
else {
printf("Error: pmTrimeNameSpace: %s\n", pmErrStr(sts));
}
if (ctx == -1) {
if ((ctx = pmNewContext(PM_CONTEXT_HOST, "local:")) < 0) {
printf("%s: pmNewContext(local:): %s\n", pmGetProgname(), pmErrStr(ctx));
exit(1);
}
}
printf("2\n2 Trimmed NameSpace below sampledso for host context ...\n");
pmUseContext(ctx);
sts = pmTrimNameSpace();
if (sts == 0) {
tag = '2';
sts = pmTraversePMNS("sampledso", dometric);
if (sts < 0) {
printf("Error: pmTraversePMNS: %s\n", pmErrStr(sts));
}
}
else {
printf("Error: pmTrimeNameSpace: %s\n", pmErrStr(sts));
}
exit(0);
}
|