diff options
author | Mike Frysinger <vapier@gentoo.org> | 2015-12-20 01:00:07 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2015-12-20 01:00:07 -0500 |
commit | 95a3da9888af86a93732be4964da6aed5e523fcd (patch) | |
tree | 9517e2587b1ca698721dfa86eee65ce8ffd686a2 | |
parent | sb_efuncs: avoid pointless stdio indirection (diff) | |
download | sandbox-95a3da9888af86a93732be4964da6aed5e523fcd.tar.gz sandbox-95a3da9888af86a93732be4964da6aed5e523fcd.tar.bz2 sandbox-95a3da9888af86a93732be4964da6aed5e523fcd.zip |
libsandbox: avoid mixing stderr & output pipes
The various debug helpers were changed to write out to a dedicated message
path, but some of the trace code still uses stderr directly. When mixing
these methods, the direct prints would sometimes be lost. Convert the few
users to a new raw print function so they all route through the same file.
We might want to extract this a bit more out in the future so it's easier
to write to them, but this should be fine for now.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rw-r--r-- | libsandbox/trace.c | 2 | ||||
-rw-r--r-- | libsandbox/trace/linux/x86_64.c | 6 | ||||
-rw-r--r-- | libsbutil/sb_efuncs.c | 14 | ||||
-rw-r--r-- | libsbutil/sbutil.h | 1 |
4 files changed, 18 insertions, 5 deletions
diff --git a/libsandbox/trace.c b/libsandbox/trace.c index d424389..5ccda2a 100644 --- a/libsandbox/trace.c +++ b/libsandbox/trace.c @@ -18,7 +18,7 @@ static long _do_ptrace(enum __ptrace_request request, const char *srequest, void #else # define SBDEBUG 0 #endif -#define __sb_debug(fmt, args...) do { if (SBDEBUG) sb_printf(fmt, ## args); } while (0) +#define __sb_debug(fmt, args...) do { if (SBDEBUG) sb_eraw(fmt, ## args); } while (0) #define _sb_debug(fmt, args...) do { if (SBDEBUG) sb_ewarn("TRACE (pid=%i):%s: " fmt, getpid(), __func__, ## args); } while (0) #define sb_debug(fmt, args...) _sb_debug(fmt "\n", ## args) diff --git a/libsandbox/trace/linux/x86_64.c b/libsandbox/trace/linux/x86_64.c index 82c492d..aff1edb 100644 --- a/libsandbox/trace/linux/x86_64.c +++ b/libsandbox/trace/linux/x86_64.c @@ -129,8 +129,8 @@ static unsigned long trace_arg(void *vregs, int num) static void trace_dump_regs(void *vregs) { trace_regs *regs = vregs; - sb_printf("{ "); -#define D(r) sb_printf(#r":%"PRIu64" ", regs->r) + __sb_debug("{ "); +#define D(r) __sb_debug(#r":%"PRIu64" ", regs->r) D(rax); D(rdi); D(rsi); @@ -139,6 +139,6 @@ static void trace_dump_regs(void *vregs) D(r8); D(r9); #undef D - sb_printf("}"); + __sb_debug("}"); } #endif diff --git a/libsbutil/sb_efuncs.c b/libsbutil/sb_efuncs.c index 2de3116..7ded90d 100644 --- a/libsbutil/sb_efuncs.c +++ b/libsbutil/sb_efuncs.c @@ -48,7 +48,8 @@ static void sb_vefunc(const char *prog, const char *color, const char *format, v if (fd == -1) fd = fileno(stderr); - sb_fdprintf(fd, " %s*%s ", color, COLOR_NORMAL); + if (color) + sb_fdprintf(fd, " %s*%s ", color, COLOR_NORMAL); sb_vfdprintf(fd, format, args); if (opened) @@ -98,6 +99,17 @@ void sb_eqawarn(const char *format, ...) va_end(args); } +/* This is a bit of a hack to expose the same file logic to generic printers. + * Probably want to revisit sb_vefunc and move the guts there to a new func. + */ +void sb_eraw(const char *format, ...) +{ + va_list args; + va_start(args, format); + sb_vefunc(NULL, NULL, format, args); + va_end(args); +} + void sb_dump_backtrace(void) { #ifdef HAVE_BACKTRACE diff --git a/libsbutil/sbutil.h b/libsbutil/sbutil.h index 15979da..66c6f73 100644 --- a/libsbutil/sbutil.h +++ b/libsbutil/sbutil.h @@ -112,6 +112,7 @@ __printf(1, 2) void sb_ewarn(const char *format, ...); __printf(1, 2) void sb_eerror(const char *format, ...); __printf(1, 2) void sb_eqawarn(const char *format, ...); __printf(1, 2) void sb_debug_dyn(const char *format, ...); +__printf(1, 2) void sb_eraw(const char *format, ...); __printf(4, 5) void __sb_ebort(const char *file, const char *func, size_t line_num, const char *format, ...) __noreturn; #define sb_ebort(format, ...) __sb_ebort(__FILE__, __func__, __LINE__, format, ## __VA_ARGS__) void sb_dump_backtrace(void); |