+sub exit_status($) {
+ my ($s) = @_;
+ if ($s >> 8) {
+ return "with exit code " . ($s >> 8);
+ } else {
+ return "on fatal signal " . ($s & 127);
+ }
+}
+
+sub run_job_prep($$$) {
+ my ($job, $queue, $mach) = @_;
+ my $prep = $job->attr('Prep');
+ defined($prep) && $prep !~ /^\s*$/ or return 'OK';
+
+ my $jid = $job->id;
+ update_status($mach, $jid, 'PREP', $queue);
+ my $lf = $queue->log_file($mach, $jid);
+ $ENV{'HOST'} = BEX::Config::host_name($mach);
+ system 'bash', '-o', 'pipefail', '-c', "( $prep ) 2>&1 | tee -a $lf";
+ delete $ENV{'HOST'};
+ if ($?) {
+ return ('PREPFAIL', 'Preparatory command failed ' . exit_status($?));
+ } else {
+ return 'OK';
+ }
+}
+
+sub run_job_body($$$) {