--- GNUmakefile 2014-07-03 17:02:50.548196806 +1000 +++ GNUmakefile.nathans 2014-07-03 17:02:25.891129164 +1000 @@ -21,6 +21,7 @@ IAM = perfevent DOMAIN = PERFEVENT CMDTARGET = pmda$(IAM) LIBTARGET = pmda_$(IAM).$(DSOSUFFIX) +PMDAINIT = $(IAM)_init PMDADIR = $(PCP_PMDAS_DIR)/$(IAM) @@ -34,8 +35,10 @@ SCRIPTS = Install Remove DFILES = README help +VERSION_SCRIPT = exports LSRCFILES = pmns root $(DFILES) $(SCRIPTS) \ perfevent.conf perfinterface.h +LDIRT = domain.h $(VERSION_SCRIPT) VERSION := $(shell head -n 1 ChangeLog | cut -d ":" -f 1) @@ -44,7 +47,7 @@ default: build-me include $(BUILDRULES) ifeq "$(TARGET_OS)" "linux" -build-me: domain.h $(LIBTARGET) $(CMDTARGET) $(HELPTARGETS) perfalloc +build-me: domain.h $(LIBTARGET) $(CMDTARGET) perfalloc install: default $(INSTALL) -m 755 -d $(PMDADIR) @@ -63,9 +66,11 @@ install_pcp : install TARGETS = $(LIBTARGET) $(CMDTARGET) perfalloc LLDLIBS = $(PCP_PMDALIB) -lpfm -lrt -LCFLAGS = -I. +LCFLAGS = -I. $(INVISIBILITY) CFLAGS += -DVERSION=\"$(VERSION)\" +$(VERSION_SCRIPT): + $(VERSION_SCRIPT_MAKERULE) domain.h: ../../pmns/stdpmid $(DOMAIN_MAKERULE) @@ -74,4 +79,4 @@ configparser.yy.c: configparser.l config flex -o $@ $< perfalloc: perfalloc.o - +pmda.o: $(VERSION_SCRIPT) --- pmda.c 2014-06-27 02:07:56.000000000 +1000 +++ pmda.c.nathans 2014-07-03 16:25:45.201195901 +1000 @@ -138,6 +138,26 @@ static const char *dynamic_helptab[] = static char mypath[MAXPATHLEN]; static int isDSO = 1; /* =0 I am a daemon */ static char *username; +static pmLongOptions longopts[] = +{ + PMDA_OPTIONS_HEADER("Options"), + PMOPT_DEBUG, + PMDAOPT_DOMAIN, + PMDAOPT_LOGFILE, + PMDAOPT_USERNAME, + PMOPT_HELP, + PMDA_OPTIONS_TEXT("\nExactly one of the following options may appear:"), + PMDAOPT_INET, + PMDAOPT_PIPE, + PMDAOPT_UNIX, + PMDAOPT_IPV6, + PMDA_OPTIONS_END +}; +static pmdaOptions opts = +{ + .short_options = "D:d:i:l:pu:U:6:?", + .long_options = longopts, +}; /* * \brief callback function that retrieves the metric value. @@ -469,6 +489,7 @@ static int setup_pmns() * Initialise the agent (both daemon and DSO). */ void +__PMDA_INIT_CALL perfevent_init(pmdaInterface *dp) { if (isDSO) @@ -489,6 +510,7 @@ perfevent_init(pmdaInterface *dp) { return; } + atexit(teardown_perfevents); if(!isDSO) { @@ -520,28 +542,11 @@ perfevent_init(pmdaInterface *dp) __pmNotifyErr(LOG_INFO, "perfevent version " VERSION " initialised\n"); } -static void usage(void) -{ - fprintf(stderr, "Usage: %s [options]\n\n", pmProgname); - fputs("Options:\n" - " -d domain use domain (numeric) for metrics domain of PMDA\n" - " -l logfile write log into logfile rather than using default log name\n" - " -U username user account to run under (default \"pcp\")\n" - "\nExactly one of the following options may appear:\n" - " -i port expect PMCD to connect on given inet port (number or name)\n" - " -p expect PMCD to supply stdin/stdout (pipe)\n" - " -u socket expect PMCD to connect on given unix domain socket\n" - " -6 port expect PMCD to connect on given ipv6 port (number or name)\n", - stderr); - exit(1); -} - /* * Set up the agent if running as a daemon. */ int main(int argc, char **argv) { - int c, err = 0; int sep = __pmPathSeparator(); pmdaInterface dispatch; @@ -554,26 +559,17 @@ int main(int argc, char **argv) pmdaDaemon(&dispatch, PMDA_INTERFACE_5, pmProgname, PERFEVENT, "perfevent.log", mypath); - while ((c = pmdaGetOpt(argc, argv, "D:d:i:l:pu:U:6:?", &dispatch, &err)) != EOF) + pmdaGetOptions(argc, argv, &opts, &dispatch); + if (opts.errors) { - switch(c) - { - case 'U': - username = optarg; - break; - default: - err++; - } + pmdaUsageMessage(&opts); + exit(1); } - if (err) - usage(); pmdaOpenLog(&dispatch); perfevent_init(&dispatch); pmdaConnect(&dispatch); pmdaMain(&dispatch); - teardown_perfevents(); - exit(0); }