summaryrefslogtreecommitdiffstats
path: root/perl-install/standalone/service_harddrake
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/standalone/service_harddrake')
-rwxr-xr-xperl-install/standalone/service_harddrake154
1 files changed, 121 insertions, 33 deletions
diff --git a/perl-install/standalone/service_harddrake b/perl-install/standalone/service_harddrake
index c8abea227..2f30ad707 100755
--- a/perl-install/standalone/service_harddrake
+++ b/perl-install/standalone/service_harddrake
@@ -24,11 +24,22 @@ use harddrake::data;
use harddrake::autoconf;
use harddrake::sound;
use Xconfig::card;
+use Xconfig::various;
use modules;
use Storable qw(store retrieve);
+use run_program;
+
+# timeout runaway processes after 2mn:
+run_program::set_default_timeout(2*60);
my $force = member('--force', @ARGV);
+my $reboot_needed;
+my $do_udev_settle;
+
+my $cmdline = cat_("/proc/cmdline");
+my $noxconf = $cmdline =~ /\bnoxconf\b/;
+my $nokmsboot = $cmdline =~ /\bnokmsboot\b/;
my $invert_do_it = $ARGV[0] eq 'X11' ? 1 : 0;
my ($hw_sysconfdir, $timeout) = ("/etc/sysconfig/harddrake2", $invert_do_it ? 600 : 25);
@@ -54,11 +65,12 @@ my ($kernel_major) = $curr_kernel =~ /^(\d+\.\d+)/;
my %previous_kernel_config = getVarsFromSh("$hw_sysconfdir/kernel");
my %previous_xorg_config = getVarsFromSh("$hw_sysconfdir/xorg");
-setVarsInSh("$hw_sysconfdir/kernel", { KERNEL => $kernel_major, IS_LAPTOP => bool2text($isLaptop) });
+setVarsInSh("$hw_sysconfdir/kernel", { KERNEL => $kernel_major, IS_LAPTOP => bool2text($isLaptop), NOKMSBOOT => $nokmsboot });
my %cfg = getVarsFromSh("$hw_sysconfdir/service.conf");
# default to 'yes' on upgrade:
$cfg{AUTORECONFIGURE_RIGHT_XORG_DRIVER} = 'yes' if !exists $cfg{AUTORECONFIGURE_RIGHT_XORG_DRIVER};
+$cfg{HANDLE_KMS_BOOT_CONFIG} = 'yes' if !exists $cfg{HANDLE_KMS_BOOT_CONFIG};
# autoreconfigure laptop-dependent services when switching from laptop to desktop, and vice versa
if (!exists $previous_kernel_config{IS_LAPTOP} || $force || $isLaptop != text2bool($previous_kernel_config{IS_LAPTOP})) {
@@ -72,6 +84,22 @@ if (!member($curr_kernel, chomp_(cat_($known_kernels)))) {
append_to_file($known_kernels, "$curr_kernel\n");
}
+sub dialog_with_timeout {
+ my ($type, $title, $msg, $timeout, $plymouth) = @_;
+ my ($pid, $res, $timed_out);
+
+ $SIG{ALRM} = sub { $timed_out = 1; kill 15, $pid };
+ unless ($pid = fork()) {
+ $plymouth and system('plymouth', 'hide-splash');
+ exec("/usr/share/harddrake/confirm", $type, $title, $msg);
+ }
+ alarm($timeout);
+ wait();
+ $res = $?;
+ alarm(0);
+ return $res, $timed_out;
+}
+
sub get_xorg_driver() {
my $x = Xconfig::xfree->read;
if ($x) {
@@ -85,7 +113,7 @@ sub schedule_warn_about_switch {
output('/var/run/harddrake-notify-x11-free-driver-switch', $reason);
}
-my $lib = arch() =~ /x86_64/ ? "lib64" : "lib";
+my $lib = get_libdir();
sub find_xorg_driver {
my ($new_driver) = @_;
@@ -94,16 +122,31 @@ sub find_xorg_driver {
|| -e "/usr/$lib/xorg/extra-modules/${new_driver}_drv.so";
}
+sub after_x_driver_switch() {
+ # If a wrong driver is loaded, ask for a reboot.
+ my $reboot_needed = -x "/sbin/display_driver_helper" && system("/sbin/display_driver_helper", "--check-loaded") != 0;
+ if (!$reboot_needed) {
+ # Load any new drivers.
+ system("udevadm", "trigger", "--subsystem-match=pci", "--attr-match=class=0x03*");
+ }
+ $reboot_needed;
+}
+
sub switch_x_driver {
my ($old_driver, $new_driver, $reason) = @_;
if (!find_xorg_driver($new_driver)) {
log::explanations("would switch X.org driver from '$old_driver' to '$new_driver' ($reason); but new driver is not installed");
return;
}
+ # This should use calls to Xconfig instead of substitution. However, currently
+ # Xconfig probably makes too intrusive changes to xorg.conf when switching the driver.
cp_af('/etc/X11/xorg.conf', "/etc/X11/xorg.conf.mga$^T");
- substInFile { s!Driver "($old_driver)"!Driver "$new_driver"!g } '/etc/X11/xorg.conf';
+ substInFile { s!^(\s*Driver\s+)"$old_driver"!$1"$new_driver"!i } '/etc/X11/xorg.conf';
log::explanations("switch X.org driver from '$old_driver' to '$new_driver' ($reason)");
Xconfig::card::libgl_config_and_more({ Driver => $new_driver });
+ my $kms_changed = Xconfig::various::setup_kms();
+
+ after_x_driver_switch() || $kms_changed; # returns 1 if reboot is needed
}
sub should_reconfigure_x_driver {
@@ -115,7 +158,7 @@ sub should_reconfigure_x_driver {
# auto reconfigure x11 only on first time default driver have changed:
if ($previous_xorg_config{XORG_DRV} ne $new_key) {
if (!member($current_driver, $card_data->{Driver}, $card_data->{Driver2}, 'fbdev', 'vesa')) {
- $reason = N("The graphic card '%s' is no more supported by the '%s' driver",
+ $reason = N("The graphics card '%s' is no longer supported by driver '%s'",
$device->{description}, $current_driver);
$reconfigure = 1;
}
@@ -137,7 +180,7 @@ my @cards = (
{
ldetect_driver_regexp => 'Card:NVIDIA',
xorg_driver_regexp => 'nv.+',
- module_names => [ qw(NVdriver nvidia.o nvidia.ko nvidia71xx.ko nvidia96xx.ko nvidia97xx.ko nvidia173.ko nvidia-current.ko) ]
+ module_names => [ qw(nvidia.ko nvidia304.ko nvidia340.ko nvidia390.ko nvidia470.ko nvidia-newfeature.ko nvidia-current.ko) ]
},
{
ldetect_driver_regexp => 'Card:ATI Radeon',
@@ -168,10 +211,19 @@ foreach my $device (@devices) {
# auto reconfigure x11 only on first time default driver have changed:
my ($should_reconfigure, $reason) = should_reconfigure_x_driver($card_data, $device, $current_driver);
if ($should_reconfigure) {
- switch_x_driver($current_driver, $card_data->{Driver}, $reason);
+ if (-e "/tmp/.X11-unix/X0") {
+ # We are too late, X server is already running.
+ # It was probably speedboot, disable it for next boot.
+ substInFile { s!^$curr_kernel .*\n!! } "/var/lib/speedboot/status" if -e "/var/lib/speedboot/status";
+ # Restore state as we were not able to switch the driver yet.
+ setVarsInSh("$hw_sysconfdir/xorg", { XORG_DRV => $previous_xorg_config{XORG_DRV} });
+ } else {
+ $reboot_needed |= switch_x_driver($current_driver, $card_data->{Driver}, $reason);
+ $do_udev_settle = 1;
schedule_warn_about_switch($reason) if any { $current_driver =~ $_->{xorg_driver_regexp} } @cards;
# Update $current_driver with the new one
$current_driver = $card_data->{Driver};
+ }
}
# nv->nouveau or non_kms_nouveau->kms_nouveau can't have "Disable dri"!
@@ -192,7 +244,7 @@ foreach my $card (@cards) {
next if !$device;
if (find { -e join('', "/lib/modules/", c::kernel_version(), $_) }
- map { ("/dkms/$_", "/dkms-binary/$_", "/kernel/$_") } map { "/drivers/$_" } map { ("extra/$_", "video/$_", "char/$_", "char/drm/$_") } map { $_, "$_.gz" } @{$card->{module_names}}) {
+ map { ("/dkms/$_", "/dkms-binary/$_", "/kernel/$_") } map { "/drivers/$_" } map { ("extra/$_", "video/$_", "char/$_", "char/drm/$_") } map { $_, "$_.xz", "$_.gz" } @{$card->{module_names}}) {
# do not automatically switch from nv to nvidia (in order to handle
# cases where nvidia module crashes the system):
@@ -207,9 +259,10 @@ foreach my $card (@cards) {
my $driver = $cards[0]{Driver};
my $old_driver = cat_('/etc/X11/xorg.conf') =~ /Driver "($card->{xorg_driver_regexp})"/ && $1;
if ($old_driver) {
- my $reason = N("The proprietary kernel driver was not found for '%s' X.org driver",
+ my $reason = N("The proprietary kernel driver was not found for X.org driver '%s'",
$old_driver);
- switch_x_driver($card->{xorg_driver_regexp}, $driver, $reason);
+ $reboot_needed |= switch_x_driver($card->{xorg_driver_regexp}, $driver, $reason);
+ $do_udev_settle = 1;
schedule_warn_about_switch($reason);
}
}
@@ -219,8 +272,7 @@ my $is_globetrotter = -f '/usr/sbin/mdkmove';
my (%config, $wait);
my $in;
-my $splash = -f '/proc/splash';
-my $splash_was_silent = cat_('/proc/splash') =~ /, silent : on/;
+my $plymouth = -x '/bin/plymouth';
# For each hw, class, detect device, compare and offer to reconfigure if needed
foreach my $hw_class (@harddrake::data::tree) {
@@ -260,7 +312,13 @@ foreach my $hw_class (@harddrake::data::tree) {
$modules_conf->write;
}
- @added || @was_removed or $cfg{"DETECT_$Ident"} ne 'force' and next;
+ # When using the Live ISOs, the proprietary driver is enabled or disabled according to which boot
+ # menu entry is selected. We can use the presence or absence of "nokmsboot" to detect which was
+ # selected. If persistence is enabled, we must force a reconfiguration if the selection changes.
+ my $force_xconf = $Ident eq 'VIDEO' && -e '/run/mgalive/persistent'
+ && $nokmsboot != $previous_kernel_config{NOKMSBOOT};
+
+ @added || @was_removed || $force_xconf or $cfg{"DETECT_$Ident"} ne 'force' and next;
next if $Ident eq 'MOUSE' && $kernel_major ne $previous_kernel_config{KERNEL} && $cfg{"DETECT_$Ident"} ne 'force';
@@ -272,15 +330,9 @@ foreach my $hw_class (@harddrake::data::tree) {
harddrake::sound::configure_sound_slots($modules_conf);
next;
} elsif ($Ident eq "ETHERNET") {
- $modules_conf->remove_alias_regexp('^(wlan|eth)[0-9]*$');
- modules::load_category($modules_conf, 'network/main|gigabit|usb|wireless|firewire|pcmcia');
- require network::connection::ethernet;
- network::connection::ethernet::configure_eth_aliases($modules_conf);
- require network::rfswitch;
- network::rfswitch::configure();
- require network::shorewall;
- network::shorewall::update_interfaces_list();
- $modules_conf->write;
+ require interactive;
+ $in ||= interactive->vnew;
+ harddrake::autoconf::network_conf($modules_conf, $in, [ @ID{@added} ]);
next;
} elsif (member($Ident, qw(ATA_STORAGE CARD_READER RAID_STORAGE SATA_STORAGE SCSI_CONTROLLER))) {
# set scsi_hostadapter in modprobe.conf:
@@ -315,8 +367,13 @@ foreach my $hw_class (@harddrake::data::tree) {
modules::load_category($modules_conf, 'bus/usb');
$modules_conf->write;
} elsif ($Ident eq "VIDEO") {
+ # Once an xorg.conf has been created, continue to use it, even if "noxconf" is specified. This
+ # allows the user to switch back to the free driver without uninstalling the proprietary driver.
+ next if $noxconf && !($force_xconf || -f '/etc/X11/xorg.conf');
# explicitely NOT read the existing config (eg: new profile with globetrotter)
harddrake::autoconf::xconf($modules_conf, {}, member($cfg{SETUP_FB}, qw(NO no)), $cfg{RESOLUTION_WANTED});
+ $reboot_needed |= after_x_driver_switch();
+ $do_udev_settle = 1;
next;
} elsif ($Ident eq "MOUSE") {
harddrake::autoconf::mouse_conf($modules_conf);
@@ -333,19 +390,12 @@ foreach my $hw_class (@harddrake::data::tree) {
log::explanations(qw(skip $Ident configuration since "$configurator" is not executable));
next;
}
- my ($pid, $no, $res);
+ my ($no, $res);
$hw_class->{automatic} ||= ref($configurator) eq 'CODE';
if (!$hw_class->{automatic}) {
- $SIG{ALRM} = sub { $no = 1; kill 15, $pid };
- unless ($pid = fork()) {
- $splash and eval { output('/proc/splash', 'verbose') } and $splash = 0;
- exec("/usr/share/harddrake/confirm", $Ident, $timeout, $msg);
- }
- alarm($timeout);
- wait();
- $res = $?;
- alarm(0);
+ ($res, $no) = dialog_with_timeout("yesorno", N("Hardware changes in \"%s\" class (%s seconds to answer)", $Ident, $timeout),
+ $msg . N("Do you want to run the appropriate config tool?"), $timeout, $plymouth);
} else {
$res = 1;
}
@@ -379,8 +429,46 @@ foreach my $hw_class (@harddrake::data::tree) {
log::explanations("created file $last_boot_config");
Storable::store(\%config, $last_boot_config);
-# restore bootsplash mode
-$splash_was_silent and eval { output('/proc/splash', 'silent') };
+if (!$reboot_needed && text2bool($cfg{HANDLE_KMS_BOOT_CONFIG})) {
+ if (-x "/sbin/display_driver_helper" && system("display_driver_helper", "--check-loaded") != 0) {
+ # incorrect driver is loaded, X.org can't start (e.g. proprietary driver loaded while free driver in use,
+ # or free driver loaded while vesa is configured).
+ my $kms_changed = Xconfig::various::setup_kms();
+ $reboot_needed |= $kms_changed;
+ if (!$reboot_needed) {
+ my $kms_allowed = system("display_driver_helper", "--is-kms-allowed") == 0;
+ if (!$kms_allowed && !$nokmsboot) {
+ # Wrong driver loaded and boot parameters incorrect, but fixing the
+ # bootloader configuration failed.
+ # Possibly a direct boot from another bootloader.
+ dialog_with_timeout("warn", N("Display driver issue"),
+ N("The display driver currently configured requires you to use the 'nokmsboot' boot option to prevent the KMS driver of the kernel from being loaded in the boot process. Startup of the X server may now fail as that option was not specified."),
+ 60, $plymouth);
+ } else {
+ # Wrong driver loaded even while boot parameters were correct.
+ dialog_with_timeout("warn", N("Display driver issue"),
+ N("Detected a loaded display driver kernel module which conflicts with the driver the X server is configured to use. Startup of the X server may now fail."),
+ 60, $plymouth);
+ }
+ }
+ } elsif (-e "/dev/.late_kms") {
+ # initrd didn't load the KMS driver; non-fatal but ugly, fix it for next boot
+ unlink("/dev/.late_kms");
+ Xconfig::various::setup_kms();
+ }
+}
+
+# Handle $reboot_needed from earlier:
+my ($reply, $timedout);
+# Don't do autoreboot if X was somehow already started (not normally the case).
+if ($reboot_needed && ! -e "/tmp/.X11-unix/X0") {
+ ($reply, $timedout) = dialog_with_timeout("okcancel", N("Display driver setup"), N("The system has to be rebooted due to a display driver change.") . "\n\n"
+ . N("Press Cancel within %d seconds to abort.", 30), 30, $plymouth);
+ if ($reply || $timedout) {
+ exec("/bin/reboot");
+ }
+}
+system("udevadm", "settle", "--timeout=10") if $do_udev_settle;
$in->exit(0) if $in;