diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2014-10-26 12:33:50 +0400 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2014-10-26 12:33:50 +0400 |
commit | 47e6e7c84f008a53061e661f31ae96629bc694ef (patch) | |
tree | 648a07f3b5b9d67ce19b0fd72e8caa1175c98f1a /qa/src/clientid.c | |
download | pcp-debian/3.9.10.tar.gz |
Debian 3.9.10debian/3.9.10debian
Diffstat (limited to 'qa/src/clientid.c')
-rw-r--r-- | qa/src/clientid.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/qa/src/clientid.c b/qa/src/clientid.c new file mode 100644 index 0000000..066f304 --- /dev/null +++ b/qa/src/clientid.c @@ -0,0 +1,91 @@ +/* + * Exercise __pmSetClientId() + * + * Copyright (c) 2009 Ken McDonell. All Rights Reserved. + */ + +#include <ctype.h> +#include <pcp/pmapi.h> +#include <pcp/impl.h> + +#define TAG "QA-clientid " + +int +main(int argc, char *argv[]) +{ + int ctx; + int sts; + int c; + int a; + int lflag = 0; + int errflag = 0; + static char *usage = "[-l] [-D debugopts]"; + + __pmSetProgname(argv[0]); + + while ((c = getopt(argc, argv, "D:l")) != EOF) { + switch (c) { + +#ifdef PCP_DEBUG + case 'D': /* debug flag */ + sts = __pmParseDebug(optarg); + if (sts < 0) { + fprintf(stderr, "%s: unrecognized debug flag specification (%s)\n", + pmProgname, optarg); + errflag++; + } + else + pmDebug |= sts; + break; +#endif + + case 'l': /* linger when done */ + lflag = 1; + break; + + case '?': + default: + errflag++; + break; + } + } + + if (errflag) { + printf("Usage: %s %s\n", pmProgname, usage); + exit(1); + } + + fprintf(stderr, "Error expected ...\n"); + if ((sts = __pmSetClientId("no context yet, bozo")) < 0) { + fprintf(stderr, "__pmSetClientId(...): %s\n", + pmErrStr(sts)); + } + + if ((ctx = pmNewContext(PM_CONTEXT_HOST, "localhost")) < 0) { + fprintf(stderr, "pmNewContext(..., \"localhost\"): %s\n", + pmErrStr(ctx)); + exit(1); + } + + for (a = optind; a < argc; a++) { + char *cp; + cp = (char *)malloc(strlen(argv[a])+strlen(TAG)+1); + strcpy(cp, TAG); + strcat(cp, argv[a]); + if ((sts = __pmSetClientId(cp)) < 0) { + fprintf(stderr, "__pmSetClientId(%s): %s\n", + cp, pmErrStr(sts)); + } + else { + sts = system("pminfo -f pmcd.client.whoami"); + if (sts != 0) + fprintf(stderr, "Warning: pminfo command: exit status %d\n", sts); + } + free(cp); + } + + if (lflag) + pause(); + + exit(0); +} |