From dbc020ffac0aa37c46b5c577fe87e0e418cdfc01 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 19 Nov 2014 15:57:47 +0100 Subject: [PATCH] Use -ex option for GDB rather than stdin --- src/backtrace.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/backtrace.c b/src/backtrace.c index b8f4183..0f69255 100644 --- a/src/backtrace.c +++ b/src/backtrace.c @@ -73,6 +73,7 @@ static void yaz_invoke_backtrace(char *buf, int buf_sz) { pid_t pid; int fds[2]; + pipe(fds); pid = fork(); @@ -83,7 +84,7 @@ static void yaz_invoke_backtrace(char *buf, int buf_sz) } else if (pid == 0) { /* child */ - char *arg[10]; + char *arg[20]; int arg_no = 0; char pidstr[40]; const char *cp = "backtrace: could not exec gdb"; @@ -103,6 +104,11 @@ static void yaz_invoke_backtrace(char *buf, int buf_sz) } arg[arg_no++] = "/usr/bin/gdb"; arg[arg_no++] = "-n"; + arg[arg_no++] = "-batch"; + arg[arg_no++] = "-ex"; + arg[arg_no++] = "info threads"; + arg[arg_no++] = "-ex"; + arg[arg_no++] = "thread apply all bt"; arg[arg_no++] = static_progname; sprintf(pidstr, NMEM_INT_PRINTF, (nmem_int_t) getppid()); arg[arg_no++] = pidstr; @@ -114,20 +120,11 @@ static void yaz_invoke_backtrace(char *buf, int buf_sz) else { /* parent */ - char *dbg_commands = "info threads\nthread apply all bt\n"; - int off = 0; int sec = 0; close(fds[0]); - while (off < strlen(dbg_commands)) - { - ssize_t r = write(fds[1], dbg_commands + off, - strlen(dbg_commands) - off); - if (r == (ssize_t) (-1)) - break; - off += r; - } - close(fds[1]); + + write(fds[1], "quit\n", 5); while (1) { int status; @@ -141,8 +138,10 @@ static void yaz_invoke_backtrace(char *buf, int buf_sz) if (sec == 4) break; sleep(1); + write(fds[1], "quit\n", 5); sec++; } + close(fds[1]); } } #else -- 1.7.10.4