X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=lib%2Flibuutil%2Fuu_misc.c;h=67f757c905a0fc50dfeccfcee4fa309239c38daa;hb=c11a12bc3b2e5ee9a6bd74e26f1a396b6025fbd4;hp=74ec177c11b79b57d7e380960e2d4f390b6277fc;hpb=172bb4bd5e4afef721dd4d2972d8680d983f144b;p=zfs.git diff --git a/lib/libuutil/uu_misc.c b/lib/libuutil/uu_misc.c index 74ec177..67f757c 100644 --- a/lib/libuutil/uu_misc.c +++ b/lib/libuutil/uu_misc.c @@ -20,12 +20,9 @@ */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. + * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include "libuutil_common.h" #include @@ -37,8 +34,8 @@ #include #include #include -#include #include +#include #if !defined(TEXT_DOMAIN) #define TEXT_DOMAIN "SYS_TEST" @@ -70,11 +67,12 @@ static va_list uu_panic_args; static pthread_t uu_panic_thread; static uint32_t _uu_main_error; +static __thread int _uu_main_thread = 0; void uu_set_error(uint_t code) { - if (thr_main() != 0) { + if (_uu_main_thread) { _uu_main_error = code; return; } @@ -103,7 +101,7 @@ uu_set_error(uint_t code) uint32_t uu_error(void) { - if (thr_main() != 0) + if (_uu_main_thread) return (_uu_main_error); if (uu_error_key_setup < 0) /* can't happen? */ @@ -208,14 +206,6 @@ uu_panic(const char *format, ...) (void) pause(); } -int -assfail(const char *astring, const char *file, int line) -{ - __assert(astring, file, line); - /*NOTREACHED*/ - return (0); -} - static void uu_lockup(void) { @@ -247,9 +237,43 @@ uu_release_child(void) uu_release(); } +#ifdef __GNUC__ +static void +uu_init(void) __attribute__((constructor)); +#else #pragma init(uu_init) +#endif + static void uu_init(void) { + _uu_main_thread = 1; (void) pthread_atfork(uu_lockup, uu_release, uu_release_child); } + +/* + * Dump a block of memory in hex+ascii, for debugging + */ +void +uu_dump(FILE *out, const char *prefix, const void *buf, size_t len) +{ + const unsigned char *p = buf; + int i; + + for (i = 0; i < len; i += 16) { + int j; + + (void) fprintf(out, "%s", prefix); + for (j = 0; j < 16 && i + j < len; j++) { + (void) fprintf(out, "%2.2x ", p[i + j]); + } + for (; j < 16; j++) { + (void) fprintf(out, " "); + } + for (j = 0; j < 16 && i + j < len; j++) { + (void) fprintf(out, "%c", + isprint(p[i + j]) ? p[i + j] : '.'); + } + (void) fprintf(out, "\n"); + } +}