/var/lib/pcp/testsuite/src/nameall.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 | /*
* Copyright (c) 1997-2001 Silicon Graphics, Inc. All Rights Reserved.
*/
/*
* nameall - exercise pmNameAll
*/
#include <ctype.h>
#include <pcp/pmapi.h>
#include "libpcp.h"
static int pmns_style = 1;
static int vflag;
static char *host = "localhost";
static char *namespace = PM_NS_DEFAULT;
static int dupok = 1;
static void
dometric(const char *name)
{
pmID pmid;
int i;
int n;
char **nameset;
/* cast const away as pmLookUpName will not modify this string */
n = pmLookupName(1, (char **)&name, &pmid);
if (n < 0) {
printf("pmLookupName(%s): %s\n", name, pmErrStr(n));
return;
}
n = pmNameAll(pmid, &nameset);
if (n < 0) {
printf("pmNameAll(%s): %s\n", name, pmErrStr(n));
return;
}
for (i = 0; i < n; i++) {
if (strcmp(name, nameset[i]) != 0)
printf("%s alias %s and %s\n", pmIDStr(pmid), name, nameset[i]);
}
free(nameset);
}
void
parse_args(int argc, char **argv)
{
int errflag = 0;
int c;
int sts;
static char *usage = "[-D debugspec] [-h hostname] [-[N|n] namespace] [-v]";
static char *style_str = "[-s 1|2]";
char *endnum;
pmSetProgname(argv[0]);
while ((c = getopt(argc, argv, "D:h:N:n:s:v")) != EOF) {
switch (c) {
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': /* hostname for PMCD to contact */
host = optarg;
break;
case 'N':
dupok=0;
/*FALLTHROUGH*/
case 'n': /* alternative name space file */
namespace = optarg;
break;
case 'v': /* verbose */
vflag++;
break;
case 's': /* pmns style */
pmns_style = (int)strtol(optarg, &endnum, 10);
if (*endnum != '\0') {
printf("%s: -s requires numeric argument\n", pmGetProgname());
errflag++;
}
break;
case '?':
default:
errflag++;
break;
}
}
if (errflag) {
printf("Usage: %s %s%s\n", pmGetProgname(), style_str, usage);
exit(1);
}
}
void
load_namespace(char *namespace)
{
struct timeval now, then;
int sts;
gettimeofday(&then, (struct timezone *)0);
sts = pmLoadASCIINameSpace(namespace, dupok);
if (sts < 0) {
printf("%s: Cannot load namespace from \"%s\" (dupok=%d): %s\n", pmGetProgname(), namespace, dupok, pmErrStr(sts));
exit(1);
}
gettimeofday(&now, (struct timezone *)0);
printf("Name space load: %.2f msec\n", pmtimevalSub(&now, &then)*1000);
}
void
test_nameall(int argc, char *argv[])
{
int sts;
if ((sts = pmNewContext(PM_CONTEXT_HOST, host)) < 0) {
printf("%s: Cannot connect to PMCD on host \"%s\": %s\n", pmGetProgname(), host, pmErrStr(sts));
exit(1);
}
if (vflag > 1)
__pmDumpNameSpace(stdout, 1);
for ( ; optind < argc; optind++)
pmTraversePMNS(argv[optind], dometric);
}
int
main(int argc, char **argv)
{
parse_args(argc, argv);
if (pmns_style == 2) {
/* test it the new way with distributed namespace */
/* i.e. no client loaded namespace */
test_nameall(argc, argv);
}
else {
/* test it the old way with namespace file */
load_namespace(namespace);
test_nameall(argc, argv);
}
exit(0);
}
|