This file I/O "debug" messaging gets in the way. Make the debugging code simple
and succinct, or don't put it in at all. Now, you can enabled SnapShot
debugging by adding this near the top of snapshot.cc:
#define CONFIG_DEBUG
#define FAILURE(mesg) { printf("failed in the API: %s with errno relative message: %s\n", mesg, strerror( errno ) ); exit(EXIT_FAILURE); }
#define FAILURE(mesg) { printf("failed in the API: %s with errno relative message: %s\n", mesg, strerror( errno ) ); exit(EXIT_FAILURE); }
+#ifdef CONFIG_SSDEBUG
+#define SSDEBUG printf
+#else
+#define SSDEBUG(...) do { } while (0)
+#endif
+
/* extern declaration definition */
#if USE_MPROTECT_SNAPSHOT
struct SnapShot * snapshotrecord = NULL;
/* extern declaration definition */
#if USE_MPROTECT_SNAPSHOT
struct SnapShot * snapshotrecord = NULL;
#else
struct Snapshot_t * sTheRecord = NULL;
#endif
#else
struct Snapshot_t * sTheRecord = NULL;
#endif
-void DumpIntoLog( const char * filename, const char * message ){
-#if SSDEBUG
- static pid_t thePID = getpid();
- char newFn[ 1024 ] ={ 0 };
- sprintf( newFn,"%s-%d.txt", filename, thePID );
- FILE * myFile = fopen( newFn, "w+" );
- fprintf( myFile, "the message %s: the process id %d\n", message, thePID );
- fflush( myFile );
- fclose( myFile );
- myFile = NULL;
-#endif
-}
#if !USE_MPROTECT_SNAPSHOT
static ucontext_t savedSnapshotContext;
static ucontext_t savedUserSnapshotContext;
#if !USE_MPROTECT_SNAPSHOT
static ucontext_t savedSnapshotContext;
static ucontext_t savedUserSnapshotContext;
} else {
int status;
int retVal;
} else {
int status;
int retVal;
-#if SSDEBUG
- char mesg[ 1024 ] = { 0 };
- sprintf( mesg, "The process id of child is %d and the process id of this process is %d and snapshot id is %d", forkedID, getpid(), snapshotid );
- DumpIntoLog( "ModelSnapshot", mesg );
-#endif
+
+ SSDEBUG("The process id of child is %d and the process id of this process is %d and snapshot id is %d",
+ forkedID, getpid(), snapshotid );
+
do {
retVal=waitpid( forkedID, &status, 0 );
} while( -1 == retVal && errno == EINTR );
do {
retVal=waitpid( forkedID, &status, 0 );
} while( -1 == retVal && errno == EINTR );
getcontext( &sTheRecord->mContextToRollback );
if( !sTemp ){
sTemp = 1;
getcontext( &sTheRecord->mContextToRollback );
if( !sTemp ){
sTemp = 1;
-#if SSDEBUG
- DumpIntoLog( "ModelSnapshot", "Invoked rollback" );
-#endif
+ SSDEBUG("Invoked rollback");
exit(EXIT_SUCCESS);
}
#endif
exit(EXIT_SUCCESS);
}
#endif