Gentoo Archives: gentoo-commits

From: Mike Frysinger <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/sandbox:master commit in: libsandbox/trace/linux/, libsbutil/, libsandbox/
Date: Sun, 20 Dec 2015 08:41:24
Message-Id: 1450591207.95a3da9888af86a93732be4964da6aed5e523fcd.vapier@gentoo
1 commit: 95a3da9888af86a93732be4964da6aed5e523fcd
2 Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
3 AuthorDate: Sun Dec 20 06:00:07 2015 +0000
4 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
5 CommitDate: Sun Dec 20 06:00:07 2015 +0000
6 URL: https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=95a3da98
7
8 libsandbox: avoid mixing stderr & output pipes
9
10 The various debug helpers were changed to write out to a dedicated message
11 path, but some of the trace code still uses stderr directly. When mixing
12 these methods, the direct prints would sometimes be lost. Convert the few
13 users to a new raw print function so they all route through the same file.
14
15 We might want to extract this a bit more out in the future so it's easier
16 to write to them, but this should be fine for now.
17
18 Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>
19
20 libsandbox/trace.c | 2 +-
21 libsandbox/trace/linux/x86_64.c | 6 +++---
22 libsbutil/sb_efuncs.c | 14 +++++++++++++-
23 libsbutil/sbutil.h | 1 +
24 4 files changed, 18 insertions(+), 5 deletions(-)
25
26 diff --git a/libsandbox/trace.c b/libsandbox/trace.c
27 index d424389..5ccda2a 100644
28 --- a/libsandbox/trace.c
29 +++ b/libsandbox/trace.c
30 @@ -18,7 +18,7 @@ static long _do_ptrace(enum __ptrace_request request, const char *srequest, void
31 #else
32 # define SBDEBUG 0
33 #endif
34 -#define __sb_debug(fmt, args...) do { if (SBDEBUG) sb_printf(fmt, ## args); } while (0)
35 +#define __sb_debug(fmt, args...) do { if (SBDEBUG) sb_eraw(fmt, ## args); } while (0)
36 #define _sb_debug(fmt, args...) do { if (SBDEBUG) sb_ewarn("TRACE (pid=%i):%s: " fmt, getpid(), __func__, ## args); } while (0)
37 #define sb_debug(fmt, args...) _sb_debug(fmt "\n", ## args)
38
39
40 diff --git a/libsandbox/trace/linux/x86_64.c b/libsandbox/trace/linux/x86_64.c
41 index 82c492d..aff1edb 100644
42 --- a/libsandbox/trace/linux/x86_64.c
43 +++ b/libsandbox/trace/linux/x86_64.c
44 @@ -129,8 +129,8 @@ static unsigned long trace_arg(void *vregs, int num)
45 static void trace_dump_regs(void *vregs)
46 {
47 trace_regs *regs = vregs;
48 - sb_printf("{ ");
49 -#define D(r) sb_printf(#r":%"PRIu64" ", regs->r)
50 + __sb_debug("{ ");
51 +#define D(r) __sb_debug(#r":%"PRIu64" ", regs->r)
52 D(rax);
53 D(rdi);
54 D(rsi);
55 @@ -139,6 +139,6 @@ static void trace_dump_regs(void *vregs)
56 D(r8);
57 D(r9);
58 #undef D
59 - sb_printf("}");
60 + __sb_debug("}");
61 }
62 #endif
63
64 diff --git a/libsbutil/sb_efuncs.c b/libsbutil/sb_efuncs.c
65 index 2de3116..7ded90d 100644
66 --- a/libsbutil/sb_efuncs.c
67 +++ b/libsbutil/sb_efuncs.c
68 @@ -48,7 +48,8 @@ static void sb_vefunc(const char *prog, const char *color, const char *format, v
69 if (fd == -1)
70 fd = fileno(stderr);
71
72 - sb_fdprintf(fd, " %s*%s ", color, COLOR_NORMAL);
73 + if (color)
74 + sb_fdprintf(fd, " %s*%s ", color, COLOR_NORMAL);
75 sb_vfdprintf(fd, format, args);
76
77 if (opened)
78 @@ -98,6 +99,17 @@ void sb_eqawarn(const char *format, ...)
79 va_end(args);
80 }
81
82 +/* This is a bit of a hack to expose the same file logic to generic printers.
83 + * Probably want to revisit sb_vefunc and move the guts there to a new func.
84 + */
85 +void sb_eraw(const char *format, ...)
86 +{
87 + va_list args;
88 + va_start(args, format);
89 + sb_vefunc(NULL, NULL, format, args);
90 + va_end(args);
91 +}
92 +
93 void sb_dump_backtrace(void)
94 {
95 #ifdef HAVE_BACKTRACE
96
97 diff --git a/libsbutil/sbutil.h b/libsbutil/sbutil.h
98 index 15979da..66c6f73 100644
99 --- a/libsbutil/sbutil.h
100 +++ b/libsbutil/sbutil.h
101 @@ -112,6 +112,7 @@ __printf(1, 2) void sb_ewarn(const char *format, ...);
102 __printf(1, 2) void sb_eerror(const char *format, ...);
103 __printf(1, 2) void sb_eqawarn(const char *format, ...);
104 __printf(1, 2) void sb_debug_dyn(const char *format, ...);
105 +__printf(1, 2) void sb_eraw(const char *format, ...);
106 __printf(4, 5) void __sb_ebort(const char *file, const char *func, size_t line_num, const char *format, ...) __noreturn;
107 #define sb_ebort(format, ...) __sb_ebort(__FILE__, __func__, __LINE__, format, ## __VA_ARGS__)
108 void sb_dump_backtrace(void);