diff options
author | Dale Rahn <drahn@cvs.openbsd.org> | 2009-05-18 20:27:20 +0000 |
---|---|---|
committer | Dale Rahn <drahn@cvs.openbsd.org> | 2009-05-18 20:27:20 +0000 |
commit | a86f52df1b164dce52103854d9c0f6dcc01308e0 (patch) | |
tree | 66e77b9048b0abafa07003222066c1ca966f81b4 | |
parent | 70d04b4454983db7f8ade89c13bbf7afd8c5c946 (diff) |
Add buffer mechanism internal ld.so printing code. makes ktrace more readable.
nudge nudge deraadt@
-rw-r--r-- | libexec/ld.so/dl_printf.c | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/libexec/ld.so/dl_printf.c b/libexec/ld.so/dl_printf.c index a7f84f02da3..7823727dda9 100644 --- a/libexec/ld.so/dl_printf.c +++ b/libexec/ld.so/dl_printf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dl_printf.c,v 1.13 2003/07/06 20:03:57 deraadt Exp $ */ +/* $OpenBSD: dl_printf.c,v 1.14 2009/05/18 20:27:19 drahn Exp $ */ /*- * Copyright (c) 1993 @@ -60,8 +60,14 @@ #include "syscall.h" #include "util.h" +int lastfd = -1; +#define OUTBUFSIZE 128 +static char outbuf[OUTBUFSIZE]; +static char *outptr = outbuf; + static void kprintn(void (*)(int,int), int, u_long, int); static void kdoprnt(void (*)(int,int), int, const char *, va_list); +static void _dl_flushbuf(void); static void putcharfd(int, int ); @@ -69,8 +75,27 @@ static void putcharfd(int c, int fd) { char b = c; + int len; + + if (fd != lastfd) { + _dl_flushbuf(); + lastfd = fd; + } + *outptr++ = b; + len = outptr - outbuf; + if ((len >= OUTBUFSIZE) || (b == '\n') || (b == '\r')) { + _dl_flushbuf(); + } +} - _dl_write(fd, &b, 1); +static void +_dl_flushbuf() +{ + int len = outptr - outbuf; + if (len != 0) { + _dl_write(lastfd, outbuf, len); + outptr = outbuf; + } } void @@ -198,6 +223,7 @@ reswitch: } } va_end(ap); + _dl_flushbuf(); } static void |