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
This commit is contained in:
parent
4f81d0f209
commit
c54c735616
@ -279,6 +279,20 @@ void FailureSignalHandler(int signal_number,
|
||||
DumpStackFrameInfo(" ", stack[i]);
|
||||
}
|
||||
#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.
|
||||
InvokeDefaultSignalHandler(signal_number);
|
||||
}
|
||||
|
||||
@ -32,6 +32,9 @@ int main(int argc, char **argv) {
|
||||
InstallFailureSignalHandler();
|
||||
const std::string command = argc > 1 ? argv[1] : "none";
|
||||
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.
|
||||
int *a = (int*)0xDEAD;
|
||||
*a = 0;
|
||||
|
||||
@ -13,6 +13,7 @@ BINDIR=".libs"
|
||||
LIBGLOG="$BINDIR/libglog.so"
|
||||
|
||||
BINARY="$BINDIR/signalhandler_unittest"
|
||||
LOG_INFO="./signalhandler_unittest.INFO"
|
||||
|
||||
# Remove temporary files.
|
||||
rm -f signalhandler.out*
|
||||
@ -43,12 +44,16 @@ if [ x`uname -p` = x"powerpc" ]; then
|
||||
fi
|
||||
|
||||
# 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
|
||||
if ! grep --quiet "$pattern" signalhandler.out1; then
|
||||
die "'$pattern' should appear in the output"
|
||||
fi
|
||||
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.
|
||||
# $! = the process id of the last command run in the background.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user