void psc_subsys_register(int ssid, const char *name) { struct psc_subsys *ss; char *p, buf[BUFSIZ]; int nss; nss = psc_dynarray_len(&psc_subsystems); ss = psc_alloc(sizeof(*ss), PAF_NOLOG); ss->pss_name = name; snprintf(buf, sizeof(buf), "PSC_LOG_LEVEL_%s", name); p = getenv(buf); if (p) { ss->pss_loglevel = psc_loglevel_fromstr(p); if (ss->pss_loglevel == PNLOGLEVELS) psc_fatalx("invalid %s value", name); } else { ss->pss_loglevel = psc_log_getlevel_global(); if (ssid == PSS_TMP) ss->pss_loglevel = PLL_DEBUG; } snprintf(buf, sizeof(buf), "PSC_SYSLOG_%s", name); if (getenv(buf) || getenv("PSC_SYSLOG")) { static int init; if (!init) { extern const char *__progname; const char *ident = __progname; init = 1; p = getenv("PFL_SYSLOG_IDENT"); if (p) { static char idbuf[32]; ident = idbuf; (void)FMTSTR(idbuf, sizeof(idbuf), p, FMTSTRCASE('n', "s", __progname) ); } openlog(ident, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON); } pfl_syslog = psc_realloc(pfl_syslog, sizeof(*pfl_syslog) * (nss + 1), PAF_NOLOG); pfl_syslog[nss] = 1; } if (ssid != nss) psc_fatalx("bad ID %d for subsys %s [want %d], " "check order", ssid, name, nss); psc_dynarray_add(&psc_subsystems, ss); }
void visit(__unusedx void *data, int64_t item, void *arg) { char buf[LINE_MAX], *p = data; struct pfl_odt **t = arg; static int dump_hdr; union { int *d; int64_t *q; void *p; } u; size_t i; if (!dump) return; if (!dump_hdr) { struct pfl_odt_hdr *h; h = (*t)->odt_hdr; printf("nitems\t%u\n", h->odth_nitems); printf("itemsz\t%u\n", h->odth_itemsz); printf("%7s %16s data\n", "slot", "crc"); dump_hdr = 1; } printf("item: %7"PRId64, item); if (fmt) { (void)FMTSTR(buf, sizeof(buf), fmt, FMTSTRCASE('d', "d", (u.p = p, p += sizeof(int), *u.d)) FMTSTRCASE('u', "u", (u.p = p, p += sizeof(int), *u.d)) FMTSTRCASE('x', "x", (u.p = p, p += sizeof(int), *u.d)) FMTSTRCASE('q', PRId64, (u.p = p, p += sizeof(int64_t), *u.q)) FMTSTRCASE('Q', PRIu64, (u.p = p, p += sizeof(int64_t), *u.q)) FMTSTRCASE('X', PRIx64, (u.p = p, p += sizeof(int64_t), *u.q)) ); printf("%s\n", buf); return; } /* * If the first 10 characters aren't ASCII, don't display as * such. */ for (i = 0, p = data; i < 10 && p; i++, p++) if (!isspace(*p) && !isgraph(*p)) goto skip; if (i != 10) goto skip; printf("%s\n", (char *)data); return; skip: for (i = 0, p = data; i < item_size; p++, i++) printf("%02x", *p); printf("\n"); }
void child_main(__unusedx struct psc_thread *thr) { char buf[40]; int i; /* * Wait here until the parent signals us to start */ psc_waitq_wait(&waitq, NULL); psclog_debug("after pseudo barrier"); /* Connect to control socket. */ (void)FMTSTR(buf, sizeof(buf), "foobar%h", FMTSTRCASE('h', "s", "test") ); for (i = 0; i < iterations; i++) { psc_waitq_wait(&waitq, NULL); psclog_debug("i=%d awake", i); } }
void visit(__unusedx void *data, struct pfl_odt_receipt *r, void *arg) { char buf[LINE_MAX], *p = data; struct pfl_odt **t = arg; static int shown_hdr; union { int *d; int64_t *q; void *p; } u; size_t i; if (num_free) { struct pfl_odt_receipt *rdup; rdup = PSCALLOC(sizeof(*rdup)); memcpy(rdup, r, sizeof(*r)); psc_dynarray_add(&rcpts, rdup); num_free--; } if (!show) return; if (!shown_hdr) { struct pfl_odt_hdr *h; h = (*t)->odt_hdr; printf("nelems\t%u\n", h->odth_nelems); printf("elemsz\t%u\n", h->odth_objsz); printf("%7s %16s data\n", "slot", "crc"); shown_hdr = 1; } printf("%7zd %16"PRIx64" ", r->odtr_elem, r->odtr_crc); if (fmt) { (void)FMTSTR(buf, sizeof(buf), fmt, FMTSTRCASE('d', "d", (u.p = p, p += sizeof(int), *u.d)) FMTSTRCASE('u', "u", (u.p = p, p += sizeof(int), *u.d)) FMTSTRCASE('x', "x", (u.p = p, p += sizeof(int), *u.d)) FMTSTRCASE('q', PRId64, (u.p = p, p += sizeof(int64_t), *u.q)) FMTSTRCASE('Q', PRIu64, (u.p = p, p += sizeof(int64_t), *u.q)) FMTSTRCASE('X', PRIx64, (u.p = p, p += sizeof(int64_t), *u.q)) ); printf("%s\n", buf); return; } /* * If the first 10 characters aren't ASCII, don't display as * such. */ for (i = 0, p = data; i < 10 && p; i++, p++) if (!isspace(*p) && !isgraph(*p)) goto skip; if (i != 10) goto skip; printf("%s\n", (char *)data); return; skip: for (i = 0, p = data; i < elem_size; p++, i++) printf("%02x", *p); printf("\n"); }