qa: update 660 to generate index.html, fixing pcp-testsuite runs
[pcp.git] / qa / src / clientid.c
blob066f304e99a33084afdcdb1dbccc175f76f6fd14
1 /*
2 * Exercise __pmSetClientId()
4 * Copyright (c) 2009 Ken McDonell. All Rights Reserved.
5 */
7 #include <ctype.h>
8 #include <pcp/pmapi.h>
9 #include <pcp/impl.h>
11 #define TAG "QA-clientid "
13 int
14 main(int argc, char *argv[])
16 int ctx;
17 int sts;
18 int c;
19 int a;
20 int lflag = 0;
21 int errflag = 0;
22 static char *usage = "[-l] [-D debugopts]";
24 __pmSetProgname(argv[0]);
26 while ((c = getopt(argc, argv, "D:l")) != EOF) {
27 switch (c) {
29 #ifdef PCP_DEBUG
30 case 'D': /* debug flag */
31 sts = __pmParseDebug(optarg);
32 if (sts < 0) {
33 fprintf(stderr, "%s: unrecognized debug flag specification (%s)\n",
34 pmProgname, optarg);
35 errflag++;
37 else
38 pmDebug |= sts;
39 break;
40 #endif
42 case 'l': /* linger when done */
43 lflag = 1;
44 break;
46 case '?':
47 default:
48 errflag++;
49 break;
53 if (errflag) {
54 printf("Usage: %s %s\n", pmProgname, usage);
55 exit(1);
58 fprintf(stderr, "Error expected ...\n");
59 if ((sts = __pmSetClientId("no context yet, bozo")) < 0) {
60 fprintf(stderr, "__pmSetClientId(...): %s\n",
61 pmErrStr(sts));
64 if ((ctx = pmNewContext(PM_CONTEXT_HOST, "localhost")) < 0) {
65 fprintf(stderr, "pmNewContext(..., \"localhost\"): %s\n",
66 pmErrStr(ctx));
67 exit(1);
70 for (a = optind; a < argc; a++) {
71 char *cp;
72 cp = (char *)malloc(strlen(argv[a])+strlen(TAG)+1);
73 strcpy(cp, TAG);
74 strcat(cp, argv[a]);
75 if ((sts = __pmSetClientId(cp)) < 0) {
76 fprintf(stderr, "__pmSetClientId(%s): %s\n",
77 cp, pmErrStr(sts));
79 else {
80 sts = system("pminfo -f pmcd.client.whoami");
81 if (sts != 0)
82 fprintf(stderr, "Warning: pminfo command: exit status %d\n", sts);
84 free(cp);
87 if (lflag)
88 pause();
90 exit(0);