Index: trunk/ppStack/src/ppStack.c
===================================================================
--- trunk/ppStack/src/ppStack.c	(revision 27106)
+++ trunk/ppStack/src/ppStack.c	(revision 27107)
@@ -58,44 +58,5 @@
     // Common code for the death.
     {
-        psExit exitValue = PS_EXIT_SUCCESS;        // Exit value for program
-        psErrorCode errorCode = psErrorCodeLast(); // Error code
-        if (errorCode != PS_ERR_NONE) {
-            psErrorStackPrint(stderr, "Unable to perform stack.");
-            switch (errorCode) {
-              case PPSTACK_ERR_UNKNOWN:
-              case PS_ERR_UNKNOWN:
-                exitValue = PS_EXIT_UNKNOWN_ERROR;
-                break;
-              case PS_ERR_IO:
-              case PS_ERR_DB_CLIENT:
-              case PS_ERR_DB_SERVER:
-              case PS_ERR_BAD_FITS:
-              case PS_ERR_OS_CALL_FAILED:
-              case PPSTACK_ERR_IO:
-                exitValue = PS_EXIT_SYS_ERROR;
-                break;
-              case PS_ERR_BAD_PARAMETER_VALUE:
-              case PS_ERR_BAD_PARAMETER_TYPE:
-              case PS_ERR_BAD_PARAMETER_NULL:
-              case PS_ERR_BAD_PARAMETER_SIZE:
-              case PPSTACK_ERR_ARGUMENTS:
-              case PPSTACK_ERR_CONFIG:
-                exitValue = PS_EXIT_CONFIG_ERROR;
-                break;
-              case PPSTACK_ERR_PSF:
-              case PPSTACK_ERR_REJECTED:
-              case PPSTACK_ERR_DATA:
-                exitValue = PS_EXIT_DATA_ERROR;
-                break;
-              case PS_ERR_UNEXPECTED_NULL:
-              case PS_ERR_PROGRAMMING:
-              case PPSTACK_ERR_NOT_IMPLEMENTED:
-              case PPSTACK_ERR_PROG:
-              default:
-                // It's a programming error if we're not dealing with the error correctly
-                exitValue = PS_EXIT_PROG_ERROR;
-                break;
-            }
-        }
+        psExit exitValue = ppStackExitCode(); // Exit code
 
         // Ensure everything closes
@@ -107,4 +68,17 @@
             if (!ppStackFilesIterateUp(config)) {
                 psErrorStackPrint(stderr, "Unable to close files.");
+                if (exitValue == PS_EXIT_SUCCESS) {
+                    exitValue = ppStackExitCode();
+                }
+            }
+        }
+
+        // Dump configuration
+        bool mdok;                                                                    // Status of MD lookup
+        psString dump = psMetadataLookupStr(&mdok, config->arguments, "DUMP_CONFIG"); // File for config
+        if (dump && !pmConfigDump(config, dump)) {
+            psErrorStackPrint(stderr, "Unable to dump configuration.");
+            if (exitValue == PS_EXIT_SUCCESS) {
+                exitValue = ppStackExitCode();
             }
         }
Index: trunk/ppStack/src/ppStack.h
===================================================================
--- trunk/ppStack/src/ppStack.h	(revision 27106)
+++ trunk/ppStack/src/ppStack.h	(revision 27107)
@@ -169,4 +169,6 @@
     );
 
+/// Return an appropriate exit code based on the error code
+psExit ppStackExitCode(void);
 
 #endif
Index: trunk/ppStack/src/ppStackFinish.c
===================================================================
--- trunk/ppStack/src/ppStackFinish.c	(revision 27106)
+++ trunk/ppStack/src/ppStackFinish.c	(revision 27107)
@@ -90,13 +90,50 @@
     }
 
-    // Dump configuration
-    psString dump = psMetadataLookupStr(&mdok, config->arguments, "DUMP_CONFIG"); // File for config
-    if (dump) {
-        if (!pmConfigDump(config, dump)) {
-            psError(psErrorCodeLast(), false, "Unable to dump configuration.");
-            return false;
+    return true;
+}
+
+
+psExit ppStackExitCode(void)
+{
+    psExit exitValue = PS_EXIT_SUCCESS;        // Exit code to return
+    psErrorCode errorCode = psErrorCodeLast(); // Error code
+    if (errorCode != PS_ERR_NONE) {
+        psErrorStackPrint(stderr, "Unable to perform stack.");
+        switch (errorCode) {
+          case PPSTACK_ERR_UNKNOWN:
+          case PS_ERR_UNKNOWN:
+            exitValue = PS_EXIT_UNKNOWN_ERROR;
+            break;
+          case PS_ERR_IO:
+          case PS_ERR_DB_CLIENT:
+          case PS_ERR_DB_SERVER:
+          case PS_ERR_BAD_FITS:
+          case PS_ERR_OS_CALL_FAILED:
+          case PPSTACK_ERR_IO:
+            exitValue = PS_EXIT_SYS_ERROR;
+            break;
+          case PS_ERR_BAD_PARAMETER_VALUE:
+          case PS_ERR_BAD_PARAMETER_TYPE:
+          case PS_ERR_BAD_PARAMETER_NULL:
+          case PS_ERR_BAD_PARAMETER_SIZE:
+          case PPSTACK_ERR_ARGUMENTS:
+          case PPSTACK_ERR_CONFIG:
+            exitValue = PS_EXIT_CONFIG_ERROR;
+            break;
+          case PPSTACK_ERR_PSF:
+          case PPSTACK_ERR_REJECTED:
+          case PPSTACK_ERR_DATA:
+            exitValue = PS_EXIT_DATA_ERROR;
+            break;
+          case PS_ERR_UNEXPECTED_NULL:
+          case PS_ERR_PROGRAMMING:
+          case PPSTACK_ERR_NOT_IMPLEMENTED:
+          case PPSTACK_ERR_PROG:
+          default:
+            // It's a programming error if we're not dealing with the error correctly
+            exitValue = PS_EXIT_PROG_ERROR;
+            break;
         }
     }
-
-    return true;
+    return exitValue;
 }
