/var/lib/pcp/testsuite/src/exectest.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 | /*
* Exercise pmSetDebug() and pmClearDebug(), and the deprecated
* __pmParseDebug() interface.
*
* Copyright (c) 2017 Ken McDonell. All Rights Reserved.
*/
#include <pcp/pmapi.h>
#include "libpcp.h"
#include <sys/types.h>
#include <sys/wait.h>
static void
report_status(int status)
{
if (status == 0)
return;
else if (status < 0)
printf(" %s", pmErrStr(status));
else if (status >= 2000)
printf(" unknown cause");
else if (status >= 1000)
printf(" signal=%d", status-1000);
else
printf(" exit=%d", status);
}
int
main(int argc, char **argv)
{
__pmExecCtl_t *h;
int sts;
int c;
int errflag = 0;
int pipein = 0;
int pipeout = 0;
FILE *fin;
FILE *fout;
/* trim cmd name of leading directory components */
pmSetProgname(argv[0]);
setlinebuf(stdout);
setlinebuf(stderr);
while ((c = getopt(argc, argv, "D:pP:?")) != 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 'p': /* __pmProcessPipe(), reading */
if (pipein || pipeout) {
fprintf(stderr, "%s: at most one of -p or -P allowed\n", pmGetProgname());
errflag++;
}
pipein++;
break;
case 'P': /* __pmProcessPipe(), writing */
if (pipein || pipeout) {
fprintf(stderr, "%s: at most one of -p or -P allowed\n", pmGetProgname());
errflag++;
}
pipeout++;
if ((fin = fopen(optarg, "r")) == NULL) {
fprintf(stderr, "%s: cannot open \"%s\" for reading: \"%s\"\n",
pmGetProgname(), optarg, pmErrStr(-errno));
exit(1);
}
break;
case '?':
default:
errflag++;
break;
}
}
if (errflag || optind == argc) {
fprintf(stderr,
"Usage: %s [options] execarg ...\n\
\n\
Options:\n\
-D debug[,...] set PCP debugging option(s)\n\
-p read to EOF from __pmProcessPipe\n\
-P data read data file and write to __pmProcessPipe\n",
pmGetProgname());
exit(1);
}
h = NULL;
while (optind < argc) {
sts = __pmProcessAddArg(&h, argv[optind]);
if (pmDebugOptions.desperate) printf("sts=%d h=%p\n", sts, h);
if (h == NULL) {
printf("__pmProcessAddArg: failed (handle is NULL) at argv[%d]: \"%s\"\n", optind-1, argv[optind]);
exit(1);
}
optind++;
}
if (pipein) {
sts = __pmProcessPipe(&h, "r", PM_EXEC_TOSS_NONE, &fin);
printf("__pmProcessPipe(..., \"r\", ...) -> %d", sts);
if (sts < 0) {
printf(": %s\n", pmErrStr(sts));
}
else {
putchar('\n');
while ((c = fgetc(fin)) != EOF) {
putchar(c);
}
sts = __pmProcessPipeClose(fin);
printf("__pmProcessPipeClose() -> %d", sts);
report_status(sts);
putchar('\n');
}
}
else if (pipeout) {
sts = __pmProcessPipe(&h, "w", PM_EXEC_TOSS_NONE, &fout);
printf("__pmProcessPipe(..., \"w\", ...) -> %d", sts);
if (sts < 0) {
printf(": %s\n", pmErrStr(sts));
}
else {
putchar('\n');
while ((c = fgetc(fin)) != EOF) {
fputc(c, fout);
}
sts = __pmProcessPipeClose(fout);
printf("__pmProcessPipeClose() -> %d", sts);
report_status(sts);
putchar('\n');
}
}
else {
sts = __pmProcessExec(&h, PM_EXEC_TOSS_NONE, PM_EXEC_WAIT);
printf("__pmProcessExec -> %d", sts);
report_status(sts);
putchar('\n');
}
return(0);
}
|