Author: mvidner Date: Mon Apr 14 20:48:50 2008 New Revision: 46620 URL: http://svn.opensuse.org/viewcvs/yast?rev=46620&view=rev Log: If Y2DEBUGONCRASH is set, the crash handler will also print the last few debugging log messages, even if Y2DEBUG is not set (fate#302166). Modified: trunk/core/VERSION trunk/core/liby2/src/genericfrontend.cc trunk/core/liby2util-r/src/include/y2util/y2log.h trunk/core/liby2util-r/src/y2log.cc trunk/core/package/yast2-core.changes Modified: trunk/core/VERSION URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/VERSION?rev=46620&r1=466... ============================================================================== --- trunk/core/VERSION (original) +++ trunk/core/VERSION Mon Apr 14 20:48:50 2008 @@ -1 +1 @@ -2.16.47 +2.16.48 Modified: trunk/core/liby2/src/genericfrontend.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/liby2/src/genericfrontend.cc... ============================================================================== --- trunk/core/liby2/src/genericfrontend.cc (original) +++ trunk/core/liby2/src/genericfrontend.cc Mon Apr 14 20:48:50 2008 @@ -58,6 +58,21 @@ static bool is_ycp_value (const char* arg); string demangle( const char * mangled ); +static +bool +log_blanik (const string & s) +{ + y2lograw (s.c_str ()); +} + +// fate#302166 "cache yast debugging logs in case of failure" +static +void log_stored_debug () +{ + y2error ("Liberating suppressed debugging messages:"); + blanik.for_each (log_blanik); + y2error ("End of suppressed debugging messages"); +} // FATE 302167, info '(libc) Backtraces' void @@ -131,6 +146,7 @@ sig, ee.filename ().c_str (), ee.linenumber ()); y2error ("got signal %d at YCP file %s:%d", sig, ee.filename ().c_str (), ee.linenumber ()); + log_stored_debug (); log_backtrace (); // bye signal (sig, SIG_DFL); Modified: trunk/core/liby2util-r/src/include/y2util/y2log.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/liby2util-r/src/include/y2ut... ============================================================================== --- trunk/core/liby2util-r/src/include/y2util/y2log.h (original) +++ trunk/core/liby2util-r/src/include/y2util/y2log.h Mon Apr 14 20:48:50 2008 @@ -31,12 +31,21 @@ /* Logging functions */ +// Implements y2_logger void y2_logger_function (loglevel_t level, const char *component, const char *file, const int line, const char *func, const char *format, ...) __attribute__ ((format (printf, 6, 7))); +// The knights of Blanik only show up when nothing else can help, and so will +// the messages logged here. fate#302166 +void y2_logger_blanik (loglevel_t level, const char *component, const char *file, + const int line, const char *func, const char *format, ...) + __attribute__ ((format (printf, 6, 7))); +// Same as above, but with va_list void y2_vlogger_function (loglevel_t level, const char *component, const char *file, const int line, const char *func, const char *format, va_list ap); +void y2_vlogger_blanik (loglevel_t level, const char *component, const char *file, + const int line, const char *func, const char *format, va_list ap); void y2_logger_raw( const char* message ); @@ -63,12 +72,16 @@ do { \ if (should_be_logged (level, comp)) \ y2_logger_function (level,comp,file,line,function,format,##args);\ + else if (should_be_buffered ()) \ + y2_logger_blanik (level,comp,file,line,function,format,##args); \ } while (0) #define y2_vlogger(level,comp,file,line,function,format,args) \ do { \ if (should_be_logged (level, comp)) \ y2_vlogger_function (level,comp,file,line,function,format,args);\ + else if (should_be_buffered ()) \ + y2_vlogger_blanik (level,comp,file,line,function,format,args); \ } while (0) /* @@ -103,8 +116,13 @@ #define y2lograw(message) y2_logger_raw(message) /** + * Should we bother evaluating the arguments to the logging function? */ bool should_be_logged (int loglevel, string componentname); +/** + * Should we bother evaluating the arguments to the buffering function? + */ +bool should_be_buffered (); /** * Set an alternate logfile name for @ref y2log. If this is not done by the @@ -141,4 +159,23 @@ */ bool get_log_debug(); +// stores a few strings. can append one. can return all. old are forgotten. +class LogTail { +public: + typedef string Data; + LogTail (size_t max_size = 42); + ~LogTail (); + void push_back (const Data &); + + // consumer returns true to continue iterating + typedef bool (* Consumer) (const Data &); + void for_each (Consumer c); +private: + class Impl; + Impl *m_impl; +}; + +// the instance used for last resort logging +extern LogTail blanik; + #endif /* _y2log_h */ Modified: trunk/core/liby2util-r/src/y2log.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/liby2util-r/src/y2log.cc?rev... ============================================================================== --- trunk/core/liby2util-r/src/y2log.cc (original) +++ trunk/core/liby2util-r/src/y2log.cc Mon Apr 14 20:48:50 2008 @@ -26,6 +26,7 @@ #include <sys/types.h> #include <unistd.h> #include <limits> +#include <list> #include "y2util/y2log.h" #include "y2util/miniini.h" @@ -62,6 +63,7 @@ #define Y2LOG_VAR_DEBUG "Y2DEBUG" #define Y2LOG_VAR_ALL "Y2DEBUGALL" +#define Y2LOG_VAR_ONCRASH "Y2DEBUGONCRASH" #define Y2LOG_VAR_SIZE "Y2MAXLOGSIZE" #define Y2LOG_VAR_NUM "Y2MAXLOGNUM" @@ -161,6 +163,15 @@ va_end(ap); } +void y2_logger_blanik(loglevel_t level, const char *component, const char *file, + const int line, const char *func, const char *format, ...) +{ + va_list ap; + va_start(ap, format); + y2_vlogger_blanik(level, component, file, line, func, format, ap); + va_end(ap); +} + /** * Formats the common part */ @@ -286,6 +297,24 @@ } } +void y2_vlogger_blanik(loglevel_t level, const char *component, const char *file, + const int line, const char *function, const char *format, va_list ap) +{ + string common = y2_logfmt_common (log_simple, + component, file, line, function, + format, ap); + + if(log_to_syslog || log_to_file) { + string tolog; + if (log_simple || (log_to_syslog > log_to_file)) + tolog = common; + else + tolog = y2_logfmt_prefix (level) + ' ' + common; + // store the message for worse times + blanik.push_back (tolog); + } +} + void y2_logger_raw( const char* logmessage ) { if(log_to_syslog) { @@ -556,4 +585,62 @@ return log_debug; } +// buffer the debugging log and show it only if yast crashes +// fate#302166 + +bool should_be_buffered () +{ + return getenv (Y2LOG_VAR_ONCRASH) != NULL; +} + +// stores a few strings. can append one. can return all. old are forgotten. +class LogTail::Impl { + size_t m_size; + size_t m_max_size; + std::list<Data> m_items; +public: + Impl(size_t max_size = 42) + : m_size (0) + , m_max_size (max_size) + {} + + void push_back (const Data &d) { + if (m_size >= m_max_size) + m_items.pop_front (); + else + ++m_size; + + m_items.push_back (d); + } + + void for_each (Consumer c) { + std::list<Data>::iterator i; + for (i = m_items.begin (); i != m_items.end (); ++i) + if (! c(*i)) + break; + } +}; + +LogTail::LogTail (size_t max_size) +{ + m_impl = new Impl (max_size); +} + +LogTail::~LogTail () +{ + delete m_impl; +} + +void LogTail::push_back (const Data &d) +{ + m_impl->push_back (d); +} +void LogTail::for_each (LogTail::Consumer c) +{ + m_impl->for_each (c); +} + +// define the singleton +LogTail blanik = LogTail (); + /* EOF */ Modified: trunk/core/package/yast2-core.changes URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/package/yast2-core.changes?r... ============================================================================== --- trunk/core/package/yast2-core.changes (original) +++ trunk/core/package/yast2-core.changes Mon Apr 14 20:48:50 2008 @@ -1,4 +1,12 @@ ------------------------------------------------------------------- +Mon Apr 14 20:47:27 CEST 2008 - mvidner@suse.cz + +- If Y2DEBUGONCRASH is set, the crash handler will also print the + last few debugging log messages, even if Y2DEBUG is not set + (fate#302166). +- 2.16.48 + +------------------------------------------------------------------- Thu Apr 10 16:53:17 CEST 2008 - mvidner@suse.cz - New builtin: dpgettext ("animals", "/mnt/share/locale", "Giraffe") -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org