Commit c54c7356 authored by 's avatar

Flush logs unsafely before program fails in the signal handler.


git-svn-id: https://google-glog.googlecode.com/svn/trunk@22 eb4d4688-79bd-11dd-afb4-1d65580434c0
parent 4f81d0f2
...@@ -279,6 +279,20 @@ void FailureSignalHandler(int signal_number, ...@@ -279,6 +279,20 @@ void FailureSignalHandler(int signal_number,
DumpStackFrameInfo(" ", stack[i]); DumpStackFrameInfo(" ", stack[i]);
} }
#endif #endif
// *** TRANSITION ***
//
// BEFORE this point, all code must be async-termination-safe!
// (See WARNING above.)
//
// AFTER this point, we do unsafe things, like using LOG()!
// The process could be terminated or hung at any time. We try to
// do more useful things first and riskier things later.
// Flush the logs before we do anything in case 'anything'
// causes problems.
FlushLogFilesUnsafe(0);
// Kill ourself by the default signal handler. // Kill ourself by the default signal handler.
InvokeDefaultSignalHandler(signal_number); InvokeDefaultSignalHandler(signal_number);
} }
......
...@@ -32,6 +32,9 @@ int main(int argc, char **argv) { ...@@ -32,6 +32,9 @@ int main(int argc, char **argv) {
InstallFailureSignalHandler(); InstallFailureSignalHandler();
const std::string command = argc > 1 ? argv[1] : "none"; const std::string command = argc > 1 ? argv[1] : "none";
if (command == "segv") { if (command == "segv") {
// We'll check if this is outputted.
LOG(INFO) << "create the log file";
LOG(INFO) << "a message before segv";
// We assume 0xDEAD is not writable. // We assume 0xDEAD is not writable.
int *a = (int*)0xDEAD; int *a = (int*)0xDEAD;
*a = 0; *a = 0;
......
...@@ -13,6 +13,7 @@ BINDIR=".libs" ...@@ -13,6 +13,7 @@ BINDIR=".libs"
LIBGLOG="$BINDIR/libglog.so" LIBGLOG="$BINDIR/libglog.so"
BINARY="$BINDIR/signalhandler_unittest" BINARY="$BINDIR/signalhandler_unittest"
LOG_INFO="./signalhandler_unittest.INFO"
# Remove temporary files. # Remove temporary files.
rm -f signalhandler.out* rm -f signalhandler.out*
...@@ -43,12 +44,16 @@ if [ x`uname -p` = x"powerpc" ]; then ...@@ -43,12 +44,16 @@ if [ x`uname -p` = x"powerpc" ]; then
fi fi
# Test for a case the program kills itself by SIGSEGV. # Test for a case the program kills itself by SIGSEGV.
$BINARY segv 2> signalhandler.out1 GOOGLE_LOG_DIR=. $BINARY segv 2> signalhandler.out1
for pattern in SIGSEGV 0xdead main "Aborted at [0-9]"; do for pattern in SIGSEGV 0xdead main "Aborted at [0-9]"; do
if ! grep --quiet "$pattern" signalhandler.out1; then if ! grep --quiet "$pattern" signalhandler.out1; then
die "'$pattern' should appear in the output" die "'$pattern' should appear in the output"
fi fi
done done
if ! grep --quiet "a message before segv" $LOG_INFO; then
die "'a message before segv' should appear in the INFO log"
fi
rm -f $LOG_INFO
# Test for a case the program is killed by this shell script. # Test for a case the program is killed by this shell script.
# $! = the process id of the last command run in the background. # $! = the process id of the last command run in the background.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment