diff options
author | Jörg Thalheim <Mic92@users.noreply.github.com> | 2023-05-04 09:48:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-04 09:48:41 +0100 |
commit | be8e3128b906f09936f2eb2b1812acabb39c2907 (patch) | |
tree | 3c99dbfda12c52bfbce48ece610a54f24f3c0ec1 /nixos/modules/system/boot/loader | |
parent | 738bf261ad499471033533ba38096ecc3ba70ee9 (diff) | |
parent | d9c92360a8454c6735b0a53e49fdedaa69862162 (diff) | |
download | nixpkgs-be8e3128b906f09936f2eb2b1812acabb39c2907.tar nixpkgs-be8e3128b906f09936f2eb2b1812acabb39c2907.tar.gz nixpkgs-be8e3128b906f09936f2eb2b1812acabb39c2907.tar.bz2 nixpkgs-be8e3128b906f09936f2eb2b1812acabb39c2907.tar.lz nixpkgs-be8e3128b906f09936f2eb2b1812acabb39c2907.tar.xz nixpkgs-be8e3128b906f09936f2eb2b1812acabb39c2907.tar.zst nixpkgs-be8e3128b906f09936f2eb2b1812acabb39c2907.zip |
Merge pull request #223418 from Mic92/grub
nixos/grub-install: don't rely on shell to run commands
Diffstat (limited to 'nixos/modules/system/boot/loader')
-rw-r--r-- | nixos/modules/system/boot/loader/grub/install-grub.pl | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/nixos/modules/system/boot/loader/grub/install-grub.pl b/nixos/modules/system/boot/loader/grub/install-grub.pl index aea426c7fdf..2779f26aa1b 100644 --- a/nixos/modules/system/boot/loader/grub/install-grub.pl +++ b/nixos/modules/system/boot/loader/grub/install-grub.pl @@ -34,23 +34,29 @@ sub getList { } sub readFile { - my ($fn) = @_; local $/ = undef; - open FILE, "<$fn" or return undef; my $s = <FILE>; close FILE; - local $/ = "\n"; chomp $s; return $s; + my ($fn) = @_; + # enable slurp mode: read entire file in one go + local $/ = undef; + open my $fh, "<$fn" or return undef; + my $s = <$fh>; + close $fh; + # disable slurp mode + local $/ = "\n"; + chomp $s; + return $s; } sub writeFile { my ($fn, $s) = @_; - open FILE, ">$fn" or die "cannot create $fn: $!\n"; - print FILE $s or die; - close FILE or die; + open my $fh, ">$fn" or die "cannot create $fn: $!\n"; + print $fh $s or die "cannot write to $fn: $!\n"; + close $fh or die "cannot close $fn: $!\n"; } sub runCommand { - my ($cmd) = @_; - open FILE, "$cmd 2>/dev/null |" or die "Failed to execute: $cmd\n"; - my @ret = <FILE>; - close FILE; + open(my $fh, "-|", @_) or die "Failed to execute: $@_\n"; + my @ret = $fh->getlines(); + close $fh; return ($?, @ret); } @@ -200,7 +206,7 @@ sub GrubFs { $search = $types{$fsIdentifier} . ' '; # Based on the type pull in the identifier from the system - my ($status, @devInfo) = runCommand("@utillinux@/bin/blkid -o export @{[$fs->device]}"); + my ($status, @devInfo) = runCommand("@utillinux@/bin/blkid", "-o", "export", @{[$fs->device]}); if ($status != 0) { die "Failed to get blkid info (returned $status) for @{[$fs->mount]} on @{[$fs->device]}"; } @@ -213,7 +219,7 @@ sub GrubFs { # BTRFS is a special case in that we need to fix the referrenced path based on subvolumes if ($fs->type eq 'btrfs') { - my ($status, @id_info) = runCommand("@btrfsprogs@/bin/btrfs subvol show @{[$fs->mount]}"); + my ($status, @id_info) = runCommand("@btrfsprogs@/bin/btrfs", "subvol", "show", @{[$fs->mount]}); if ($status != 0) { die "Failed to retrieve subvolume info for @{[$fs->mount]}\n"; } @@ -221,7 +227,7 @@ sub GrubFs { if ($#ids > 0) { die "Btrfs subvol name for @{[$fs->device]} listed multiple times in mount\n" } elsif ($#ids == 0) { - my ($status, @path_info) = runCommand("@btrfsprogs@/bin/btrfs subvol list @{[$fs->mount]}"); + my ($status, @path_info) = runCommand("@btrfsprogs@/bin/btrfs", "subvol", "list", @{[$fs->mount]}); if ($status != 0) { die "Failed to find @{[$fs->mount]} subvolume id from btrfs\n"; } |