From 4698d40e0ba982029b4e1f018f2bdfc1b99a5b32 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Wed, 30 May 2012 19:49:03 -0700 Subject: [PATCH] use EXIT_SUCCESS and EXIT_FAILURE We were wildly inconsistent with our exit status. We might as well follow the C standard. --- common.h | 2 +- mymemory.cc | 8 ++++---- snapshot.cc | 16 ++++++++-------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/common.h b/common.h index 656ea379..a950f791 100644 --- a/common.h +++ b/common.h @@ -23,7 +23,7 @@ do { \ if (!(expr)) { \ fprintf(stderr, "Error: assertion failed in %s at line %d\n", __FILE__, __LINE__); \ - exit(1); \ + exit(EXIT_FAILURE); \ } \ } while (0); diff --git a/mymemory.cc b/mymemory.cc index 0bbb7492..1dada053 100644 --- a/mymemory.cc +++ b/mymemory.cc @@ -18,7 +18,7 @@ void *MYMALLOC(size_t size) { mallocp = ( void * ( * )( size_t ) )dlsym(RTLD_NEXT, "malloc"); if ((error = dlerror()) != NULL) { fputs(error, stderr); - exit(1); + exit(EXIT_FAILURE); } } ptr = mallocp(size); @@ -43,7 +43,7 @@ void *system_malloc( size_t size ){ mallocp = ( void * ( * )( size_t ) )dlsym(RTLD_NEXT, "malloc"); if ((error = dlerror()) != NULL) { fputs(error, stderr); - exit(1); + exit(EXIT_FAILURE); } } ptr = mallocp(size); @@ -59,7 +59,7 @@ void system_free( void * ptr ){ freep = ( void ( * )( void * ) )dlsym(RTLD_NEXT, "free"); if ((error = dlerror()) != NULL) { fputs(error, stderr); - exit(1); + exit(EXIT_FAILURE); } } freep(ptr); @@ -74,7 +74,7 @@ void MYFREE(void *ptr) { freep = ( void ( * )( void * ) )dlsym(RTLD_NEXT, "free"); if ((error = dlerror()) != NULL) { fputs(error, stderr); - exit(1); + exit(EXIT_FAILURE); } } freep(ptr); diff --git a/snapshot.cc b/snapshot.cc index 3c5e5151..5a25bb14 100644 --- a/snapshot.cc +++ b/snapshot.cc @@ -18,7 +18,7 @@ #include //extern declaration definition -#define FAILURE(mesg) { printf("failed in the API: %s with errno relative message: %s\n", mesg, strerror( errno ) ); exit( -1 ); } +#define FAILURE(mesg) { printf("failed in the API: %s with errno relative message: %s\n", mesg, strerror( errno ) ); exit(EXIT_FAILURE); } #if USE_MPROTECT_SNAPSHOT struct SnapShot * snapshotrecord = NULL; struct Snapshot_t * sTheRecord = NULL; @@ -138,7 +138,7 @@ void initSnapShotLibrary(unsigned int numbackingpages, sa.sa_sigaction = HandlePF; if( sigaction( SIGSEGV, &sa, NULL ) == -1 ){ printf("SIGACTION CANNOT BE INSTALLED\n"); - exit(-1); + exit(EXIT_FAILURE); } initSnapShotRecord(numbackingpages, numsnapshots, nummemoryregions); @@ -210,7 +210,7 @@ void initSnapShotLibrary(unsigned int numbackingpages, } while( -1 == retVal && errno == EINTR ); if( sTheRecord->mIDToRollback != snapshotid ) - exit(0); + exit(EXIT_SUCCESS); else{ swapContext = true; } @@ -225,7 +225,7 @@ void addMemoryRegionToSnapShot( void * addr, unsigned int numPages) { unsigned int memoryregion=snapshotrecord->lastRegion++; if (memoryregion==snapshotrecord->maxRegions) { printf("Exceeded supported number of memory regions!\n"); - exit(-1); + exit(EXIT_FAILURE); } snapshotrecord->regionsToSnapShot[ memoryregion ].basePtr=addr; @@ -239,13 +239,13 @@ snapshot_id takeSnapshot( ){ if( mprotect(snapshotrecord->regionsToSnapShot[region].basePtr, snapshotrecord->regionsToSnapShot[region].sizeInPages*sizeof(struct SnapShotPage), PROT_READ ) == -1 ){ perror("mprotect"); printf("Failed to mprotect inside of takeSnapShot\n"); - exit(-1); + exit(EXIT_FAILURE); } } unsigned int snapshot=snapshotrecord->lastSnapShot++; if (snapshot==snapshotrecord->maxSnapShots) { printf("Out of snapshots\n"); - exit(-1); + exit(EXIT_FAILURE); } snapshotrecord->snapShots[snapshot].firstBackingPage=snapshotrecord->lastBackingPage; @@ -262,7 +262,7 @@ void rollBack( snapshot_id theID ){ if( mprotect(snapshotrecord->regionsToSnapShot[region].basePtr, snapshotrecord->regionsToSnapShot[region].sizeInPages*sizeof(struct SnapShotPage), PROT_READ | PROT_WRITE ) == -1 ){ perror("mprotect"); printf("Failed to mprotect inside of takeSnapShot\n"); - exit(-1); + exit(EXIT_FAILURE); } } for(unsigned int page=snapshotrecord->snapShots[theID].firstBackingPage; pagelastBackingPage; page++) { @@ -289,7 +289,7 @@ void rollBack( snapshot_id theID ){ #if SSDEBUG DumpIntoLog( "ModelSnapshot", "Invoked rollback" ); #endif - exit( 0 ); + exit(EXIT_SUCCESS); } #endif } -- 2.34.1