diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2004-10-27 08:58:09 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2004-10-27 08:58:09 +0000 |
commit | 9d4845f779a1486cf265064b1c8e3c0c5177c197 (patch) | |
tree | 4ab2f7150643a3475d5d1e695fb339925e81444e | |
parent | a3989b83e00b151543953e96886fde51532055f0 (diff) | |
download | drakx-backup-do-not-use-9d4845f779a1486cf265064b1c8e3c0c5177c197.tar drakx-backup-do-not-use-9d4845f779a1486cf265064b1c8e3c0c5177c197.tar.gz drakx-backup-do-not-use-9d4845f779a1486cf265064b1c8e3c0c5177c197.tar.bz2 drakx-backup-do-not-use-9d4845f779a1486cf265064b1c8e3c0c5177c197.tar.xz drakx-backup-do-not-use-9d4845f779a1486cf265064b1c8e3c0c5177c197.zip |
split {get,set}_append() into {get,set}_append_with_key() and {get,set}_append_simple()
-rw-r--r-- | perl-install/any.pm | 18 | ||||
-rw-r--r-- | perl-install/bootloader.pm | 87 | ||||
-rw-r--r-- | perl-install/install_steps.pm | 16 |
3 files changed, 65 insertions, 56 deletions
diff --git a/perl-install/any.pm b/perl-install/any.pm index 0e0392f70..817ffab51 100644 --- a/perl-install/any.pm +++ b/perl-install/any.pm @@ -82,7 +82,7 @@ sub hdInstallPath() { sub install_acpi_pkgs { my ($do_pkgs, $b) = @_; - my $acpi = bootloader::get_append($b, 'acpi') or return; + my $acpi = bootloader::get_append_with_key($b, 'acpi') or return; if (!member($acpi, 'off', 'ht')) { $do_pkgs->install('acpi', 'acpid') if !(-x "$::prefix/usr/bin/acpi" && -x "$::prefix/usr/sbin/acpid") } @@ -228,10 +228,10 @@ sub setupBootloader__general { my ($in, $b, $all_hds, $fstab, $security) = @_; my @method_choices = bootloader::method_choices($fstab); - my $prev_force_acpi = my $force_acpi = bootloader::get_append($b, 'acpi') !~ /off|ht/; - my $prev_force_noapic = my $force_noapic = bootloader::get_append($b, 'noapic'); - my $prev_force_nolapic = my $force_nolapic = bootloader::get_append($b, 'nolapic'); - my $memsize = bootloader::get_append($b, 'mem'); + my $prev_force_acpi = my $force_acpi = bootloader::get_append_with_key($b, 'acpi') !~ /off|ht/; + my $prev_force_noapic = my $force_noapic = bootloader::get_append_simple($b, 'noapic'); + my $prev_force_nolapic = my $force_nolapic = bootloader::get_append_simple($b, 'nolapic'); + my $memsize = bootloader::get_append_with_key($b, 'mem'); my $prev_clean_tmp = my $clean_tmp = any { $_->{mntpoint} eq '/tmp' } @{$all_hds->{special} ||= []}; my $prev_boot = $b->{boot}; @@ -297,15 +297,15 @@ sub setupBootloader__general { $in->do_pkgs->ensure_binary_is_installed('grub', "grub", 1) or return 0; } - bootloader::set_append($b, "mem", $memsize || 0); + bootloader::set_append_with_key($b, mem => $memsize || 0); if ($prev_force_acpi != $force_acpi) { - bootloader::set_append($b, acpi => ($force_acpi ? '' : 'ht')); + bootloader::set_append_with_key($b, acpi => ($force_acpi ? '' : 'ht')); } if ($prev_force_noapic != $force_noapic) { - ($force_noapic ? \&bootloader::set_append : \&bootloader::remove_append_simple)->($b, 'noapic'); + ($force_noapic ? \&bootloader::set_append_simple : \&bootloader::remove_append_simple)->($b, 'noapic'); } if ($prev_force_nolapic != $force_nolapic) { - ($force_nolapic ? \&bootloader::set_append : \&bootloader::remove_append_simple)->($b, 'nolapic'); + ($force_nolapic ? \&bootloader::set_append_simple : \&bootloader::remove_append_simple)->($b, 'nolapic'); } if ($prev_clean_tmp != $clean_tmp) { diff --git a/perl-install/bootloader.pm b/perl-install/bootloader.pm index 4b3cfddf0..d0be63cf4 100644 --- a/perl-install/bootloader.pm +++ b/perl-install/bootloader.pm @@ -510,22 +510,6 @@ sub normalize_append { pack_append($simple, $dict); } -sub append__mem_is_memsize { $_[0] =~ /^\d+[kM]?$/i } - -sub get_append { - my ($b, $key) = @_; - my ($simple, $dict) = unpack_append($b->{perImageAppend}); - if (member($key, @$simple)) { - return 1; - } - my @l = map { $_->[1] } grep { $_->[0] eq $key } @$dict; - - #- suppose we want the memsize - @l = grep { append__mem_is_memsize($_) } @l if $key eq 'mem'; - - log::l("more than one $key in $b->{perImageAppend}") if @l > 1; - $l[0]; -} sub modify_append { my ($b, $f) = @_; @@ -538,6 +522,25 @@ sub modify_append { log::l("modify_append: $$_"); } } + +sub append__mem_is_memsize { $_[0] =~ /^\d+[kM]?$/i } + +sub get_append_simple { + my ($b, $key) = @_; + my ($simple, $_dict) = unpack_append($b->{perImageAppend}); + member($key, @$simple); +} +sub get_append_with_key { + my ($b, $key) = @_; + my ($_simple, $dict) = unpack_append($b->{perImageAppend}); + my @l = map { $_->[1] } grep { $_->[0] eq $key } @$dict; + + #- suppose we want the memsize + @l = grep { append__mem_is_memsize($_) } @l if $key eq 'mem'; + + log::l("more than one $key in $b->{perImageAppend}") if @l > 1; + $l[0]; +} sub remove_append_simple { my ($b, $key) = @_; modify_append($b, sub { @@ -545,34 +548,38 @@ sub remove_append_simple { @$simple = grep { $_ ne $key } @$simple; }); } -sub set_append { - my $has_val = @_ > 2; +sub set_append_with_key { my ($b, $key, $val) = @_; modify_append($b, sub { - my ($simple, $dict) = @_; - if ($has_val) { - my $to_add = $key eq 'mem' ? $val : $val ne ''; - @$dict = map { - if ($_->[0] ne $key || $key eq 'mem' && append__mem_is_memsize($_->[1]) != append__mem_is_memsize($val)) { - $_; - } elsif ($to_add) { - $to_add = 0; - [ $key, $val ]; - } else { - (); - } - } @$dict; + my ($_simple, $dict) = @_; + + my $to_add = $key eq 'mem' ? $val : $val ne ''; + @$dict = map { + if ($_->[0] ne $key || $key eq 'mem' && append__mem_is_memsize($_->[1]) != append__mem_is_memsize($val)) { + $_; + } elsif ($to_add) { + $to_add = 0; + [ $key, $val ]; + } else { + (); + } + } @$dict; - push @$dict, [ $key, $val ] if $to_add; - } else { - @$simple = uniq(@$simple, $key); - } + push @$dict, [ $key, $val ] if $to_add; + }); +} +sub set_append_simple { + my ($b, $key) = @_; + + modify_append($b, sub { + my ($simple, $_dict) = @_; + @$simple = uniq(@$simple, $key); }); } -sub may_append { +sub may_append_with_key { my ($b, $key, $val) = @_; - set_append($b, $key, $val) if !get_append($b, $key); + set_append_with_key($b, $key, $val) if !get_append_with_key($b, $key); } sub get_append_netprofile { @@ -714,7 +721,7 @@ wait for default boot. add2hash_($bootloader, { memsize => $1 }) if cat_("/proc/cmdline") =~ /\bmem=(\d+[KkMm]?)(?:\s.*)?$/; if (my ($s, $port, $speed) = cat_("/proc/cmdline") =~ /console=(ttyS(\d),(\d+)\S*)/) { log::l("serial console $s $port $speed"); - set_append($bootloader, 'console' => $s); + set_append_with_key($bootloader, console => $s); any::set_login_serial_console($port, $speed); } @@ -1025,7 +1032,7 @@ sub write_lilo { push @conf, qq(append="$bootloader->{append}") if $bootloader->{append}; push @conf, "password=" . $bootloader->{password} if $bootloader->{password}; #- also done by msec push @conf, "timeout=" . round(10 * $bootloader->{timeout}) if $bootloader->{timeout}; - push @conf, "serial=" . $1 if get_append($bootloader, 'console') =~ /ttyS(.*)/; + push @conf, "serial=" . $1 if get_append_with_key($bootloader, 'console') =~ /ttyS(.*)/; push @conf, "message=/boot/message" if arch() !~ /ia64/; push @conf, "menu-scheme=wb:bw:wb:bw" if arch() !~ /ia64/; @@ -1190,7 +1197,7 @@ sub write_grub { my @sorted_hds = sort_hds_according_to_bios($bootloader, $all_hds); write_grub_device_map(\@legacy_floppies, \@sorted_hds); - if (get_append($bootloader, 'console') =~ /ttyS(\d),(\d+)/) { + if (get_append_with_key($bootloader, 'console') =~ /ttyS(\d),(\d+)/) { $bootloader->{serial} ||= "--unit=$1 --speed=$2"; $bootloader->{terminal} ||= "--timeout=" . ($bootloader->{timeout} || 0) . " console serial"; } diff --git a/perl-install/install_steps.pm b/perl-install/install_steps.pm index 22f013565..323b8c3b3 100644 --- a/perl-install/install_steps.pm +++ b/perl-install/install_steps.pm @@ -497,7 +497,7 @@ Consoles 1,3,4,7 may also contain interesting information"; $p && $p->flag_installed }; require bootloader; - bootloader::may_append($o->{bootloader}, devfs => $have_devfsd ? 'mount' : 'nomount'); + bootloader::may_append_with_key($o->{bootloader}, devfs => $have_devfsd ? 'mount' : 'nomount'); #- generate /etc/lvmtab needed for rc.sysinit run_program::rooted($o->{prefix}, 'lvm2', 'vgscan') if -e '/etc/lvmtab'; @@ -848,13 +848,13 @@ sub setupBootloaderBefore { }); if ($o->{miscellaneous}{HDPARM}) { - bootloader::set_append($o->{bootloader}, $_, 'autotune') foreach grep { /ide/ } all("/proc/ide"); + bootloader::set_append_with_key($o->{bootloader}, $_, 'autotune') foreach grep { /ide/ } all("/proc/ide"); } if (cat_("/proc/cmdline") =~ /mem=nopentium/) { - bootloader::set_append($o->{bootloader}, mem => 'nopentium'); + bootloader::set_append_with_key($o->{bootloader}, mem => 'nopentium'); } if (cat_("/proc/cmdline") =~ /\b(pci)=(\S+)/) { - bootloader::set_append($o->{bootloader}, $1, $2); + bootloader::set_append_with_key($o->{bootloader}, $1, $2); } if (my ($acpi) = cat_("/proc/cmdline") =~ /\bacpi=(\w+)/) { if ($acpi eq 'ht') { @@ -865,15 +865,17 @@ sub setupBootloaderBefore { $acpi = 'on'; } } - bootloader::set_append($o->{bootloader}, acpi => $acpi); + bootloader::set_append_with_key($o->{bootloader}, acpi => $acpi); } if (cat_("/proc/cmdline") =~ /\bnoapic/) { - bootloader::set_append($o->{bootloader}, 'noapic'); + bootloader::set_append_simple($o->{bootloader}, 'noapic'); } my ($MemTotal) = cat_("/proc/meminfo") =~ /^MemTotal:\s*(\d+)/m; if (my ($biggest_swap) = sort { $b->{size} <=> $a->{size} } grep { isSwap($_) } @{$o->{fstab}}) { log::l("MemTotal: $MemTotal < ", $biggest_swap->{size} / 2); - bootloader::set_append($o->{bootloader}, resume => devices::make($biggest_swap->{device})) if $MemTotal < $biggest_swap->{size} / 2; + if ($MemTotal < $biggest_swap->{size} / 2) { + bootloader::set_append_with_key($o->{bootloader}, resume => devices::make($biggest_swap->{device})); + } } #- check for valid fb mode to enable a default boot with frame buffer. |