diff options
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | src/pacman/pacman.c | 35 |
2 files changed, 30 insertions, 6 deletions
diff --git a/configure.ac b/configure.ac index c7aac6c3..c87d17b7 100644 --- a/configure.ac +++ b/configure.ac @@ -319,6 +319,7 @@ AC_MSG_CHECKING(for debug mode request) if test x$debug = xyes ; then AM_CONDITIONAL(PACMAN_DEBUG, test x$debug = xyes) CFLAGS="-g -Wall -Werror -std=c99 -DPACMAN_DEBUG" + LDFLAGS="$LDFLAGS -lmcheck" AC_MSG_RESULT(yes) else AM_CONDITIONAL(PACMAN_DEBUG, test x$debug = xno) diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 9259cf9d..1708d371 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -85,6 +85,32 @@ unsigned int maxcols = 80; extern int neednl; +#if defined(PACMAN_DEBUG) && !defined(CYGWIN) && !defined(BSD) +void mcheck_abort(enum mcheck_status status) +{ + switch(status) + { + case MCHECK_DISABLED: + fputs("mcheck: disabled, no checking can be done", stderr); + break; + case MCHECK_OK: + fputs("mcheck: block ok", stderr); + break; + case MCHECK_HEAD: + fputs("mcheck: inconsistancy at block head (underrun)", stderr); + abort(); + break; + case MCHECK_TAIL: + fputs("mcheck: inconsistancy at block tail (overrun)", stderr); + abort(); + break; + case MCHECK_FREE: + fputs("mcheck: block has already been freed", stderr); + break; + }; +} +#endif + /* Display usage/syntax for the specified operation. * op: the operation code requested * myname: basename(argv[0]) @@ -209,12 +235,10 @@ static void cleanup(int signum) FREELIST(pm_targets); FREECONF(config); -#ifndef CYGWIN -#ifndef BSD +#if defined(PACMAN_DEBUG) && !defined(CYGWIN) && !defined(BSD) /* debug */ muntrace(); #endif -#endif if(neednl) { putchar('\n'); @@ -417,11 +441,10 @@ int main(int argc, char *argv[]) #endif list_t *lp; -#ifndef CYGWIN -#ifndef BSD +#if defined(PACMAN_DEBUG) && !defined(CYGWIN) && !defined(BSD) /* debug */ mtrace(); -#endif + mcheck(0); #endif cenv = getenv("COLUMNS"); |