glibc backtrace - can't redirect output to file

偶尔善良 提交于 2019-12-18 04:42:13

问题


I'm in the process of debugging a C program (that I didn't write). I have all of the internal debugging tools (a whole bunch of printf's) enabled, and I wrote a small PHP script that uses proc_open() and just grabs both stdout and stderr, and time-coordinates them in one file.

At the moment, the binary is dieing with a realloc() error that's caught by glibc, and a glibc backtrace is printed, beginning with:

*** glibc detected *** /sbin/rsyslogd: realloc(): invalid next size: 0x00002ace626ac910 ***

Here's the thing I don't understand: I've confirmed that the PHP script is catching both stdout and stderr from the binary's process and writing them to the correct files, but this backtrace is still printed to the console. Where is this coming from? Is there some magical output channel other than stdout and stderr?

Any ideas on how I go about capturing this backtrace to a file, or sending it out with stderr?

Thanks, Jason


回答1:


Sorry... I asked the question after about half an hour of googling, but after a little more investigation, I found a solution... in a Fedora mailing list post (http://www.redhat.com/archives/rhl-devel-list/2009-August/msg00982.html) dealing with this problem in the Koji build system...

export LIBC_FATAL_STDERR_=1

Apparently by default the error reports go right to /dev/tty for some reason...




回答2:


The mailing list that Jason references also suggests some more heavy-duty solutions, as follows:

IMHO koji (and mock for that matter) ought to be running the builds inside a captive pty whose output it logs anyway, even if they redirect everything. You never know what crazy nonsense some package is going to try. (Roland McGrath, http://www.redhat.com/archives/rhl-devel-list/2009-August/msg00982.html)

Following posts suggest using the pty python package to accomplish this.



来源:https://stackoverflow.com/questions/4616061/glibc-backtrace-cant-redirect-output-to-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!