File hashcash-sendmail-exitstatus.diff of Package hashcash

--- hashcash-sendmail	2004-11-12 16:21:01.000000000 +0100
+++ hashcash-sendmail	2010-03-15 16:22:10.000000000 +0100
@@ -202,6 +202,7 @@
 # 'dat'          -- the name of the job's .dat file
 # 'sendmailfh'   -- where I write the message
 # 'sendmailpid'  -- the sendmail PID
+# 'loggerpid'    -- the PID of the logger process spawned for sendmail
 # 'msgfh'        -- whence I read the message
 # 'hashcashfh'   -- whence I read a token
 # 'hashcashpid'  -- what to signal with STOP and CONT
@@ -1078,22 +1079,30 @@
 	# This checks sendmail's exit status.  If something's wrong, we
 	# put the message back in the queue, whine, and abort with the same
 	# exit code that sendmail gave.
+	my $exit_code = 0;
 	if ( ! close( $sm ) && ! $! ) {
 	    # Propogate the exit code.
-	    my $exit_code = $?;
-
-	    logline( "putting $msg back in queue" );
-	    rename( "$workdir/tmp/$msg", "$workdir/queue/$msg" );
-	    complain( "sendmail exited with $exit_code\n" );
-	    exit( $exit_code );
+	    $exit_code = $? >> 8;
 	}
 
 	# Reap my subprocesses properly.
 	if ( $$state{ 'sendmailpid' } ) {
 	    waitpid( $$state{ 'sendmailpid' }, 0 );
+	    if (!$exit_code) {
+		$exit_code = $? >> 8;
+	    }
+	    $$state{ 'sendmailpid' } = 0;
 	}
 	if ( $$state{ 'loggerpid' } ) {
 	    waitpid( $$state{ 'loggerpid' }, 0 );
+	    $$state{ 'loggerpid' } = 0;
+	}
+
+	if ($exit_code) {
+	    logline( "putting $msg back in queue" );
+	    rename( "$workdir/tmp/$msg", "$workdir/queue/$msg" );
+	    complain( "sendmail exited with $exit_code\n" );
+	    exit $exit_code;
 	}
     }
     close( $msgfh ) if ( $msgfh );
@@ -1200,20 +1209,28 @@
 		logline( "TERM sendmail PID $pid" );
 		kill( 'TERM', $pid );
 	    }
+	    $pid = $$state{ 'loggerpid' };
+	    if ( $pid ) {
+		# the logger should exit by itself when sendmail dies...
+		#sleep(1);
+		#logline( "TERM logger PID $pid" );
+		#kill( 'TERM', $pid );
+	    }
 	    # This was 'TERM', but that didn't get it.
 	    $pid = $$state{ 'hashcashpid' };
 	    logline( "KILL hashcash PID $pid" );
 	    kill( 'KILL', $pid );
 
 	    my $msg = $$state{ 'msg' };
-	    logline( "putting $msg back in queue" );
-	    rename( "$workdir/tmp/$msg", "$workdir/queue/$msg" );
+	    if (-f "$workdir/tmp/$msg") {
+		logline( "putting $msg back in queue" );
+		rename( "$workdir/tmp/$msg", "$workdir/queue/$msg" );
+	    }
 	}
 	# It's tempting to unlink $pidfile here, but it's possible
 	# someone has it open for reading.  If I unlink it, they'll
 	# write to a file that disappears when they close it.
     }
-    exit;
 }
 
 # This looks through premade tokens looking for things that are expired.
openSUSE Build Service is sponsored by