Skip to content

Commit

Permalink
Merge pull request #1705 from ulrich1919/ncm_grub_pxeboot_check_sys_f…
Browse files Browse the repository at this point in the history
…irmware_efi

Fixes #1704: ncm-grub::pxeboot return SUCCESS on non-UEFI systems
  • Loading branch information
jrha authored Sep 5, 2024
2 parents cd8f69d + d5b986b commit 7b750c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ncm-grub/src/main/perl/grub.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Readonly my $GRUB2_USER_CFG => "$GRUB2_DIR/user.cfg";
Readonly my $GRUBBY => '/sbin/grubby';
Readonly my $PREFIX => '/boot';
Readonly my $EFIBOOTMGR => '/sbin/efibootmgr';
Readonly my $SYS_FIRMWARE_EFI => '/sys/firmware/efi';
Readonly::Hash my %SERIAL_CONSOLE_DEFAULTS => {
unit => 0,
speed => 9600,
Expand Down Expand Up @@ -894,6 +895,11 @@ sub pxeboot
return SUCCESS;
}

if (!$self->directory_exists($SYS_FIRMWARE_EFI)) {
$self->info("pxeboot: no $SYS_FIRMWARE_EFI found. Not doing anything");
return SUCCESS;
}

my $efi = CAF::Process->new([$EFIBOOTMGR, '-v'], log => $self, keeps_state => 1)->output();
if (!$efi) {
$self->error("No output from $EFIBOOTMGR");
Expand Down
7 changes: 6 additions & 1 deletion ncm-grub/src/test/perl/methods.t
Original file line number Diff line number Diff line change
Expand Up @@ -405,21 +405,26 @@ ok(command_history_ok([
=cut

my $ebm = '/sbin/efibootmgr';
my $sfe = '/sys/firmware/efi';
command_history_reset();
ok (!$cmp->file_exists($ebm), "efibootmgr does not exist");
ok($cmp->pxeboot(), "pxeboot returns success when efibootmgr is missing");
ok(command_history_ok(undef, ['']), "No commands were run when efibootmgr is missing");
ok (!$cmp->directory_exists($sfe), "/sys/firmware/efi does not exist");
ok($cmp->pxeboot(), "pxeboot returns success when /sys/firmware/efi is missing");
ok(command_history_ok(undef, ['']), "No commands were run when /sys/firmware/efi is missing");

$mock->mock('directory_exists', 1);
set_file_contents($ebm, '');
set_desired_output("$ebm -v", "$EFIBOOTMGROUT");
ok ($cmp->file_exists($ebm), "efibootmgr does exist");
ok($cmp->pxeboot(), "pxeboot returns success");
$mock->unmock('directory_exists');
ok(command_history_ok([
"$ebm -v",
"$ebm -o 4,3,2",
]), "efibootmgr called, correct bootorder set");


=head1 sanitize_arguments
=cut
Expand Down

0 comments on commit 7b750c4

Please sign in to comment.