From 4f4698a12c91030a2369f32de10b0ab07cab9b87 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Sat, 9 Feb 2013 18:19:40 -0800 Subject: [PATCH] Nonlib: Add (some) support for opening sessions readonly. --- nonlib/Loggable.C | 14 +++++++++++++- nonlib/Loggable.H | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/nonlib/Loggable.C b/nonlib/Loggable.C index b0edbe5..2bb6ebc 100644 --- a/nonlib/Loggable.C +++ b/nonlib/Loggable.C @@ -44,6 +44,7 @@ using std::max; +bool Loggable::_readonly = false; FILE *Loggable::_fp; unsigned int Loggable::_log_id = 0; int Loggable::_level = 0; @@ -116,8 +117,19 @@ Loggable::open ( const char *filename ) if ( ! ( fp = fopen( filename, "a+" ) ) ) { WARNING( "Could not open log file for writing!" ); - return false; + + if ( ! ( fp = fopen( filename, "r" ) ) ) + { + WARNING( "Could not open log file for reading!" ); + return false; + } + else + { + _readonly = true; + } } + + _readonly = false; load_unjournaled_state(); diff --git a/nonlib/Loggable.H b/nonlib/Loggable.H index e2f379c..25ed00a 100644 --- a/nonlib/Loggable.H +++ b/nonlib/Loggable.H @@ -70,6 +70,7 @@ class Loggable Log_Entry * unjournaled_state; }; + static bool _readonly; static FILE *_fp; static unsigned int _log_id; static int _level; @@ -141,6 +142,8 @@ private: static void clear_dirty ( void ) { signal_dirty( _dirty = 0 ); } public: + + static bool readonly ( void ) { return _readonly; } static bool replay ( const char *name );