Index: /trunk/ippTools/src/regtoolConfig.c
===================================================================
--- /trunk/ippTools/src/regtoolConfig.c	(revision 11085)
+++ /trunk/ippTools/src/regtoolConfig.c	(revision 11086)
@@ -30,4 +30,7 @@
 // this function can not fail -- exits on error
 pxConfig *p0toolConfig(pxConfig *config, int argc, char **argv) {
+
+    psExit exit_status = PS_EXIT_SUCCESS;
+
     if (!config) {
         config = pxConfigAlloc();
@@ -37,5 +40,5 @@
     config->modules = pmConfigRead(&argc, argv, NULL);
     if (!config->modules) {
-        psError(PS_ERR_UNKNOWN, false, "Can't find site configuration");
+        psError(PXTOOLS_ERR_CONFIG, false, "Can't find site configuration");
         goto FAIL;
     }
@@ -211,5 +214,5 @@
         psArgumentRemove (N, &argc, argv); \
         if (config->mode) { \
-            psError(PS_ERR_UNKNOWN, true, "only one mode selection is allowed"); \
+            psError(PXTOOLS_ERR_CONFIG, true, "only one mode selection is allowed"); \
             goto FAIL; \
         } \
@@ -218,5 +221,5 @@
     } \
     if (!psMetadataAddMetadata(argSets, PS_LIST_TAIL, option, 0, NULL, argset)) {;\
-        psError(PS_ERR_UNKNOWN, false, "failed to add argset for %s", option);\
+        psError(PXTOOLS_ERR_PROG, false, "failed to add argset for %s", option);\
     } \
     psFree(argset); \
@@ -236,9 +239,11 @@
     bool argErr = false;
     if (config->mode == P0TOOL_MODE_NONE) {
+	psError(PXTOOLS_ERR_CONFIG, false, "missing mode argument");
+        fprintf (stderr, "mode argument is required\n");
         argErr = true;
-        fprintf (stderr, "mode argument is required\n");
     } else if (! psArgumentParse(config->args, &argc, argv) || argc != 1) {
+	psError(PXTOOLS_ERR_CONFIG, false, "unknown argument");
+        fprintf (stderr, "error parsing arguments\n");
         argErr = true;
-        fprintf (stderr, "error parsing arguments\n");
     }
 
@@ -272,5 +277,5 @@
     if ((str = psMetadataLookupStr(&status, config->args, "-" #name))) { \
         if (!psMetadataAddStr(config->where, PS_LIST_TAIL, #name, 0, "==", str)) {\
-            psError(PS_ERR_UNKNOWN, false, "failed to add item " #name); \
+            psError(PXTOOLS_ERR_PROG, false, "failed to add item " #name); \
             goto FAIL; \
         } \
@@ -288,5 +293,5 @@
         if ((str = psMetadataLookupStr(&status, config->args, "-inst"))) {
             if (!psMetadataAddStr(config->where, PS_LIST_TAIL, "camera", 0, "==", str)) {
-                psError(PS_ERR_UNKNOWN, false, "failed to add item camera");
+                psError(PXTOOLS_ERR_PROG, false, "failed to add item camera");
                 goto FAIL;
             }
@@ -300,5 +305,5 @@
         if ((imfiles = psMetadataLookupS32(&status, config->args, "-imfiles"))) {
             if (!psMetadataAddS32(config->where, PS_LIST_TAIL, "imfiles", 0, "==", imfiles)) {
-                psError(PS_ERR_UNKNOWN, false, "failed to add item imfiles");
+                psError(PXTOOLS_ERR_PROG, false, "failed to add item imfiles");
                 goto FAIL;
             }
@@ -318,5 +323,5 @@
     config->dbh = pmConfigDB(config->modules);
     if (!config->dbh) {
-        psError(PS_ERR_UNKNOWN, false, "Can't configure database");
+        psError(PXTOOLS_ERR_SYS, false, "Can't configure database");
         goto FAIL;
     }
@@ -330,7 +335,10 @@
 
 FAIL:
+    // use the top-most error to determine the exit status
+    exit_status = pxerrorGetExitStatus();
+
     psFree(config);
     pmConfigDone();
     psLibFinalize();
-    exit(EXIT_FAILURE);
+    exit(exit_status);
 }
