/var/lib/pcp/testsuite/src/chkputlogresult.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 | /*
* Copyright (c) 1995-2001 Silicon Graphics, Inc. All Rights Reserved.
* Copyright (c) 2014 Ken McDonell. All Rights Reserved.
* Copyright (c) 2017 Red Hat.
*
* Excercise __pmLogPutResult() and __pmLogPutResult2().
*/
#include <pcp/pmapi.h>
#include "libpcp.h"
#include <assert.h>
int
main(int argc, char **argv)
{
int c;
int i;
int sts;
int bflag = 0;
int errflag = 0;
char *metrics[] = {
"sampledso.long.one",
"sampledso.ulonglong.one",
"sampledso.float.one",
"sampledso.double.one",
"sampledso.string.hullo",
"sampledso.bin",
};
int nmetric = sizeof(metrics)/sizeof(metrics[0]);
pmID *pmids;
pmDesc desc;
pmResult *rp;
__pmLogCtl logctl;
__pmArchCtl archctl;
__pmPDU *pdp;
pmTimeval epoch = { 0, 0 };
int numinst;
int *ilist;
char **nlist;
/* trim cmd name of leading directory components */
pmSetProgname(argv[0]);
while ((c = getopt(argc, argv, "bD::?")) != EOF) {
switch (c) {
case 'b': /* backwards compatibility */
bflag++;
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 '?':
default:
errflag++;
break;
}
}
if (errflag || optind != argc-1) {
fprintf(stderr,
"Usage: %s [options] archive\n\
\n\
Options:\n\
-b backwards compatibility (use __pmLogPutResult() instead\n\
__pmLogPutResult2(), the default\n\
-D debugflag[,...]\n\
",
pmGetProgname());
exit(1);
}
if ((sts = pmNewContext(PM_CONTEXT_HOST, "local:")) < 0) {
fprintf(stderr, "%s: Cannot connect to PMCD on \"local:\": %s\n",
pmGetProgname(), pmErrStr(sts));
exit(1);
}
memset(&logctl, 0, sizeof(logctl));
memset(&archctl, 0, sizeof(archctl));
archctl.ac_log = &logctl;
if ((sts = __pmLogCreate("qatest", argv[optind], LOG_PDU_VERSION, &archctl)) != 0) {
fprintf(stderr, "%s: __pmLogCreate failed: %s\n", pmGetProgname(), pmErrStr(sts));
exit(1);
}
logctl.l_state = PM_LOG_STATE_INIT;
/*
* make the archive label deterministic
*/
logctl.l_label.ill_pid = 1234;
logctl.l_label.ill_start.tv_sec = epoch.tv_sec;
logctl.l_label.ill_start.tv_usec = epoch.tv_usec;
strcpy(logctl.l_label.ill_hostname, "happycamper");
strcpy(logctl.l_label.ill_tz, "UTC");
logctl.l_label.ill_vol = PM_LOG_VOL_TI;
if ((sts = __pmLogWriteLabel(logctl.l_tifp, &logctl.l_label)) != 0) {
fprintf(stderr, "%s: __pmLogWriteLabel TI failed: %s\n", pmGetProgname(), pmErrStr(sts));
exit(1);
}
logctl.l_label.ill_vol = PM_LOG_VOL_META;
if ((sts = __pmLogWriteLabel(logctl.l_mdfp, &logctl.l_label)) != 0) {
fprintf(stderr, "%s: __pmLogWriteLabel META failed: %s\n", pmGetProgname(), pmErrStr(sts));
exit(1);
}
logctl.l_label.ill_vol = 0;
if ((sts = __pmLogWriteLabel(archctl.ac_mfp, &logctl.l_label)) != 0) {
fprintf(stderr, "%s: __pmLogWriteLabel VOL 0 failed: %s\n", pmGetProgname(), pmErrStr(sts));
exit(1);
}
__pmFflush(archctl.ac_mfp);
__pmFflush(logctl.l_mdfp);
__pmLogPutIndex(&archctl, &epoch);
pmids = (pmID *)malloc(nmetric*sizeof(pmID));
assert(pmids != NULL);
for (i = 0; i < nmetric; i++) {
if ((sts = pmLookupName(1, &metrics[i], &pmids[i])) != 1) {
fprintf(stderr, "%s: pmLookupName(\"%s\") failed: %s\n", pmGetProgname(), metrics[i], pmErrStr(sts));
exit(1);
}
printf("%s -> %s\n", metrics[i], pmIDStr(pmids[i]));
if ((sts = pmLookupDesc(pmids[i], &desc)) < 0) {
fprintf(stderr, "%s: pmLookupDesc(\"%s\") failed: %s\n", pmGetProgname(), pmIDStr(pmids[i]), pmErrStr(sts));
exit(1);
}
if ((sts = __pmLogPutDesc(&archctl, &desc, 1, &metrics[i])) < 0) {
fprintf(stderr, "%s: __pmLogPutDesc(\"%s\") failed: %s\n", pmGetProgname(), pmIDStr(pmids[i]), pmErrStr(sts));
exit(1);
}
if (desc.indom != PM_INDOM_NULL) {
if ((numinst = pmGetInDom(desc.indom, &ilist, &nlist)) < 0) {
printf("pmGetInDom: %s: %s\n", pmInDomStr(desc.indom), pmErrStr(numinst));
exit(1);
}
if ((sts = __pmLogPutInDom(&archctl, desc.indom, &epoch, numinst, ilist, nlist)) < 0) {
fprintf(stderr, "%s: __pmLogPutInDom(...,indom=%s,numinst=%d,...) failed: %s\n", pmGetProgname(), pmInDomStr(desc.indom), numinst, pmErrStr(sts));
exit(1);
}
}
}
for (i = 0; i < nmetric; i++) {
if ((sts = pmFetch(i+1, pmids, &rp)) < 0) {
fprintf(stderr, "%s: pmFetch(%d, ...) failed: %s\n", pmGetProgname(), i+1, pmErrStr(sts));
exit(1);
}
rp->timestamp.tv_sec = ++epoch.tv_sec;
rp->timestamp.tv_usec = epoch.tv_usec;
if ((sts = __pmEncodeResult(__pmFileno(archctl.ac_mfp), rp, &pdp)) < 0) {
fprintf(stderr, "%s: __pmEncodeResult failed: %s\n", pmGetProgname(), pmErrStr(sts));
exit(1);
}
__pmOverrideLastFd(__pmFileno(archctl.ac_mfp));
if (bflag) {
printf("__pmLogPutResult: %d metrics ...\n", i+1);
if ((sts = __pmLogPutResult(&archctl, pdp)) < 0) {
fprintf(stderr, "%s: __pmLogPutResult failed: %s\n", pmGetProgname(), pmErrStr(sts));
exit(1);
}
}
else {
printf("__pmLogPutResult2: %d metrics ...\n", i+1);
if ((sts = __pmLogPutResult2(&archctl, pdp)) < 0) {
fprintf(stderr, "%s: __pmLogPutResult2 failed: %s\n", pmGetProgname(), pmErrStr(sts));
exit(1);
}
}
__pmUnpinPDUBuf(pdp);
pmFreeResult(rp);
}
__pmFflush(archctl.ac_mfp);
__pmFflush(logctl.l_mdfp);
__pmLogPutIndex(&archctl, &epoch);
return 0;
}
|