use EXIT_SUCCESS and EXIT_FAILURE
authorBrian Norris <banorris@uci.edu>
Thu, 31 May 2012 02:49:03 +0000 (19:49 -0700)
committerBrian Norris <banorris@uci.edu>
Thu, 31 May 2012 02:49:03 +0000 (19:49 -0700)
We were wildly inconsistent with our exit status. We might as well follow the
C standard.

common.h
mymemory.cc
snapshot.cc

index 656ea3798dde73d08b168fdfe54f5d4c72dcc04d..a950f79194c55d849fe82da5d18e35cef2675464 100644 (file)
--- 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);
 
index 0bbb7492dd3c1aef9987304a326678cde9484330..1dada053c2ba9060ed1c3301e3b895c44bf3855c 100644 (file)
@@ -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);
index 3c5e515103e6b6f4699e7ccf6cf67a69c2f27a49..5a25bb14efbe24bbf88ad0e4d6de8238316f884b 100644 (file)
@@ -18,7 +18,7 @@
 #include <ucontext.h>
 
 //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; page<snapshotrecord->lastBackingPage; page++) {
@@ -289,7 +289,7 @@ void rollBack( snapshot_id theID ){
 #if SSDEBUG
                DumpIntoLog( "ModelSnapshot", "Invoked rollback" );
 #endif
-               exit( 0 );
+               exit(EXIT_SUCCESS);
        }
 #endif
 }