QedApp::QedApp(int &argc, char **argv) : QApplication(argc, argv) { // TODO: rewrite with pmOptions __pmSetProgname(argv[0]); my.argc = argc; my.argv = argv; my.pmnsfile = NULL; my.Lflag = 0; my.Sflag = NULL; my.Tflag = NULL; my.Aflag = NULL; my.Oflag = NULL; my.zflag = 0; my.tz = NULL; my.port = -1; QCoreApplication::setOrganizationName("PCP"); QCoreApplication::setApplicationName(pmProgname); QCoreApplication::setApplicationVersion(pmGetConfig("PCP_VERSION")); QString confirm = pmGetConfig("PCP_BIN_DIR"); confirm.prepend("PCP_XCONFIRM_PROG="); confirm.append("/pmquery"); putenv(strdup((const char *)confirm.toLatin1())); if (getenv("PCP_STDERR") == NULL) // do not overwrite, for QA putenv(strdup("PCP_STDERR=DISPLAY")); }
/* * Set up the agent if running as a daemon. */ int main(int argc, char **argv) { int sep = __pmPathSeparator(); pmdaInterface desc; _isDSO = 0; __pmSetProgname(argv[0]); __pmGetUsername(&username); snprintf(mypath, sizeof(mypath), "%s%c" "aix" "%c" "help", pmGetConfig("PCP_PMDAS_DIR"), sep, sep); pmdaDaemon(&desc, PMDA_INTERFACE_3, pmProgname, AIX, "aix.log", mypath); pmdaGetOptions(argc, argv, &opts, &desc); if (opts.errors) { pmdaUsageMessage(&opts); exit(1); } if (opts.username) username = opts.username; pmdaOpenLog(&desc); aix_init(&desc); pmdaConnect(&desc); pmdaMain(&desc); exit(0); }
/* * Initialise the agent (both daemon and DSO). */ void __PMDA_INIT_CALL mounts_init(pmdaInterface *dp) { if (isDSO) { int sep = __pmPathSeparator(); snprintf(mypath, sizeof(mypath), "%s%c" "mounts" "%c" "help", pmGetConfig("PCP_PMDAS_DIR"), sep, sep); pmdaDSO(dp, PMDA_INTERFACE_2, "mounts DSO", mypath); } else { __pmSetProcessIdentity(username); } if (dp->status != 0) return; dp->version.two.fetch = mounts_fetch; pmdaSetFetchCallBack(dp, mounts_fetchCallBack); pmdaInit(dp, indomtab, sizeof(indomtab)/sizeof(indomtab[0]), metrictab, sizeof(metrictab)/sizeof(metrictab[0])); /* Let's grab the info right away just to make sure it's there. */ mounts_grab_config_info(); }
static void mounts_config_file_check(void) { struct stat statbuf; static int last_error; int sep = __pmPathSeparator(); snprintf(mypath, sizeof(mypath), "%s%c" "mounts" "%c" "mounts.conf", pmGetConfig("PCP_PMDAS_DIR"), sep, sep); if (stat(mypath, &statbuf) == -1) { if (oserror() != last_error) { last_error = oserror(); __pmNotifyErr(LOG_WARNING, "stat failed on %s: %s\n", mypath, pmErrStr(last_error)); } } else { last_error = 0; #if defined(HAVE_ST_MTIME_WITH_E) if (statbuf.st_mtime != file_change.st_mtime) #elif defined(HAVE_ST_MTIME_WITH_SPEC) if (statbuf.st_mtimespec.tv_sec != file_change.st_mtimespec.tv_sec || statbuf.st_mtimespec.tv_nsec != file_change.st_mtimespec.tv_nsec) #else if (statbuf.st_mtim.tv_sec != file_change.st_mtim.tv_sec || statbuf.st_mtim.tv_nsec != file_change.st_mtim.tv_nsec) #endif { mounts_clear_config_info(); mounts_grab_config_info(); file_change = statbuf; } } }
void darwin_init(pmdaInterface *dp) { if (_isDSO) { int sep = __pmPathSeparator(); char helppath[MAXPATHLEN]; sprintf(helppath, "%s%c" "darwin" "%c" "help", pmGetConfig("PCP_PMDAS_DIR"), sep, sep); pmdaDSO(dp, PMDA_INTERFACE_3, "darwin DSO", helppath); } else { __pmSetProcessIdentity(username); } if (dp->status != 0) return; dp->version.two.instance = darwin_instance; dp->version.two.fetch = darwin_fetch; pmdaSetFetchCallBack(dp, darwin_fetchCallBack); pmdaSetFlags(dp, PMDA_EXT_FLAG_DIRECT); pmdaInit(dp, indomtab, sizeof(indomtab)/sizeof(indomtab[0]), metrictab, sizeof(metrictab)/sizeof(metrictab[0])); mach_host = mach_host_self(); host_page_size(mach_host, &mach_page_size); mach_page_shift = ffs(mach_page_size) - 1; if (refresh_hertz(&mach_hertz) != 0) mach_hertz = 100; init_network(); }
int main(int argc, char **argv) { int c, sep = __pmPathSeparator(); int errflag = 0; char helppath[MAXPATHLEN]; _isDSO = 0; __pmSetProgname(argv[0]); __pmGetUsername(&username); sprintf(helppath, "%s%c" "darwin" "%c" "help", pmGetConfig("PCP_PMDAS_DIR"), sep, sep); pmdaDaemon(&dispatch, PMDA_INTERFACE_3, pmProgname, DARWIN, "darwin.log", helppath); while ((c = pmdaGetOpt(argc, argv, "D:d:i:l:pu:U:6:?", &dispatch, &errflag)) != EOF) { switch(c) { case 'U': username = optarg; break; default: errflag++; } } if (errflag) usage(); pmdaOpenLog(&dispatch); darwin_init(&dispatch); pmdaConnect(&dispatch); pmdaMain(&dispatch); exit(0); }
/* * Set up the agent if running as a daemon. */ int main(int argc, char **argv) { int c, err = 0; int sep = __pmPathSeparator(); pmdaInterface dispatch; char mypath[MAXPATHLEN]; isDSO = 0; __pmSetProgname(argv[0]); __pmGetUsername(&username); snprintf(mypath, sizeof(mypath), "%s%c" "openbsd" "%c" "help", pmGetConfig("PCP_PMDAS_DIR"), sep, sep); pmdaDaemon(&dispatch, PMDA_INTERFACE_5, pmProgname, OPENBSD, "openbsd.log", mypath); while ((c = pmdaGetOpt(argc, argv, "D:d:i:l:pu:U:6:?", &dispatch, &err)) != EOF) { switch(c) { case 'U': username = optarg; break; default: err++; } } if (err) usage(); pmdaOpenLog(&dispatch); openbsd_init(&dispatch); pmdaConnect(&dispatch); pmdaMain(&dispatch); exit(0); }
int __pmServerCreatePIDFile(const char *spec, int verbose) { char pidpath[MAXPATHLEN]; FILE *pidfile; if (!serviceSpec) __pmServerSetServiceSpec(spec); snprintf(pidpath, sizeof(pidpath), "%s%c%s.pid", pmGetConfig("PCP_RUN_DIR"), __pmPathSeparator(), spec); if ((pidfile = fopen(pidpath, "w")) == NULL) { if (verbose) fprintf(stderr, "Error: cannot open PID file %s\n", pidpath); return -oserror(); } atexit(pidonexit); fprintf(pidfile, "%" FMT_PID, getpid()); #ifdef HAVE_FCHMOD (void)fchmod(fileno(pidfile), S_IRUSR | S_IRGRP | S_IROTH); #else (void)chmod(pidpath, S_IRUSR | S_IRGRP | S_IROTH); #endif fclose(pidfile); return 0; }
/* * Set up agent if running as daemon. */ int main(int argc, char **argv) { int sep = __pmPathSeparator(); pmdaInterface dispatch; isDSO = 0; __pmSetProgname(argv[0]); snprintf(helppath, sizeof(helppath), "%s%c" "papi" "%c" "help", pmGetConfig("PCP_PMDAS_DIR"), sep, sep); pmdaDaemon(&dispatch, PMDA_INTERFACE_6, pmProgname, PAPI, "papi.log", helppath); pmdaGetOptions(argc, argv, &opts, &dispatch); if (opts.errors) { pmdaUsageMessage(&opts); exit(1); } pmdaOpenLog(&dispatch); papi_init(&dispatch); pmdaConnect(&dispatch); pmdaMain(&dispatch); free(ctxtab); free(papi_info); free(values); exit(0); }
void etw_init(pmdaInterface *dp, const char *configfile) { char helppath[MAXPATHLEN]; int sep = __pmPathSeparator(); snprintf(helppath, sizeof(helppath), "%s%c" "etw" "%c" "help", pmGetConfig("PCP_PMDAS_DIR"), sep, sep); pmdaDSO(dp, PMDA_INTERFACE_5, "etw DSO", helppath); if (dp->status != 0) return; if (event_table_init() < 0) return; if (event_init() < 0) return; dp->version.four.fetch = etw_fetch; dp->version.four.store = etw_store; dp->version.four.profile = etw_profile; dp->version.four.text = etw_text; pmdaSetFetchCallBack(dp, etw_fetchCallBack); pmdaSetEndContextCallBack(dp, etw_end_contextCallBack); pmdaInit(dp, NULL, 0, metrictab, sizeof(metrictab)/sizeof(metrictab[0])); }
inline Type get_pcp_runtime_version() { const char * const str = pmGetConfig("PCP_VERSION"); const char * const pos[2] = { strchr(str, '.'), strrchr(str, '.') }; return (pos[0] == pos[1]) ? 0 : (strtoul(str, NULL, 10) << 16) + (strtoul(pos[0]+1, NULL, 10) << 8) + strtoul(pos[1]+1, NULL, 10); }
static char * helpfile(void) { static char buf[MAXPATHLEN]; if (!buf[0]) { snprintf(buf, sizeof(buf), "%s/ctdb/help", pmGetConfig("PCP_PMDAS_DIR")); } return buf; }
static void pidonexit(void) { char pidpath[MAXPATHLEN]; if (serviceSpec) { snprintf(pidpath, sizeof(pidpath), "%s%c%s.pid", pmGetConfig("PCP_RUN_DIR"), __pmPathSeparator(), serviceSpec); unlink(pidpath); } }
static FILE * do_pmcpp(char *configfile) { FILE *f; char cmd[3*MAXPATHLEN+80]; char *bin_dir = pmGetConfig("PCP_BINADM_DIR"); char *lib_dir = pmGetConfig("PCP_VAR_DIR"); if (configfile != NULL) { if ((f = fopen(configfile, "r")) == NULL) { fprintf(stderr, "%s: Cannot open config file \"%s\": %s\n", pmProgname, configfile, osstrerror()); exit(1); } fclose(f); } if (bin_dir == NULL) { fprintf(stderr, "%s: pmGetConfig: cannot get $PCP_BINADM_DIR value\n", pmProgname); exit(1); } if (lib_dir == NULL) { fprintf(stderr, "%s: pmGetConfig: cannot get $PCP_VAR_DIR value\n", pmProgname); exit(1); } snprintf(cmd, sizeof(cmd), "%s%cpmcpp -rs %s -I %s%cconfig%cpmlogger", bin_dir, sep, configfile == NULL ? "" : configfile, lib_dir, sep, sep); fprintf(stderr, "preprocessor cmd: %s\n", cmd); if ((f = popen(cmd, "r")) == NULL) { fprintf(stderr, "%s: popen(\"%s\", \"r\") failed: %s\n", pmProgname, cmd, osstrerror()); exit(1); } return f; }
void PmChart::helpManual() { bool ok; QString documents("file://"); QString separator = QString(__pmPathSeparator()); documents.append(pmGetConfig("PCP_HTML_DIR")); documents.append(separator).append("index.html"); ok = QDesktopServices::openUrl(QUrl(documents, QUrl::TolerantMode)); if (!ok) { documents.prepend("Failed to open:\n"); QMessageBox::warning(this, pmProgname, documents); } }
/* * This routine opens the config file and stores the information in the * mounts structure. The mounts structure must be reallocated as * necessary, and also the num_procs structure needs to be reallocated * as we define new mounts. When all of that is done, we fill in the * values in the indomtab structure, those being the number of instances * and the pointer to the mounts structure. */ static void mounts_grab_config_info(void) { FILE *fp; char mount_name[MAXPATHLEN]; char *q; size_t size; int mount_number = 0; int sep = __pmPathSeparator(); snprintf(mypath, sizeof(mypath), "%s%c" "mounts" "%c" "mounts.conf", pmGetConfig("PCP_PMDAS_DIR"), sep, sep); if ((fp = fopen(mypath, "r")) == NULL) { __pmNotifyErr(LOG_ERR, "fopen on %s failed: %s\n", mypath, pmErrStr(-oserror())); if (mounts) { free(mounts); mounts = NULL; mount_number = 0; } goto done; } while (fgets(mount_name, sizeof(mount_name), fp) != NULL) { if (mount_name[0] == '#') continue; /* Remove the newline */ if ((q = strchr(mount_name, '\n')) != NULL) { *q = '\0'; } else { /* This means the line was too long */ __pmNotifyErr(LOG_WARNING, "line %d in the config file too long\n", mount_number+1); } size = (mount_number + 1) * sizeof(pmdaInstid); if ((mounts = realloc(mounts, size)) == NULL) __pmNoMem("process", size, PM_FATAL_ERR); mounts[mount_number].i_name = malloc(strlen(mount_name) + 1); strcpy(mounts[mount_number].i_name, mount_name); mounts[mount_number].i_inst = mount_number; mount_number++; } fclose(fp); done: if (mounts == NULL) __pmNotifyErr(LOG_WARNING, "\"mounts\" instance domain is empty"); indomtab[MOUNTS_INDOM].it_set = mounts; indomtab[MOUNTS_INDOM].it_numinst = mount_number; mount_list = realloc(mount_list, (mount_number)*sizeof(mountinfo)); }
/* * Parse our stomp configuration file, simple format: * host=<hostname> # JMS server machine * port=<port#> # server port number * username=<user> | user=<user> * passcode=<password> | password=<password> * timeout=<seconds> # optional * topic=<JMStopic> # optional */ static void stomp_parse(void) { char config[MAXPATHLEN+1]; FILE *f; int sep = __pmPathSeparator(); if (stompfile) strncat(config, stompfile, sizeof(config)-1); else snprintf(config, sizeof(config), "%s%c" "config" "%c" "pmie" "%c" "stomp", pmGetConfig("PCP_VAR_DIR"), sep, sep, sep); if ((f = fopen(config, "r")) == NULL) { __pmNotifyErr(LOG_ERR, "Cannot open STOMP configuration file %s: %s", config, osstrerror()); exit(1); } while (fgets(buffer, sizeof(buffer), f)) { if (strncmp(buffer, "port=", 5) == 0) port = atoi(isspace_terminate(&buffer[5])); else if (strncmp(buffer, "host=", 5) == 0) hostname = strdup(isspace_terminate(&buffer[5])); else if (strncmp(buffer, "hostname=", 9) == 0) hostname = strdup(isspace_terminate(&buffer[9])); else if (strncmp(buffer, "user="******"username="******"password="******"passcode=", 9) == 0) passcode = strdup(isspace_terminate(&buffer[9])); else if (strncmp(buffer, "timeout=", 8) == 0) /* optional */ timeout = atoi(isspace_terminate(&buffer[8])); else if (strncmp(buffer, "topic=", 6) == 0) /* optional */ topic = strdup(isspace_terminate(&buffer[6])); } fclose(f); if (!hostname) __pmNotifyErr(LOG_ERR, "No host in STOMP config file %s", config); if (port == -1) __pmNotifyErr(LOG_ERR, "No port in STOMP config file %s", config); if (!username) __pmNotifyErr(LOG_ERR, "No username in STOMP config file %s", config); if (!passcode) __pmNotifyErr(LOG_ERR, "No passcode in STOMP config file %s", config); if (port == -1 || !hostname || !username || !passcode) exit(1); }
void PmChart::filePrint() { QPrinter printer; QString creator = QString("pmchart Version "); creator.append(pmGetConfig("PCP_VERSION")); printer.setCreator(creator); printer.setOrientation(QPrinter::Portrait); printer.setDocName("pmchart.pdf"); QPrintDialog print(&printer, (QWidget *)this); if (print.exec()) { QPainter qp(&printer); painter(&qp, printer.width(), printer.height(), false, false); } }
static void setupEnvironment(void) { char *value; QString confirm = pmGetConfig("PCP_BIN_DIR"); confirm.prepend("PCP_XCONFIRM_PROG="); confirm.append(QChar(__pmPathSeparator())); confirm.append("pmquery"); if ((value = strdup((const char *)confirm.toLatin1())) != NULL) putenv(value); if (getenv("PCP_STDERR") == NULL && // do not overwrite, for QA ((value = strdup("PCP_STDERR=DISPLAY")) != NULL)) putenv(value); QCoreApplication::setOrganizationName("PCP"); QCoreApplication::setApplicationName("pmtime"); }
void __PMDA_INIT_CALL papi_init(pmdaInterface *dp) { int sts; if (isDSO) { int sep = __pmPathSeparator(); snprintf(helppath, sizeof(helppath), "%s%c" "papi" "%c" "help", pmGetConfig("PCP_PMDAS_DIR"), sep, sep); pmdaDSO(dp, PMDA_INTERFACE_6, "papi DSO", helppath); } if (dp->status != 0) return; dp->comm.flags |= PDU_FLAG_AUTH; if ((sts = papi_internal_init(dp)) < 0) { __pmNotifyErr(LOG_ERR, "papi_internal_init: %s\n", pmErrStr(sts)); dp->status = PM_ERR_GENERIC; return; } if ((sts = papi_setup_auto_af()) < 0) { __pmNotifyErr(LOG_ERR, "papi_setup_auto_af: %s\n", pmErrStr(sts)); dp->status = PM_ERR_GENERIC; return; } dp->version.six.fetch = papi_fetch; dp->version.six.store = papi_store; dp->version.six.attribute = papi_contextAttributeCallBack; dp->version.six.desc = papi_desc; dp->version.any.text = papi_text; dp->version.four.pmid = papi_name_lookup; dp->version.four.children = papi_children; pmdaSetFetchCallBack(dp, papi_fetchCallBack); pmdaSetEndContextCallBack(dp, papi_endContextCallBack); pmdaInit(dp, NULL, 0, NULL, 0); }
/* * Initialise the agent (both daemon and DSO). */ void aix_init(pmdaInterface *dp) { if (_isDSO) { int sep = __pmPathSeparator(); snprintf(mypath, sizeof(mypath), "%s%c" "aix" "%c" "help", pmGetConfig("PCP_PMDAS_DIR"), sep, sep); pmdaDSO(dp, PMDA_INTERFACE_3, "AIX DSO", mypath); } else { __pmSetProcessIdentity(username); } if (dp->status != 0) return; dp->version.two.fetch = aix_fetch; pmdaSetFetchCallBack(dp, aix_fetch_callback); init_data(dp->domain); pmdaInit(dp, indomtab, indomtab_sz, metrictab, metrictab_sz); }
static inline int fetch_uname(unsigned int item, pmAtomValue *atom) { static char mach_uname_all[(_SYS_NAMELEN*5)+8]; if (mach_uname_error) return mach_uname_error; switch (item) { case 28: /* pmda.uname */ snprintf(mach_uname_all, sizeof(mach_uname_all), "%s %s %s %s %s", mach_uname.sysname, mach_uname.nodename, mach_uname.release, mach_uname.version, mach_uname.machine); atom->cp = mach_uname_all; return 1; case 29: /* pmda.version */ atom->cp = pmGetConfig("PCP_VERSION"); return 1; } return PM_ERR_PMID; }
void hotproc_init(void) { char h_configfile[MAXPATHLEN]; FILE *conf; int sep = __pmPathSeparator(); snprintf(h_configfile, sizeof(h_configfile), "%s%c" "proc" "%c" "hotproc.conf", pmGetConfig("PCP_PMDAS_DIR"), sep, sep); conf = open_config(h_configfile); /* Hotproc configured */ if (conf != NULL) { if (read_config(conf)) { conf_gen = 1; } fclose(conf); } }
/* * Initialise the agent (both daemon and DSO). */ void generic_init(pmdaInterface *dp) { if (isDSO) { int sep = __pmPathSeparator(); snprintf(mypath, sizeof(mypath), "%s%c" "generic" "%c" "help", pmGetConfig("PCP_PMDAS_DIR"), sep, sep); pmdaDSO(dp, PMDA_INTERFACE_2, "generic DSO", mypath); } /** else { __pmSetProcessIdentity(username); } */ if (dp->status != 0) return; pmdaSetFetchCallBack(dp, generic_fetchCallBack); pmdaInit(dp, NULL, 0, metrictab, sizeof(metrictab)/sizeof(metrictab[0])); }
/* * generate dialog/message when launching application wishes to break * its association with pmlogger * * cmd is one of the following: * D detach pmlogger and let it run forever * Q terminate pmlogger * ? display status * X fatal error or application exit ... user must decide * to detach or quit */ void do_dialog(char cmd) { FILE *msgf = NULL; time_t now; static char lbuf[100+MAXPATHLEN]; double archsize; char *q; char *p = NULL; int nchar; char *msg; #if HAVE_MKSTEMP char tmp[MAXPATHLEN]; #endif time(&now); now -= rsc_start; if (now == 0) /* hack is close enough! */ now = 1; archsize = vol_bytes + ftell(logctl.l_mfp); nchar = add_msg(&p, 0, ""); p[0] = '\0'; snprintf(lbuf, sizeof(lbuf), "PCP recording for the archive folio \"%s\" and the host", folio_name); nchar = add_msg(&p, nchar, lbuf); snprintf(lbuf, sizeof(lbuf), " \"%s\" has been in progress for %ld %s", pmcd_host, now < 240 ? now : now/60, now < 240 ? "seconds" : "minutes"); nchar = add_msg(&p, nchar, lbuf); nchar = add_msg(&p, nchar, " and in that time the pmlogger process has created an"); nchar = add_msg(&p, nchar, " archive of "); q = do_size(archsize); nchar = add_msg(&p, nchar, q); nchar = add_msg(&p, nchar, "."); if (rsc_replay) { nchar = add_msg(&p, nchar, "\n\nThis archive may be replayed with the following command:\n"); snprintf(lbuf, sizeof(lbuf), " $ pmafm %s replay", folio_name); nchar = add_msg(&p, nchar, lbuf); } if (cmd == 'D') { nchar = add_msg(&p, nchar, "\n\nThe application that launched pmlogger has asked pmlogger"); nchar = add_msg(&p, nchar, " to continue independently and the PCP archive will grow at"); nchar = add_msg(&p, nchar, " the rate of "); q = do_size((archsize * 3600) / now); nchar = add_msg(&p, nchar, q); nchar = add_msg(&p, nchar, " per hour or "); q = do_size((archsize * 3600 * 24) / now); nchar = add_msg(&p, nchar, q); nchar = add_msg(&p, nchar, " per day."); } if (cmd == 'X') { nchar = add_msg(&p, nchar, "\n\nThe application that launched pmlogger has exited and you"); nchar = add_msg(&p, nchar, " must decide if the PCP recording session should be terminated"); nchar = add_msg(&p, nchar, " or continued. If recording is continued the PCP archive will"); nchar = add_msg(&p, nchar, " grow at the rate of "); q = do_size((archsize * 3600) / now); nchar = add_msg(&p, nchar, q); nchar = add_msg(&p, nchar, " per hour or "); q = do_size((archsize * 3600 * 24) / now); nchar = add_msg(&p, nchar, q); nchar = add_msg(&p, nchar, " per day."); } if (cmd == 'Q') { nchar = add_msg(&p, nchar, "\n\nThe application that launched pmlogger has terminated"); nchar = add_msg(&p, nchar, " this PCP recording session.\n"); } if (cmd != 'Q') { nchar = add_msg(&p, nchar, "\n\nAt any time this pmlogger process may be terminated with the"); nchar = add_msg(&p, nchar, " following command:\n"); snprintf(lbuf, sizeof(lbuf), " $ pmsignal -s TERM %" FMT_PID "\n", getpid()); nchar = add_msg(&p, nchar, lbuf); } if (cmd == 'X') nchar = add_msg(&p, nchar, "\n\nTerminate this PCP recording session now?"); if (nchar > 0) { char * xconfirm = __pmNativePath(pmGetConfig("PCP_XCONFIRM_PROG")); int fd = -1; #if HAVE_MKSTEMP snprintf(tmp, sizeof(tmp), "%s%cmsgXXXXXX", pmGetConfig("PCP_TMPFILE_DIR"), __pmPathSeparator()); msg = tmp; fd = mkstemp(tmp); #else if ((msg = tmpnam(NULL)) != NULL) fd = open(msg, O_WRONLY|O_CREAT|O_EXCL, 0600); #endif if (fd >= 0) msgf = fdopen(fd, "w"); if (msgf == NULL) { fprintf(stderr, "\nError: failed create temporary message file for recording session dialog\n"); fprintf(stderr, "Reason? %s\n", osstrerror()); if (fd != -1) close(fd); goto failed; } fputs(p, msgf); fclose(msgf); msgf = NULL; if (cmd == 'X') snprintf(lbuf, sizeof(lbuf), "%s -c -header \"%s - %s\" -file %s -icon question " "-B Yes -b No 2>/dev/null", xconfirm, dialog_title, rsc_prog, msg); else snprintf(lbuf, sizeof(lbuf), "%s -c -header \"%s - %s\" -file %s -icon info " "-b Close 2>/dev/null", xconfirm, dialog_title, rsc_prog, msg); if ((msgf = popen(lbuf, "r")) == NULL) { fprintf(stderr, "\nError: failed to start command for recording session dialog\n"); fprintf(stderr, "Command: \"%s\"\n", lbuf); goto failed; } if (fgets(lbuf, sizeof(lbuf), msgf) == NULL) { fprintf(stderr, "\n%s: pmconfirm(1) failed for recording session dialog\n", cmd == '?' ? "Warning" : "Error"); failed: fprintf(stderr, "Dialog:\n"); fputs(p, stderr); strcpy(lbuf, "Yes"); } else { /* strip at first newline */ for (q = lbuf; *q && *q != '\n'; q++) ; *q = '\0'; } if (msgf != NULL) pclose(msgf); unlink(msg); } else { fprintf(stderr, "Error: failed to create recording session dialog message!\n"); fprintf(stderr, "Reason? %s\n", osstrerror()); strcpy(lbuf, "Yes"); } free(p); if (cmd == 'Q' || (cmd == 'X' && strcmp(lbuf, "Yes") == 0)) { run_done(0, "Recording session terminated"); /*NOTREACHED*/ } if (cmd != '?') { /* detach, silently go off to the races ... */ close(rsc_fd); __pmFD_CLR(rsc_fd, &fds); rsc_fd = -1; } }
static void _b(void) { int i; int j; int inst; int sts; char cmd[2*MAXPATHLEN+30]; indom = pmInDom_build(FORQA, 8); pmsprintf(cmd, sizeof(cmd), "rm -f %s/config/pmda/%s", pmGetConfig("PCP_VAR_DIR"), pmInDomStr(indom)); sts = system(cmd); if (sts != 0) fprintf(stderr, "Warning: %s: exit status %d\n", cmd, sts); pmsprintf(cmd, sizeof(cmd), "[ -f %s/config/pmda/%s ] || exit 0; cat %s/config/pmda/%s", pmGetConfig("PCP_VAR_DIR"), pmInDomStr(indom), pmGetConfig("PCP_VAR_DIR"), pmInDomStr(indom)); fprintf(stderr, "\nPopulate the instance domain ...\n"); j = 1; for (i = 0; i < 20; i++) { strncpy(nbuf, xxx, ncount+3); pmsprintf(nbuf, sizeof(nbuf), "%03d", ncount); ncount++; inst = pmdaCacheStore(indom, PMDA_CACHE_ADD, nbuf, (void *)((__psint_t)(0xbeef0000+ncount))); if (inst < 0) fprintf(stderr, "PMDA_CACHE_ADD failed for \"%s\": %s\n", nbuf, pmErrStr(inst)); else if (i > 14) { sts = pmdaCacheOp(indom, PMDA_CACHE_SAVE); fprintf(stderr, "Save -> %d\n", sts); } if (i == j) { j <<= 1; inst = pmdaCacheStore(indom, PMDA_CACHE_HIDE, nbuf, NULL); if (inst < 0) fprintf(stderr, "PMDA_CACHE_HIDE failed for \"%s\": %s\n", nbuf, pmErrStr(inst)); } if (i == 6 || i == 13) { fprintf(stderr, "Save ...\n"); fprintf(stderr, "Before:\n"); sts = system(cmd); if (sts != 0) fprintf(stderr, "Warning: _b:1: %s: exit status %d\n", cmd, sts); sts = pmdaCacheOp(indom, PMDA_CACHE_SAVE); fprintf(stderr, "return -> %d", sts); if (sts < 0) fprintf(stderr, ": %s", pmErrStr(sts)); fputc('\n', stderr); fprintf(stderr, "After:\n"); sts = system(cmd); if (sts != 0) fprintf(stderr, "Warning: _b:2: %s: exit status %d\n", cmd, sts); } if (i == 14) { fprintf(stderr, "Start save after changes ...\n"); } if (i > 14) { sts = system(cmd); if (sts != 0) fprintf(stderr, "Warning: _b:3: %s: exit status %d\n", cmd, sts); } } __pmdaCacheDump(stderr, indom, 0); strncpy(nbuf, xxx, 11+3); pmsprintf(nbuf, sizeof(nbuf), "%03d", 11); fprintf(stderr, "\nHide %s ...\n", nbuf); inst = pmdaCacheStore(indom, PMDA_CACHE_HIDE, nbuf, NULL); if (inst < 0) fprintf(stderr, "PMDA_CACHE_HIDE failed for \"%s\": %s\n", nbuf, pmErrStr(inst)); sts = pmdaCacheOp(indom, PMDA_CACHE_SAVE); fprintf(stderr, "Save -> %d\n", sts); sts = system(cmd); if (sts != 0) fprintf(stderr, "Warning: _b:4: %s: exit status %d\n", cmd, sts); fprintf(stderr, "Add %s ...\n", nbuf); inst = pmdaCacheStore(indom, PMDA_CACHE_ADD, nbuf, (void *)((__psint_t)0xdeadbeef)); if (inst < 0) fprintf(stderr, "PMDA_CACHE_ADD failed for \"%s\": %s\n", nbuf, pmErrStr(inst)); sts = pmdaCacheOp(indom, PMDA_CACHE_SAVE); fprintf(stderr, "Save -> %d\n", sts); sts = system(cmd); if (sts != 0) fprintf(stderr, "Warning: _b:5: %s: exit status %d\n", cmd, sts); fprintf(stderr, "Cull %s ...\n", nbuf); inst = pmdaCacheStore(indom, PMDA_CACHE_CULL, nbuf, NULL); if (inst < 0) fprintf(stderr, "PMDA_CACHE_CULL failed for \"%s\": %s\n", nbuf, pmErrStr(inst)); sts = pmdaCacheOp(indom, PMDA_CACHE_SAVE); fprintf(stderr, "Save -> %d\n", sts); sts = system(cmd); if (sts != 0) fprintf(stderr, "Warning: _b:6: %s: exit status %d\n", cmd, sts); fprintf(stderr, "Add %s ...\n", nbuf); inst = pmdaCacheStore(indom, PMDA_CACHE_ADD, nbuf, (void *)((__psint_t)0xdeadbeef)); if (inst < 0) fprintf(stderr, "PMDA_CACHE_ADD failed for \"%s\": %s\n", nbuf, pmErrStr(inst)); sts = pmdaCacheOp(indom, PMDA_CACHE_SAVE); fprintf(stderr, "Save -> %d\n", sts); sts = system(cmd); if (sts != 0) fprintf(stderr, "Warning: _b:7: %s: exit status %d\n", cmd, sts); }
static int build_dsotab(void) { /* * parse pmcd's config file extracting details from dso lines * * very little syntactic checking here ... pmcd(1) does that job * nicely and even if we get confused, the worst thing that happens * is we don't include one or more of the DSO PMDAs in dsotab[] * * lines for DSO PMDAs generally look like this ... * Name Domain Type Init Routine Path * mmv 70 dso mmv_init /var/lib/pcp/pmdas/mmv/pmda_mmv.so * */ char configFileName[MAXPATHLEN]; FILE *configFile; char *config; char *p; char *q; struct stat sbuf; int lineno = 1; int domain; char *init; char *name; char peekc; numdso = 0; dsotab = NULL; strcpy(configFileName, pmGetConfig("PCP_PMCDCONF_PATH")); #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_CONTEXT) { fprintf(stderr, "build_dsotab: parsing %s\n", configFileName); } #endif if (stat(configFileName, &sbuf) < 0) { return -oserror(); } configFile = fopen(configFileName, "r"); if (configFile == NULL) { return -oserror(); } if ((config = malloc(sbuf.st_size+1)) == NULL) { __pmNoMem("build_dsotbl:", sbuf.st_size+1, PM_RECOV_ERR); fclose(configFile); return -oserror(); } if (fread(config, 1, sbuf.st_size, configFile) != sbuf.st_size) { fclose(configFile); free(config); return -oserror(); } config[sbuf.st_size] = '\0'; p = config; while (*p != '\0') { /* each time through here we're at the start of a new line */ if (*p == '#') goto eatline; if (strncmp(p, "pmcd", 4) == 0) { /* * the pmcd PMDA is an exception ... it makes reference to * symbols in pmcd, and only makes sense when attached to the * pmcd process, so we skip this one */ goto eatline; } /* skip the PMDA's name */ while (*p != '\0' && *p != '\n' && !isspace((int)*p)) p++; while (*p != '\0' && *p != '\n' && isspace((int)*p)) p++; /* extract domain number */ domain = (int)strtol(p, &q, 10); p = q; while (*p != '\0' && *p != '\n' && isspace((int)*p)) p++; /* only interested if the type is "dso" */ if (strncmp(p, "dso", 3) != 0) goto eatline; p += 3; while (*p != '\0' && *p != '\n' && isspace((int)*p)) p++; /* up to the init routine name */ init = p; while (*p != '\0' && *p != '\n' && !isspace((int)*p)) p++; *p = '\0'; p++; while (*p != '\0' && *p != '\n' && isspace((int)*p)) p++; /* up to the dso pathname */ name = p; while (*p != '\0' && *p != '\n' && !isspace((int)*p)) p++; peekc = *p; *p = '\0'; #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_CONTEXT) { fprintf(stderr, "[%d] domain=%d, name=%s, init=%s\n", lineno, domain, name, init); } #endif /* * a little bit recursive if we got here via __pmLocalPMDA(), * but numdso has been set correctly, so this is OK */ __pmLocalPMDA(PM_LOCAL_ADD, domain, name, init); *p = peekc; eatline: while (*p != '\0' && *p != '\n') p++; if (*p == '\n') { lineno++; p++; } } fclose(configFile); free(config); return 0; }
int main(int argc, char **argv) { static char helppath[MAXPATHLEN]; char *endnum; pmdaInterface desc; long minmem; int c, err = 0, sep = __pmPathSeparator(); __pmSetProgname(argv[0]); __pmGetUsername(&username); minmem = getpagesize(); maxmem = (minmem > DEFAULT_MAXMEM) ? minmem : DEFAULT_MAXMEM; snprintf(helppath, sizeof(helppath), "%s%c" "logger" "%c" "help", pmGetConfig("PCP_PMDAS_DIR"), sep, sep); pmdaDaemon(&desc, PMDA_INTERFACE_5, pmProgname, LOGGER, "logger.log", helppath); while ((c = pmdaGetOpt(argc, argv, "D:d:l:m:s:U:?", &desc, &err)) != EOF) { switch (c) { case 'm': maxmem = strtol(optarg, &endnum, 10); if (*endnum != '\0') convertUnits(&endnum, &maxmem); if (*endnum != '\0' || maxmem < minmem) { fprintf(stderr, "%s: invalid max memory '%s' (min=%ld)\n", pmProgname, optarg, minmem); err++; } break; case 's': if (pmParseInterval(optarg, &interval, &endnum) < 0) { fprintf(stderr, "%s: -s requires a time interval: %s\n", pmProgname, endnum); free(endnum); err++; } break; case 'U': username = optarg; break; default: err++; break; } } if (err || optind != argc -1) usage(); pmdaOpenLog(&desc); logger_init(&desc, argv[optind]); pmdaConnect(&desc); loggerMain(&desc); event_shutdown(); exit(0); }
int main(int argc, char **argv) { int c; int sflag = 0; while ((c = pmgetopt_r(argc, argv, &opts)) != EOF) { switch (c) { case 'a': /* show all, default (unmodified) list format */ case 'l': sflag = 0; break; case 's': /* show all, guarded format for shell expansion */ sflag = 1; break; case 'L': apiflag = 1; break; default: opts.errors++; break; } } if (opts.errors) { pmUsageMessage(&opts); exit(1); } if (sflag) { putenv("SHELL=/bin/sh"); empty = none; } /* the complete list of variables is to be reported */ if (opts.optind >= argc) { if (apiflag) __pmAPIConfig(sflag ? export_report : direct_report); else __pmConfig(sflag ? pcp_conf_shell_extract : pcp_conf_extract); exit(0); } /* an explicit list of variables has been requested */ if (sflag) { if (apiflag) for (c = opts.optind; c < argc; c++) export_report(argv[c], __pmGetAPIConfig(argv[c])); else for (c = opts.optind; c < argc; c++) export_report(argv[c], pmGetConfig(argv[c])); } else { if (apiflag) for (c = opts.optind; c < argc; c++) direct_report(argv[c], __pmGetAPIConfig(argv[c])); else for (c = opts.optind; c < argc; c++) direct_report(argv[c], pmGetConfig(argv[c])); } exit(0); }
int main(int argc, char **argv) { int c; int sts; int sep = __pmPathSeparator(); int use_localtime = 0; int isdaemon = 0; char *pmnsfile = PM_NS_DEFAULT; char *username; char *logfile = "pmlogger.log"; /* default log (not archive) file name */ char *endnum; int i; task_t *tp; optcost_t ocp; __pmFdSet readyfds; char *p; char *runtime = NULL; int ctx; /* handle corresponding to ctxp below */ __pmContext *ctxp; /* pmlogger has just this one context */ int niter; pid_t target_pid = 0; __pmGetUsername(&username); /* * Warning: * If any of the pmlogger options change, make sure the * corresponding changes are made to pmnewlog when pmlogger * options are passed through from the control file */ while ((c = pmgetopt_r(argc, argv, &opts)) != EOF) { switch (c) { case 'c': /* config file */ if (access(opts.optarg, F_OK) == 0) configfile = opts.optarg; else { /* does not exist as given, try the standard place */ char *sysconf = pmGetConfig("PCP_VAR_DIR"); int sz = strlen(sysconf)+strlen("/config/pmlogger/")+strlen(opts.optarg)+1; if ((configfile = (char *)malloc(sz)) == NULL) __pmNoMem("config file name", sz, PM_FATAL_ERR); snprintf(configfile, sz, "%s%c" "config%c" "pmlogger%c" "%s", sysconf, sep, sep, sep, opts.optarg); if (access(configfile, F_OK) != 0) { /* still no good, error handling happens below */ free(configfile); configfile = opts.optarg; } } break; case 'D': /* debug flag */ sts = __pmParseDebug(opts.optarg); if (sts < 0) { pmprintf("%s: unrecognized debug flag specification (%s)\n", pmProgname, opts.optarg); opts.errors++; } else pmDebug |= sts; break; case 'h': /* hostname for PMCD to contact */ pmcd_host_conn = opts.optarg; break; case 'l': /* log file name */ logfile = opts.optarg; break; case 'L': /* linger if not primary logger */ linger = 1; break; case 'm': /* note for port map file */ note = opts.optarg; isdaemon = ((strcmp(note, "pmlogger_check") == 0) || (strcmp(note, "pmlogger_daily") == 0)); break; case 'n': /* alternative name space file */ pmnsfile = opts.optarg; break; case 'p': target_pid = (int)strtol(opts.optarg, &endnum, 10); if (*endnum != '\0') { pmprintf("%s: invalid process identifier (%s)\n", pmProgname, opts.optarg); opts.errors++; } else if (!__pmProcessExists(target_pid)) { pmprintf("%s: PID error - no such process (%d)\n", pmProgname, target_pid); opts.errors++; } break; case 'P': /* this is the primary pmlogger */ primary = 1; isdaemon = 1; break; case 'r': /* report sizes of pmResult records */ rflag = 1; break; case 's': /* exit size */ sts = ParseSize(opts.optarg, &exit_samples, &exit_bytes, &exit_time); if (sts < 0) { pmprintf("%s: illegal size argument '%s' for exit size\n", pmProgname, opts.optarg); opts.errors++; } else if (exit_time.tv_sec > 0) { __pmAFregister(&exit_time, NULL, run_done_callback); } break; case 'T': /* end time */ runtime = opts.optarg; break; case 't': /* change default logging interval */ if (pmParseInterval(opts.optarg, &delta, &p) < 0) { pmprintf("%s: illegal -t argument\n%s", pmProgname, p); free(p); opts.errors++; } break; case 'U': /* run as named user */ username = opts.optarg; isdaemon = 1; break; case 'u': /* flush output buffers after each fetch */ /* * all archive write I/O is unbuffered now, so maintain -u * for backwards compatibility only */ break; case 'v': /* volume switch after given size */ sts = ParseSize(opts.optarg, &vol_switch_samples, &vol_switch_bytes, &vol_switch_time); if (sts < 0) { pmprintf("%s: illegal size argument '%s' for volume size\n", pmProgname, opts.optarg); opts.errors++; } else if (vol_switch_time.tv_sec > 0) { vol_switch_afid = __pmAFregister(&vol_switch_time, NULL, vol_switch_callback); } break; case 'V': archive_version = (int)strtol(opts.optarg, &endnum, 10); if (*endnum != '\0' || archive_version != PM_LOG_VERS02) { pmprintf("%s: -V requires a version number of %d\n", pmProgname, PM_LOG_VERS02); opts.errors++; } break; case 'x': /* recording session control fd */ rsc_fd = (int)strtol(opts.optarg, &endnum, 10); if (*endnum != '\0' || rsc_fd < 0) { pmprintf("%s: -x requires a non-negative numeric argument\n", pmProgname); opts.errors++; } else { time(&rsc_start); } break; case 'y': use_localtime = 1; break; case '?': default: opts.errors++; break; } } if (primary && pmcd_host != NULL) { pmprintf( "%s: -P and -h are mutually exclusive; use -P only when running\n" "%s on the same (local) host as the PMCD to which it connects.\n", pmProgname, pmProgname); opts.errors++; } if (!opts.errors && opts.optind != argc - 1) { pmprintf("%s: insufficient arguments\n", pmProgname); opts.errors++; } if (opts.errors) { pmUsageMessage(&opts); exit(1); } if (rsc_fd != -1 && note == NULL) { /* add default note to indicate running with -x */ static char xnote[10]; snprintf(xnote, sizeof(xnote), "-x %d", rsc_fd); note = xnote; } /* if we are running as a daemon, change user early */ if (isdaemon) __pmSetProcessIdentity(username); __pmOpenLog("pmlogger", logfile, stderr, &sts); if (sts != 1) { fprintf(stderr, "%s: Warning: log file (%s) creation failed\n", pmProgname, logfile); /* continue on ... writing to stderr */ } /* base name for archive is here ... */ archBase = argv[opts.optind]; if (pmcd_host_conn == NULL) pmcd_host_conn = "local:"; /* initialise access control */ if (__pmAccAddOp(PM_OP_LOG_ADV) < 0 || __pmAccAddOp(PM_OP_LOG_MAND) < 0 || __pmAccAddOp(PM_OP_LOG_ENQ) < 0) { fprintf(stderr, "%s: access control initialisation failed\n", pmProgname); exit(1); } if (pmnsfile != PM_NS_DEFAULT) { if ((sts = pmLoadASCIINameSpace(pmnsfile, 1)) < 0) { fprintf(stderr, "%s: Cannot load namespace from \"%s\": %s\n", pmProgname, pmnsfile, pmErrStr(sts)); exit(1); } } if ((ctx = pmNewContext(PM_CONTEXT_HOST, pmcd_host_conn)) < 0) { fprintf(stderr, "%s: Cannot connect to PMCD on host \"%s\": %s\n", pmProgname, pmcd_host_conn, pmErrStr(ctx)); exit(1); } pmcd_host = (char *)pmGetContextHostName(ctx); if (strlen(pmcd_host) == 0) { fprintf(stderr, "%s: pmGetContextHostName(%d) failed\n", pmProgname, ctx); exit(1); } if (rsc_fd == -1) { /* no -x, so register client id with pmcd */ __pmSetClientIdArgv(argc, argv); } /* * discover fd for comms channel to PMCD ... */ if ((ctxp = __pmHandleToPtr(ctx)) == NULL) { fprintf(stderr, "%s: botch: __pmHandleToPtr(%d) returns NULL!\n", pmProgname, ctx); exit(1); } pmcdfd = ctxp->c_pmcd->pc_fd; PM_UNLOCK(ctxp->c_lock); if (configfile != NULL) { if ((yyin = fopen(configfile, "r")) == NULL) { fprintf(stderr, "%s: Cannot open config file \"%s\": %s\n", pmProgname, configfile, osstrerror()); exit(1); } } else { /* **ANY** Lex would read from stdin automagically */ configfile = "<stdin>"; } __pmOptFetchGetParams(&ocp); ocp.c_scope = 1; __pmOptFetchPutParams(&ocp); /* prevent early timer events ... */ __pmAFblock(); if (yyparse() != 0) exit(1); if (configfile != NULL) fclose(yyin); yyend(); #ifdef PCP_DEBUG fprintf(stderr, "Config parsed\n"); #endif fprintf(stderr, "Starting %slogger for host \"%s\" via \"%s\"\n", primary ? "primary " : "", pmcd_host, pmcd_host_conn); #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_LOG) { fprintf(stderr, "optFetch Cost Parameters: pmid=%d indom=%d fetch=%d scope=%d\n", ocp.c_pmid, ocp.c_indom, ocp.c_fetch, ocp.c_scope); fprintf(stderr, "\nAfter loading config ...\n"); for (tp = tasklist; tp != NULL; tp = tp->t_next) { if (tp->t_numvalid == 0) continue; fprintf(stderr, " state: %sin log, %savail, %s, %s", PMLC_GET_INLOG(tp->t_state) ? "" : "not ", PMLC_GET_AVAIL(tp->t_state) ? "" : "un", PMLC_GET_MAND(tp->t_state) ? "mand" : "adv", PMLC_GET_ON(tp->t_state) ? "on" : "off"); fprintf(stderr, " delta: %ld usec", (long)1000 * tp->t_delta.tv_sec + tp->t_delta.tv_usec); fprintf(stderr, " numpmid: %d\n", tp->t_numpmid); for (i = 0; i < tp->t_numpmid; i++) { fprintf(stderr, " %s (%s):\n", pmIDStr(tp->t_pmidlist[i]), tp->t_namelist[i]); } __pmOptFetchDump(stderr, tp->t_fetch); } } #endif if (!primary && tasklist == NULL && !linger) { fprintf(stderr, "Nothing to log, and not the primary logger instance ... good-bye\n"); exit(1); } if ((sts = __pmLogCreate(pmcd_host, archBase, archive_version, &logctl)) < 0) { fprintf(stderr, "__pmLogCreate: %s\n", pmErrStr(sts)); exit(1); } else { /* * try and establish $TZ from the remote PMCD ... * Note the label record has been set up, but not written yet */ char *name = "pmcd.timezone"; pmID pmid; pmResult *resp; __pmtimevalNow(&epoch); sts = pmUseContext(ctx); if (sts >= 0) sts = pmLookupName(1, &name, &pmid); if (sts >= 0) sts = pmFetch(1, &pmid, &resp); if (sts >= 0) { if (resp->vset[0]->numval > 0) { /* pmcd.timezone present */ strcpy(logctl.l_label.ill_tz, resp->vset[0]->vlist[0].value.pval->vbuf); /* prefer to use remote time to avoid clock drift problems */ epoch = resp->timestamp; /* struct assignment */ if (! use_localtime) pmNewZone(logctl.l_label.ill_tz); } #ifdef PCP_DEBUG else if (pmDebug & DBG_TRACE_LOG) { fprintf(stderr, "main: Could not get timezone from host %s\n", pmcd_host); } #endif pmFreeResult(resp); } } /* do ParseTimeWindow stuff for -T */ if (runtime) { struct timeval res_end; /* time window end */ struct timeval start; struct timeval end; struct timeval last_delta; char *err_msg; /* parsing error message */ time_t now; struct timeval now_tv; time(&now); now_tv.tv_sec = now; now_tv.tv_usec = 0; start = now_tv; end.tv_sec = INT_MAX; end.tv_usec = INT_MAX; sts = __pmParseTime(runtime, &start, &end, &res_end, &err_msg); if (sts < 0) { fprintf(stderr, "%s: illegal -T argument\n%s", pmProgname, err_msg); exit(1); } last_delta = res_end; tsub(&last_delta, &now_tv); __pmAFregister(&last_delta, NULL, run_done_callback); last_stamp = res_end; } fprintf(stderr, "Archive basename: %s\n", archBase); #ifndef IS_MINGW /* detach yourself from the launching process */ if (isdaemon) setpgid(getpid(), 0); #endif /* set up control port */ init_ports(); __pmFD_ZERO(&fds); for (i = 0; i < CFD_NUM; ++i) { if (ctlfds[i] >= 0) __pmFD_SET(ctlfds[i], &fds); } #ifndef IS_MINGW __pmFD_SET(pmcdfd, &fds); #endif if (rsc_fd != -1) __pmFD_SET(rsc_fd, &fds); numfds = maxfd() + 1; if ((sts = do_preamble()) < 0) fprintf(stderr, "Warning: problem writing archive preamble: %s\n", pmErrStr(sts)); sts = 0; /* default exit status */ parse_done = 1; /* enable callback processing */ __pmAFunblock(); for ( ; ; ) { int nready; #ifdef PCP_DEBUG if ((pmDebug & DBG_TRACE_APPL2) && (pmDebug & DBG_TRACE_DESPERATE)) { fprintf(stderr, "before __pmSelectRead(%d,...): run_done_alarm=%d vol_switch_alarm=%d log_alarm=%d\n", numfds, run_done_alarm, vol_switch_alarm, log_alarm); } #endif niter = 0; while (log_alarm && niter++ < 10) { __pmAFblock(); log_alarm = 0; #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL2) fprintf(stderr, "delayed callback: log_alarm\n"); #endif for (tp = tasklist; tp != NULL; tp = tp->t_next) { if (tp->t_alarm) { tp->t_alarm = 0; do_work(tp); } } __pmAFunblock(); } if (vol_switch_alarm) { __pmAFblock(); vol_switch_alarm = 0; #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL2) fprintf(stderr, "delayed callback: vol_switch_alarm\n"); #endif newvolume(VOL_SW_TIME); __pmAFunblock(); } if (run_done_alarm) { #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL2) fprintf(stderr, "delayed callback: run_done_alarm\n"); #endif run_done(0, NULL); /*NOTREACHED*/ } __pmFD_COPY(&readyfds, &fds); nready = __pmSelectRead(numfds, &readyfds, NULL); #ifdef PCP_DEBUG if ((pmDebug & DBG_TRACE_APPL2) && (pmDebug & DBG_TRACE_DESPERATE)) { fprintf(stderr, "__pmSelectRead(%d,...) done: nready=%d run_done_alarm=%d vol_switch_alarm=%d log_alarm=%d\n", numfds, nready, run_done_alarm, vol_switch_alarm, log_alarm); } #endif __pmAFblock(); if (nready > 0) { /* handle request on control port */ for (i = 0; i < CFD_NUM; ++i) { if (ctlfds[i] >= 0 && __pmFD_ISSET(ctlfds[i], &readyfds)) { if (control_req(ctlfds[i])) { /* new client has connected */ __pmFD_SET(clientfd, &fds); if (clientfd >= numfds) numfds = clientfd + 1; } } } if (clientfd >= 0 && __pmFD_ISSET(clientfd, &readyfds)) { /* process request from client, save clientfd in case client * closes connection, resetting clientfd to -1 */ int fd = clientfd; if (client_req()) { /* client closed connection */ __pmFD_CLR(fd, &fds); __pmCloseSocket(clientfd); clientfd = -1; numfds = maxfd() + 1; qa_case = 0; } } #ifndef IS_MINGW if (pmcdfd >= 0 && __pmFD_ISSET(pmcdfd, &readyfds)) { /* * do not expect this, given synchronous commumication with the * pmcd ... either pmcd has terminated, or bogus PDU ... or its * Win32 and we are operating under the different conditions of * our AF.c implementation there, which has to deal with a lack * of signal support on Windows - race condition exists between * this check and the async event timer callback. */ __pmPDU *pb; __pmPDUHdr *php; sts = __pmGetPDU(pmcdfd, ANY_SIZE, TIMEOUT_NEVER, &pb); if (sts <= 0) { if (sts < 0) fprintf(stderr, "Error: __pmGetPDU: %s\n", pmErrStr(sts)); disconnect(sts); } else { php = (__pmPDUHdr *)pb; fprintf(stderr, "Error: Unsolicited %s PDU from PMCD\n", __pmPDUTypeStr(php->type)); disconnect(PM_ERR_IPC); } if (sts > 0) __pmUnpinPDUBuf(pb); } #endif if (rsc_fd >= 0 && __pmFD_ISSET(rsc_fd, &readyfds)) { /* * some action on the recording session control fd * end-of-file means launcher has quit, otherwise we * expect one of these commands * V<number>\n - version * F<folio>\n - folio name * P<name>\n - launcher's name * R\n - launcher can replay * D\n - detach from launcher * Q\n - quit pmlogger */ char rsc_buf[MAXPATHLEN]; char *rp = rsc_buf; char myc; int fake_x = 0; for (rp = rsc_buf; ; rp++) { if (read(rsc_fd, &myc, 1) <= 0) { #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL2) fprintf(stderr, "recording session control: eof\n"); #endif if (rp != rsc_buf) { *rp = '\0'; fprintf(stderr, "Error: incomplete recording session control message: \"%s\"\n", rsc_buf); } fake_x = 1; break; } if (rp >= &rsc_buf[MAXPATHLEN]) { fprintf(stderr, "Error: absurd recording session control message: \"%100.100s ...\"\n", rsc_buf); fake_x = 1; break; } if (myc == '\n') { *rp = '\0'; break; } *rp = myc; } #ifdef PCP_DEBUG if (pmDebug & DBG_TRACE_APPL2) { if (fake_x == 0) fprintf(stderr, "recording session control: \"%s\"\n", rsc_buf); } #endif if (fake_x) do_dialog('X'); else if (strcmp(rsc_buf, "Q") == 0 || strcmp(rsc_buf, "D") == 0 || strcmp(rsc_buf, "?") == 0) do_dialog(rsc_buf[0]); else if (rsc_buf[0] == 'F') folio_name = strdup(&rsc_buf[1]); else if (rsc_buf[0] == 'P') rsc_prog = strdup(&rsc_buf[1]); else if (strcmp(rsc_buf, "R") == 0) rsc_replay = 1; else if (rsc_buf[0] == 'V' && rsc_buf[1] == '0') { /* * version 0 of the recording session control ... * this is all we grok at the moment */ ; } else { fprintf(stderr, "Error: illegal recording session control message: \"%s\"\n", rsc_buf); do_dialog('X'); } } } else if (vol_switch_flag) { newvolume(VOL_SW_SIGHUP); vol_switch_flag = 0; } else if (nready < 0 && neterror() != EINTR) fprintf(stderr, "Error: select: %s\n", netstrerror()); __pmAFunblock(); if (target_pid && !__pmProcessExists(target_pid)) exit(EXIT_SUCCESS); if (exit_code) break; } exit(exit_code); }