/var/lib/pcp/testsuite/src/archfetch.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 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 | /*
* Copyright (c) 1995-2001 Silicon Graphics, Inc. All Rights Reserved.
* Copyright (c) 2015 Ken McDonell. All Rights Reserved.
*/
#include <pcp/pmapi.h>
int
main(int argc, char **argv)
{
int c;
int sts;
int errflag = 0;
int type = 0;
char *archive = NULL; /* pander to gcc */
int mode = PM_MODE_FORW; /* mode for archives */
pmLogLabel label; /* get hostname for archives */
int zflag = 0; /* for -z */
char *tz = NULL; /* for -Z timezone */
int tzh; /* initial timezone handle */
int samples = -1;
int save_samples;
char *endnum;
int numpmid = 0;
pmID *pmidlist = NULL;
pmResult *rp;
char timebuf[26];
/* trim cmd name of leading directory components */
pmSetProgname(argv[0]);
while ((c = getopt(argc, argv, "a:D:O:s:zZ:?")) != EOF) {
switch (c) {
case 'a': /* archive name */
if (type != 0) {
#ifdef BUILD_STANDALONE
fprintf(stderr, "%s: at most one of -a, -h and -L allowed\n", pmGetProgname());
#else
fprintf(stderr, "%s: at most one of -a and -h allowed\n", pmGetProgname());
#endif
errflag++;
}
type = PM_CONTEXT_ARCHIVE;
archive = optarg;
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 's': /* sample count */
samples = (int)strtol(optarg, &endnum, 10);
if (*endnum != '\0' || samples < 0) {
fprintf(stderr, "%s: -s requires numeric argument\n", pmGetProgname());
errflag++;
}
break;
case 'z': /* timezone from archive */
if (tz != NULL) {
fprintf(stderr, "%s: at most one of -Z and/or -z allowed\n", pmGetProgname());
errflag++;
}
zflag++;
break;
case 'Z': /* $TZ timezone */
if (zflag) {
fprintf(stderr, "%s: at most one of -Z and/or -z allowed\n", pmGetProgname());
errflag++;
}
tz = optarg;
break;
case '?':
default:
errflag++;
break;
}
}
if (errflag) {
fprintf(stderr,
"Usage: %s [options] metric ...\n\
\n\
Options:\n\
-a archive metrics source is a PCP log archive\n\
-s samples terminate after this many samples\n\
-z set reporting timezone to local time of metrics source\n\
-Z timezone set reporting timezone\n",
pmGetProgname());
exit(1);
}
if (type == 0) {
fprintf(stderr, "%s: -a is not optional\n", pmGetProgname());
exit(1);
}
if ((sts = pmNewContext(type, archive)) < 0) {
fprintf(stderr, "%s: Cannot open archive \"%s\": %s\n",
pmGetProgname(), archive, pmErrStr(sts));
exit(1);
}
if ((sts = pmGetArchiveLabel(&label)) < 0) {
fprintf(stderr, "%s: Cannot get archive label record: %s\n",
pmGetProgname(), pmErrStr(sts));
exit(1);
}
if ((sts = pmSetMode(mode, &label.ll_start, 0)) < 0) {
fprintf(stderr, "%s: pmSetMode: %s\n", pmGetProgname(), pmErrStr(sts));
exit(1);
}
if (zflag) {
if ((tzh = pmNewContextZone()) < 0) {
fprintf(stderr, "%s: Cannot set context timezone: %s\n",
pmGetProgname(), pmErrStr(tzh));
exit(1);
}
printf("Note: timezone set to local timezone of host \"%s\" from archive\n\n",
label.ll_hostname);
}
else if (tz != NULL) {
if ((tzh = pmNewZone(tz)) < 0) {
fprintf(stderr, "%s: Cannot set timezone to \"%s\": %s\n",
pmGetProgname(), tz, pmErrStr(tzh));
exit(1);
}
printf("Note: timezone set to \"TZ=%s\"\n\n", tz);
}
while (optind < argc) {
pmidlist = (pmID *)realloc(pmidlist, (numpmid+1)*sizeof(pmidlist[0]));
if (pmidlist == NULL) {
pmNoMem("pmidlist[]", (numpmid+1)*sizeof(pmidlist[0]), PM_FATAL_ERR);
/* NOTREACHED */
}
sts = pmLookupName(1, &argv[optind], &pmidlist[numpmid]);
if (sts < 0) {
fprintf(stderr, "%s: pmLookupName(..., %s, ...): %s\n", pmGetProgname(), argv[optind], pmErrStr(sts));
exit(1);
}
numpmid++;
optind++;
}
printf("pmFetch ...\n");
save_samples = samples;
while (samples == -1 || samples-- > 0) {
sts = pmFetch(numpmid, pmidlist, &rp);
if (sts >= 0) {
pmCtime(&rp->timestamp.tv_sec, timebuf);
printf("numpmid=%2d %.19s.%08d\n", rp->numpmid, timebuf, (int)rp->timestamp.tv_usec);
pmFreeResult(rp);
}
else {
printf("-> %s\n", pmErrStr(sts));
break;
}
}
if ((sts = pmSetMode(mode, &label.ll_start, 0)) < 0) {
fprintf(stderr, "%s: pmSetMode: %s\n", pmGetProgname(), pmErrStr(sts));
exit(1);
}
printf("\npmFetchArchive ...\n");
samples = save_samples;
while (samples == -1 || samples-- > 0) {
sts = pmFetchArchive(&rp);
if (sts >= 0) {
pmCtime(&rp->timestamp.tv_sec, timebuf);
printf("numpmid=%2d %.19s.%08d", rp->numpmid, timebuf, (int)rp->timestamp.tv_usec);
if (rp->numpmid == 0)
printf(" <mark>");
putchar('\n');
pmFreeResult(rp);
}
else {
printf("-> %s\n", pmErrStr(sts));
break;
}
}
return 0;
}
|