RPM Package Manager, CVS Repository http://rpm5.org/cvs/ ____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson Root: /v/rpm/cvs Email: j...@rpm5.org Module: rpm Date: 27-May-2017 16:22:18 Branch: rpm-5_4 Handle: 2017052714221701 Modified files: (Branch: rpm-5_4) rpm CHANGES rpm/rpmio msqio.c rpmio.c rpmio.h rpmmalloc.c Log: - rpmio: wire up the fooInit callback, pass the message to fooDbug. Summary: Revision Changes Path 1.3501.2.563+1 -0 rpm/CHANGES 1.1.2.14 +46 -3 rpm/rpmio/msqio.c 1.230.2.52 +15 -1 rpm/rpmio/rpmio.c 1.97.2.20 +1 -1 rpm/rpmio/rpmio.h 1.29.2.7 +49 -24 rpm/rpmio/rpmmalloc.c ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/CHANGES ============================================================================ $ cvs diff -u -r1.3501.2.562 -r1.3501.2.563 CHANGES --- rpm/CHANGES 26 May 2017 20:49:22 -0000 1.3501.2.562 +++ rpm/CHANGES 27 May 2017 14:22:17 -0000 1.3501.2.563 @@ -1,4 +1,5 @@ 5.4.17 -> 5.4.18: + - jbj: rpmio: wire up the fooInit callback, pass the message to fooDbug. - jbj: rpmio: stub in fooDbug and fooInit callbacks for pools. - jbj: msqio: add a monitor to handle multiple readers/writers. - jbj: msqio: add fopencookie wrapper. @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/msqio.c ============================================================================ $ cvs diff -u -r1.1.2.13 -r1.1.2.14 msqio.c --- rpm/rpmio/msqio.c 26 May 2017 20:49:22 -0000 1.1.2.13 +++ rpm/rpmio/msqio.c 27 May 2017 14:22:18 -0000 1.1.2.14 @@ -18,7 +18,6 @@ #endif /* WITH_MQ */ #include "rpmio_internal.h" -#define _RPMLOG_INTERNAL /* XXX ANSI_COLOR* */ #include <rpmlog.h> #include <rpmmacro.h> #include <rpmcb.h> /* XXX rpmIsDebug() */ @@ -394,8 +393,52 @@ } } -#define rpmmsqDbug NULL -#define rpmmsqInit NULL +static char * rpmmsqDbug(void *_msq, char *b, size_t nb) +{ + rpmmsq msq = (rpmmsq) _msq; + size_t len = strlen(b); + char * be = b + len; + + if (msq) { + int colorize = isatty(fileno(stderr)); +#define ANSI_BRIGHT_BLUE "\x1b[34;1m" +#define ANSI_RESET "\x1b[0m" + *be++ = '\n'; + if (colorize) be = stpcpy(be, ANSI_BRIGHT_BLUE); +#define PRINT(_fmt, _foo) \ + { be += sprintf(be, "%19s: %"#_fmt"\n", #_foo, msq->_foo); } + PRINT(s, qname); + PRINT(s, fmode); + PRINT(d, fdno); + PRINT(x, flags); + PRINT(x, qid); + PRINT(x, oflags); + PRINT(0o, omode); + PRINT(x, key); + PRINT(ld, mtype); + PRINT(d, msgmax); + PRINT(d, msgsize); + LOCK(msq->m); + PRINT(d, inflight); + PRINT(d, nsent); + PRINT(d, nrecv); + PRINT(d, ntimeout); + PRINT(d, nagain); + UNLOCK(msq->m); +#undef PRINT + be--; + if (colorize) be = stpcpy(be, ANSI_RESET); + *be = '\0'; + } + return b; +} + +static void rpmmsqInit(void *_msq) +{ + rpmmsq msq = (rpmmsq) _msq; +fprintf(stderr, "<== %s(%p)\n", __FUNCTION__, msq); +} + RPMIOPOOL_MODULE(msq) rpmmsq rpmmsqNew(const char * path, const char * fmode, int fdno, unsigned flags) @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmio.c ============================================================================ $ cvs diff -u -r1.230.2.51 -r1.230.2.52 rpmio.c --- rpm/rpmio/rpmio.c 26 May 2017 13:22:17 -0000 1.230.2.51 +++ rpm/rpmio/rpmio.c 27 May 2017 14:22:18 -0000 1.230.2.52 @@ -321,13 +321,27 @@ rpmioPool _fdPool; +static char * fdDbug(void * _fd, char *b, size_t nb) +{ + FD_t fd = (FD_t) _fd; + size_t len = strlen(b); + char * be = b + len; + *be++ = ' '; + be = stpncpy(be, fdbg(fd), nb-len-1); + return b; +} + +static void fdInit(void * _fd) +{ +} + static FD_t fdGetPool(rpmioPool pool) { FD_t fd; if (_fdPool == NULL) { _fdPool = rpmioNewPool("fd", sizeof(*fd), -1, _rpmio_debug, - (char * (*)(void *))fdbg, NULL, fdFini); + fdDbug, fdInit, fdFini); pool = _fdPool; } fd = (FD_t) rpmioGetPool(pool, sizeof(*fd)); @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmio.h ============================================================================ $ cvs diff -u -r1.97.2.19 -r1.97.2.20 rpmio.h --- rpm/rpmio/rpmio.h 26 May 2017 20:49:23 -0000 1.97.2.19 +++ rpm/rpmio/rpmio.h 27 May 2017 14:22:18 -0000 1.97.2.20 @@ -784,7 +784,7 @@ */ rpmioPool rpmioNewPool(const char * name, size_t size, int limit, int flags, - char * (*dbg) (void *item), + char * (*dbg) (void *item, char *b, size_t nb), void (*init) (void *item), void (*fini) (void *item)); @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmmalloc.c ============================================================================ $ cvs diff -u -r1.29.2.6 -r1.29.2.7 rpmmalloc.c --- rpm/rpmio/rpmmalloc.c 11 May 2017 16:22:08 -0000 1.29.2.6 +++ rpm/rpmio/rpmmalloc.c 27 May 2017 14:22:18 -0000 1.29.2.7 @@ -49,7 +49,7 @@ size_t size; /*!< size of items in this pool */ int limit; /*!< number of new items allowed, or -1 */ int flags; - const char * (*dbg) (void *item); + char * (*dbug) (void *item, char *b, size_t nb); /*!< generate string w Unlink/Link debugging */ void (*init) (void *item); /*!< create item contents. */ void (*fini) (void *item); /*!< destroy item contents. */ @@ -67,7 +67,7 @@ pool = _rpmioPool; _rpmioPool = NULL; } - if (pool != NULL) { + if (pool) { rpmioItem item; int count = 0; yarnPossess(pool->have); @@ -75,7 +75,7 @@ while ((item = pool->head) != NULL) { VALGRIND_HG_CLEAN_MEMORY(item, pool->size); pool->head = (rpmioItem) item->pool; /* XXX pool == next */ - if (item->use != NULL) + if (item->use) item->use = yarnFreeLock(item->use); item = _free(item); count++; @@ -96,7 +96,7 @@ } rpmioPool rpmioNewPool(const char * name, size_t size, int limit, int flags, - char * (*dbg) (void *item), + char * (*dbug) (void *item, char *b, size_t nb), void (*init) (void *item), void (*fini) (void *item)) { @@ -115,7 +115,7 @@ pool->size = size; pool->limit = limit; pool->flags = flags; - pool->dbg = (const char* (*)(void*)) dbg; + pool->dbug = (char * (*)(void *item, char *b, size_t nb)) dbug; pool->init = init; pool->fini = fini; pool->reused = 0; @@ -126,32 +126,46 @@ return pool; } -rpmioItem rpmioUnlinkPoolItem(rpmioItem item, const char * msg, - const char * fn, unsigned ln) +rpmioItem rpmioUnlinkPoolItem(rpmioItem item, + const char * msg, const char * fn, unsigned ln) { rpmioPool pool; if (item == NULL) return NULL; yarnPossess(item->use); ANNOTATE_HAPPENS_AFTER(item); - if ((pool = (rpmioPool) item->pool) != NULL && pool->flags && msg != NULL) { - const char * imsg = (pool->dbg ? (*pool->dbg)((void *)item) : ""); - fprintf(stderr, "--> %s %p -- %ld %s at %s:%u%s\n", pool->name, - item, yarnPeekLock(item->use), msg, fn, ln, imsg); + if ((pool = (rpmioPool) item->pool) != NULL && pool->flags && msg) { + char * imsg; + char b[BUFSIZ]; + size_t nb = sizeof(b); + (void) snprintf(b, nb, "--> %s %p -- %ld %s at %s:%u", pool->name, + item, yarnPeekLock(item->use), msg, fn, ln); + imsg = (pool->dbug ? (*pool->dbug)((void *)item, b, nb) : b); + if (imsg) { + fprintf(stderr, "%s\n", imsg); + if (imsg != b) free(imsg); + } } yarnTwist(item->use, BY, -1); return item; } -rpmioItem rpmioLinkPoolItem(rpmioItem item, const char * msg, - const char * fn, unsigned ln) +rpmioItem rpmioLinkPoolItem(rpmioItem item, + const char * msg, const char * fn, unsigned ln) { rpmioPool pool; if (item == NULL) return NULL; yarnPossess(item->use); if ((pool = (rpmioPool) item->pool) != NULL && pool->flags && msg != NULL) { - const char * imsg = (pool->dbg ? (*pool->dbg)((void *)item) : ""); - fprintf(stderr, "--> %s %p ++ %ld %s at %s:%u%s\n", pool->name, - item, yarnPeekLock(item->use)+1, msg, fn, ln, imsg); + char * imsg; + char b[BUFSIZ]; + size_t nb = sizeof(b); + (void) snprintf(b, nb, "--> %s %p ++ %ld %s at %s:%u", pool->name, + item, yarnPeekLock(item->use)+1, msg, fn, ln); + imsg = (pool->dbug ? (*pool->dbug)((void *)item, b, nb) : b); + if (imsg) { + fprintf(stderr, "%s\n", imsg); + if (imsg != b) free(imsg); + } } ANNOTATE_HAPPENS_BEFORE(item); yarnTwist(item->use, BY, 1); @@ -170,13 +184,20 @@ yarnPossess(item->use); ANNOTATE_HAPPENS_AFTER(item); if ((pool = (rpmioPool) item->pool) != NULL && pool->flags && msg != NULL) { - const char * imsg = (pool->dbg ? (*pool->dbg)((void *)item) : ""); - fprintf(stderr, "--> %s %p -- %ld %s at %s:%u%s\n", pool->name, - item, yarnPeekLock(item->use), msg, fn, ln, imsg); + char * imsg; + char b[BUFSIZ]; + size_t nb = sizeof(b); + (void) snprintf(b, nb, "--> %s %p -- %ld %s at %s:%u", pool->name, + item, yarnPeekLock(item->use), msg, fn, ln); + imsg = (pool->dbug ? (*pool->dbug)((void *)item, b, nb) : b); + if (imsg) { + fprintf(stderr, "%s\n", imsg); + if (imsg != b) free(imsg); + } } if (yarnPeekLock(item->use) <= 1L) { VALGRIND_HG_CLEAN_MEMORY(item, pool->size); - if (pool != NULL && pool->fini != NULL) + if (pool->fini) (*pool->fini) ((void *)item); VALGRIND_MEMPOOL_FREE(pool, item + 1); item = rpmioPutPool(item); @@ -189,14 +210,14 @@ { rpmioItem item; - if (pool != NULL) { + if (pool) { /* if can't create any more, wait for a space to show up */ yarnPossess(pool->have); if (pool->limit == 0) yarnWaitFor(pool->have, NOT_TO_BE, 0); /* if a space is available, pull it from the list and return it */ - if (pool->head != NULL) { + if (pool->head) { item = pool->head; pool->head = (rpmioItem) item->pool; /* XXX pool == next */ if (pool->head == NULL) @@ -207,6 +228,8 @@ VALGRIND_MEMPOOL_ALLOC(pool, item + 1, size - sizeof(struct rpmioItem_s)); + if (pool->init) + (*pool->init) ((void *)item); return item; } @@ -224,6 +247,8 @@ VALGRIND_MEMPOOL_ALLOC(pool, item + 1, size - sizeof(struct rpmioItem_s)); + if (pool->init) + (*pool->init) ((void *)item); return item; } @@ -237,12 +262,12 @@ *pool->tail = item; pool->tail = (rpmioItem *)&item->pool;/* XXX pool == next */ yarnTwist(pool->have, BY, 1); - if (item->use != NULL) + if (item->use) yarnTwist(item->use, TO, 0); return NULL; } - if (item->use != NULL) { + if (item->use) { yarnTwist(item->use, TO, 0); item->use = yarnFreeLock(item->use); } @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository rpm-cvs@rpm5.org