certi-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[certi-cvs] certi/libCERTI PrettyDebug.hh PrettyDebug.cc


From: CERTI CVS commits
Subject: [certi-cvs] certi/libCERTI PrettyDebug.hh PrettyDebug.cc
Date: Thu, 21 Jun 2012 12:16:17 +0000

CVSROOT:        /sources/certi
Module name:    certi
Changes by:     Eric NOULARD <erk>      12/06/21 12:16:17

Modified files:
        libCERTI       : PrettyDebug.hh PrettyDebug.cc 

Log message:
        Avoid race condition on DEBUG file.
        Mangle the filename using PID

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/PrettyDebug.hh?cvsroot=certi&r1=4.9&r2=4.10
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/PrettyDebug.cc?cvsroot=certi&r1=4.11&r2=4.12

Patches:
Index: PrettyDebug.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/PrettyDebug.hh,v
retrieving revision 4.9
retrieving revision 4.10
diff -u -b -r4.9 -r4.10
--- PrettyDebug.hh      21 Jun 2012 08:03:24 -0000      4.9
+++ PrettyDebug.hh      21 Jun 2012 12:16:17 -0000      4.10
@@ -19,7 +19,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: PrettyDebug.hh,v 4.9 2012/06/21 08:03:24 erk Exp $
+// $Id: PrettyDebug.hh,v 4.10 2012/06/21 12:16:17 erk Exp $
 // ----------------------------------------------------------------------------
 
 #ifndef PRETTYDEBUG_HH
@@ -126,8 +126,9 @@
     static void initStreams();
     static std::ostream _defaultOutputStream;
     static std::string _federateName;
+    static std::filebuf* fb;
 };
 
 #endif // PRETTYDEBUG_HH
 
-// $Id: PrettyDebug.hh,v 4.9 2012/06/21 08:03:24 erk Exp $
+// $Id: PrettyDebug.hh,v 4.10 2012/06/21 12:16:17 erk Exp $

Index: PrettyDebug.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/PrettyDebug.cc,v
retrieving revision 4.11
retrieving revision 4.12
diff -u -b -r4.11 -r4.12
--- PrettyDebug.cc      21 Jun 2012 08:03:25 -0000      4.11
+++ PrettyDebug.cc      21 Jun 2012 12:16:17 -0000      4.12
@@ -19,7 +19,7 @@
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 // USA
 //
-// $Id: PrettyDebug.cc,v 4.11 2012/06/21 08:03:25 erk Exp $
+// $Id: PrettyDebug.cc,v 4.12 2012/06/21 12:16:17 erk Exp $
 // ----------------------------------------------------------------------------
 
 #include "PrettyDebug.hh"
@@ -36,20 +36,31 @@
 #ifdef _WIN32
 # include <time.h>
 # include <sys/timeb.h>
+# include <process.h>
 #else
 # include <sys/time.h>
+# include <sys/types.h>
+# include <unistd.h>
 #endif
 
 std::ostream PrettyDebug::_defaultOutputStream(std::cerr.rdbuf());
 std::string PrettyDebug::_federateName;
+std::filebuf* PrettyDebug::fb = NULL;
 
 void PrettyDebug::initStreams() {
-    static std::filebuf* fb = NULL;
     if (!fb) {
         const char *value = getenv("CERTI_DEBUG_FILE");
         if  (value) {
+            std::ostringstream filename;
+            int pid
+#ifdef _WIN32
+              = _getpid();
+#else
+              =(int)getpid();
+#endif
+            filename << value <<"-" <<pid;
             fb = new std::filebuf();
-            fb->open(value, std::ios_base::out | std::ios_base::app);
+            fb->open(filename.str().c_str(), std::ios_base::out | 
std::ios_base::trunc);
         }
     }
     /* replace buffer stream if we have one */
@@ -196,4 +207,4 @@
     return stream;
 }
 
-// $Id: PrettyDebug.cc,v 4.11 2012/06/21 08:03:25 erk Exp $
+// $Id: PrettyDebug.cc,v 4.12 2012/06/21 12:16:17 erk Exp $



reply via email to

[Prev in Thread] Current Thread [Next in Thread]