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/dumb_pmda.c | |
download | pcp-debian/3.9.10.tar.gz |
Debian 3.9.10debian/3.9.10debian
Diffstat (limited to 'qa/src/dumb_pmda.c')
-rw-r--r-- | qa/src/dumb_pmda.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/qa/src/dumb_pmda.c b/qa/src/dumb_pmda.c new file mode 100644 index 0000000..c60225f --- /dev/null +++ b/qa/src/dumb_pmda.c @@ -0,0 +1,81 @@ +/* + * Dumb, a PMDA which never responds to requests ... used in qa/023 + * + * Copyright (c) 1995-2001 Silicon Graphics, Inc. All Rights Reserved. + */ + +#include <pcp/pmapi.h> +#include <pcp/impl.h> +#include <pcp/pmda.h> + +#include "localconfig.h" + +#if PCP_VER < 3611 +#define __pmRead read +#endif + +static void +usage(void) +{ + fprintf(stderr, "Usage: %s [options] controlwords\n\n", pmProgname); + fputs("Options:\n" + " -D N set pmDebug debugging flag to N\n" + " -d domain use domain (numeric) for metrics domain of PMDA\n" + " -h helpfile get help text from helpfile rather then default path\n" + " -l logfile write log into logfile rather than using default log name\n", + stderr); + exit(1); +} + +/* + * Set up the agent if running as a daemon. + */ + +int +main(int argc, char **argv) +{ + int err = 0; + int sts; + pmdaInterface desc = { 0 }; + char c; + int exit_action = 0; + + __pmSetProgname(argv[0]); + + pmdaDaemon(&desc, PMDA_INTERFACE_3, pmProgname, desc.domain, "dumb_pmda.log", NULL); + if (desc.status != 0) { + fprintf(stderr, "pmdaDaemon() failed!\n"); + exit(1); + } + + if (pmdaGetOpt(argc, argv, "D:d:h:l:", &desc, &err) != EOF) + err++; + if (err) + usage(); + + /* + * scan cmd line args for action keywords ... + */ + for (; optind < argc; optind++) { + if (strcmp(argv[optind], "exit") == 0) exit_action = 1; + } + + pmdaOpenLog(&desc); + pmdaConnect(&desc); + + /* + * We have connection to pmcd ... consume PDUs from pmcd, + * ignore them, optionally execute an action and exit on end of file + */ + + while ((sts = __pmRead(desc.version.two.ext->e_infd, &c, 1)) == 1) { + if (exit_action) exit(1); + } + + if (sts < 0) { + fprintf(stderr, "dumb_pmda: Error on read from pmcd?: %s\n", strerror(errno)); + exit(1); + } + + exit(0); +} |