Fix start_unit reporting success when journalctl lookup follows a failed start

This commit is contained in:
Ilia Ross
2026-09-29 22:24:52 +02:00
parent bbdd520807
commit 9458057978
2 changed files with 12 additions and 2 deletions

View File

@@ -585,10 +585,11 @@ my ($name) = @_;
return (0, $text{'systemd_ename'}) if (!valid_unit_name($name));
my $out = backquote_logged(
"systemctl start ".quotemeta($name)." 2>&1 </dev/null");
if ($? && $out =~ /journalctl/) {
my $rv = $?;
if ($rv && $out =~ /journalctl/) {
$out .= backquote_command("journalctl -xe 2>/dev/null");
}
return (!$?, $out);
return (!$rv, $out);
}
=head2 stop_unit(name)

View File

@@ -846,6 +846,15 @@ like(get_unit_root(), qr{^/(etc|usr/lib|lib)/systemd/system$},
'dependency command uses full non-paged output');
}
# Failed starts must remain failures even when journal diagnostics succeed.
{
local *main::backquote_logged = sub { $? = 256; return 'See journalctl for details'; };
local *main::backquote_command = sub { $? = 0; return 'Start failed'; };
my ($ok, $out) = start_unit('broken.service');
ok(!$ok, 'journal lookup cannot hide a failed start');
like($out, qr/Start failed/, 'failed start includes diagnostics');
}
{
my @cmds;
my $reloaded = 0;