@@ -382,9 +382,17 @@ sub waitForUnit {
382382 my $state = $info->{ActiveState};
383383 die "unit ‘$unit’ reached state ‘$state’\n" if $state eq "failed";
384384 if ($state eq "inactive") {
385+ # If there are no pending jobs, then assume this unit
386+ # will never reach active state.
385387 my ($status, $jobs) = $self->execute("systemctl list-jobs --full 2>&1");
386− die "unit ‘$unit’ is inactive and there are no pending jobs\n"
387− if $jobs =~ /No jobs/; # FIXME: fragile
388+ if ($jobs =~ /No jobs/) { # FIXME: fragile
389+ # Handle the case where the unit may have started
390+ # between the previous getUnitInfo() and
391+ # list-jobs.
392+ my $info2 = $self->getUnitInfo($unit);
393+ die "unit ‘$unit’ is inactive and there are no pending jobs\n"
394+ if $info2->{ActiveState} eq $state;
395+ }
388396 }
389397 return 1 if $state eq "active";
390398 };