Index: trunk/pstamp/scripts/pstamp_parser_run.pl
===================================================================
--- trunk/pstamp/scripts/pstamp_parser_run.pl	(revision 25058)
+++ trunk/pstamp/scripts/pstamp_parser_run.pl	(revision 25195)
@@ -14,4 +14,12 @@
 use File::Basename qw( basename dirname);
 use POSIX qw( strftime );
+use Carp;
+use IPC::Cmd 0.36 qw( can_run run );
+
+use PS::IPP::Metadata::Config;
+use PS::IPP::Metadata::Stats;
+use PS::IPP::Metadata::List qw( parse_md_list );
+
+use PS::IPP::Config qw( :standard );
 
 my $req_id;
@@ -39,26 +47,8 @@
 }
 
-die "--req_id --uri --product are required" 
+my_die("--req_id --uri --product are required", $req_id, $PS_EXIT_CONFIG_ERROR)
     if !defined($req_id) or
        !defined($uri) or
        !defined($product);
-
-use IPC::Cmd 0.36 qw( can_run run );
-
-use PS::IPP::Metadata::Config;
-use PS::IPP::Metadata::Stats;
-use PS::IPP::Metadata::List qw( parse_md_list );
-
-use PS::IPP::Config qw($PS_EXIT_SUCCESS
-		       $PS_EXIT_UNKNOWN_ERROR
-		       $PS_EXIT_SYS_ERROR
-		       $PS_EXIT_CONFIG_ERROR
-		       $PS_EXIT_PROG_ERROR
-		       $PS_EXIT_DATA_ERROR
-		       $PS_EXIT_TIMEOUT_ERROR
-		       metadataLookupStr
-		       metadataLookupBool
-		       caturi
-		       );
 
 my $ipprc = PS::IPP::Config->new(); # IPP Configuration
@@ -80,10 +70,12 @@
 my $datedir = "$pstamp_workdir/$datestr";
 if (! -e $datedir ) {
-    mkdir $datedir or die "failed to create working directory $datedir for request id $req_id";
+    mkdir $datedir or my_die( "failed to create working directory $datedir for request id $req_id", $req_id,
+        $PS_EXIT_CONFIG_ERROR);
 }
 
 my $workdir = "$datedir/$req_id";
 if (! -e $workdir ) {
-    mkdir $workdir or die "failed to create working directory $workdir for request id $req_id";
+    mkdir $workdir or my_die("failed to create working directory $workdir for request id $req_id", $req_id,
+        $PS_EXIT_CONFIG_ERROR);
 }
 
@@ -119,18 +111,18 @@
         run(command => $command, verbose => $verbose);
     unless ($success) {
-        die("Unable to perform $command error code: $error_code");
+        my_die("Unable to perform $command error code: $error_code", $req_id, $error_code >> 8);
     }
 } elsif ($uri ne $new_uri) {
     # put a link to the file into the workdir
     if (-e $new_uri) {
-        unlink $new_uri or die "failed to unlink $new_uri";
+        unlink $new_uri or my_die("failed to unlink $new_uri", $req_id, $PS_EXIT_UNKNOWN_ERROR);
     }
     if (! symlink $uri, $new_uri) {
-        die ("failed to link request file $uri to workdir $workdir");
+        my_die ("failed to link request file $uri to workdir $workdir", $req_id, $PS_EXIT_UNKNOWN_ERROR);
     }
 }
 $uri = $new_uri;
 
-die "request file $uri not found" if ! -e $uri;
+my_die("request file $uri not found", $req_id, $PS_EXIT_UNKNOWN_ERROR) if ! -e $uri;
 
 #  if product was not defined (in database), use the default
@@ -263,2 +255,20 @@
     }
 }
+
+sub my_die {
+    my $msg = shift;
+    my $req_id = shift;
+    my $fault = shift;
+
+    carp($msg);
+
+    my $command = "$pstamptool -updatereq -req_id $req_id  -fault $fault";
+    $command   .= " -dbname $dbname" if $dbname;
+    $command   .= " -dbserver $dbserver" if $dbserver;
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $verbose);
+    unless ($success) {
+        die("Unable to perform $command error code: $error_code");
+    }
+    exit $fault;
+}
