From: Date: Fri, 19 Dec 2008 06:49:33 +0000 (+0000) Subject: Flush logs unsafely before program fails in the signal handler. X-Git-Tag: accepted/tizen/5.0/unified/20181102.024921~214 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c54c735616b5dba9966c342b0e14e07833bbec7b;p=platform%2Fupstream%2Fglog.git 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 --- diff --git a/src/signalhandler.cc b/src/signalhandler.cc index 3c89715..367c226 100644 --- a/src/signalhandler.cc +++ b/src/signalhandler.cc @@ -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); } diff --git a/src/signalhandler_unittest.cc b/src/signalhandler_unittest.cc index 48fc713..eb078a0 100644 --- a/src/signalhandler_unittest.cc +++ b/src/signalhandler_unittest.cc @@ -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; diff --git a/src/signalhandler_unittest.sh b/src/signalhandler_unittest.sh index ef30450..5875bd2 100755 --- a/src/signalhandler_unittest.sh +++ b/src/signalhandler_unittest.sh @@ -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.