+sub run_subprocess {
+ my ($proc, @args) = @_;
+
+ my $pid = POSIX::fork();
+ if ($pid == 0) {
+ my $null = POSIX::open("/dev/null", POSIX::O_RDWR);
+ POSIX::dup2($null, 0);
+ POSIX::dup2($null, 1);
+ POSIX::dup2($null, 2);
+ exec $proc, @args;
+ die "Could not exec $proc: $!";
+ }
+ waitpid($pid, 0);
+ my $s = $? >> 8;
+ debug("$proc exited with code $s: $!");
+}
+
+sub do_amcleanup {
+ my $self = shift;
+
+ return 1 unless -f $self->{'trace_log_filename'};
+
+ # logfiles are still around. First, try an amcleanup -p to see if
+ # the actual processes are already dead
+ debug("runing amcleanup -p");
+ run_subprocess("$sbindir/amcleanup", '-p', $self->{'config_name'},
+ $self->{'config_overrides_opts'});
+
+ return 1 unless -f $self->{'trace_log_filename'};
+
+ return 0;
+}
+
+sub bail_already_running() {
+ my $self = shift;
+ my $msg = "An Amanda process is already running - please run amcleanup manually";
+ print "$msg\n";
+ debug($msg);
+ $self->{'exit_cb'}->(1);
+}
+