diff options
-rw-r--r-- | installer/OpenSLX/OSSetup/Distro/Base.pm | 67 | ||||
-rw-r--r-- | installer/OpenSLX/OSSetup/Engine.pm | 37 | ||||
-rw-r--r-- | lib/OpenSLX/Syscall.pm | 56 |
3 files changed, 97 insertions, 63 deletions
diff --git a/installer/OpenSLX/OSSetup/Distro/Base.pm b/installer/OpenSLX/OSSetup/Distro/Base.pm index d2931046..39572e5d 100644 --- a/installer/OpenSLX/OSSetup/Distro/Base.pm +++ b/installer/OpenSLX/OSSetup/Distro/Base.pm @@ -20,6 +20,7 @@ our $VERSION = 1.01; # API-version . implementation-version use Fcntl qw(:DEFAULT :flock); use File::Basename; +use File::Path; use OpenSLX::Basics; use OpenSLX::Utils; @@ -126,9 +127,13 @@ sub startSession "slxos-setup::distro::chroot", sub { $self->finishSession(); } ); + # setup a fixed locale environment to avoid warnings about unset locales + # (like for instance shown by apt-get) + $ENV{LC_ALL} = 'POSIX'; + # make sure there's a /dev/zero, /dev/null and /dev/urandom # /dev/urandom for passwd chroot - if (!-e "$osDir/dev" && !mkdir("$osDir/dev")) { + if (!-e "$osDir/dev" && !mkpath("$osDir/dev")) { die _tr("unable to create folder '%s' (%s)\n", "$osDir/dev", $!); } if (!-e "$osDir/dev/zero" && slxsystem("mknod $osDir/dev/zero c 1 5")) { @@ -141,30 +146,36 @@ sub startSession die _tr("unable to create node '%s' (%s)\n", "$osDir/dev/urandom", $!); } - - # fake proc, depending on what is needed ... - if (!-e "$osDir/proc" && !mkdir("$osDir/proc")) { - die _tr("unable to create folder '%s' (%s)\n", "$osDir/proc", $!); - } - if (!-e "$osDir/proc/cpuinfo" && slxsystem("cp /proc/cpuinfo $osDir/proc/")) { - die _tr("unable to copy file '%s' (%s)\n", "/proc/cpuinfo", $!); - } - # TODO: alternatively, we could mount proc, but that causes problems - # when we are not able to umount it properly (which may happen - # if 'umount' is not available in the chroot!) - # - # mount /proc -# if (!-e "$osDir/proc") { -# slxsystem("mkdir -p $osDir/proc"); -# } -# if (slxsystem("mount -t proc proc $osDir/proc 2>/dev/null")) { -# die _tr("unable to mount '%s' (%s)\n", "$osDir/proc", $!); -# } - # enter chroot jail chrootInto($osDir); $ENV{PATH} = join(':', @{$self->getDefaultPathList()}); + # mount /proc (if we have 'mount' available) + if (qx{which mount 2>/dev/null}) { + if (!-e "$osDir/proc" && !mkpath("$osDir/proc")) { + die _tr("unable to create folder '%s' (%s)\n", "$osDir/proc", $!); + } + if (slxsystem("mount -t proc proc '/proc'")) { + warn _tr("unable to mount '%s' (%s)\n", "$osDir/proc", $!); + } + } + + return; +} + +sub finishSession +{ + my $self = shift; + + removeCleanupFunction('slxos-setup::distro::chroot'); + + # umount /proc (if we have 'umount' available) + if (qx{which umount 2>/dev/null}) { + if (slxsystem("umount /proc")) { + warn _tr("unable to umount '%s' (%s)\n", "/proc", $!); + } + } + return; } @@ -186,20 +197,6 @@ sub getDefaultPathList ) ]; } -sub finishSession -{ - my $self = shift; - - removeCleanupFunction('slxos-setup::distro::chroot'); - - # unmount /proc -# if (slxsystem('ash', '-c', 'umount /proc 2>/dev/null')) { -# die _tr("unable to unmount '%s' (%s)\n", "/proc", $!); -# } - - return; -} - sub updateDistroConfig { if (slxsystem("ldconfig")) { diff --git a/installer/OpenSLX/OSSetup/Engine.pm b/installer/OpenSLX/OSSetup/Engine.pm index 9030beaa..9518c74a 100644 --- a/installer/OpenSLX/OSSetup/Engine.pm +++ b/installer/OpenSLX/OSSetup/Engine.pm @@ -31,6 +31,7 @@ use File::Basename; use URI; use OpenSLX::Basics; +use OpenSLX::Syscall; use OpenSLX::Utils; use vars qw(%supportedDistros); @@ -1521,8 +1522,13 @@ sub _setupStage1D $self->_stage1D_setupPackageSources(); $self->_stage1D_updateBasicVendorOS(); $self->{distro}->preSystemInstallationHook(); - $self->_stage1D_installPackageSelection(); + my $ok = eval { + $self->_stage1D_installPackageSelection(); + 1; + }; + my $err = $ok ? undef : $@; $self->{distro}->postSystemInstallationHook(); + die $err if defined $err; }, updateConfig => 1, }); @@ -1576,7 +1582,7 @@ sub _callChrootedFunction 'updateConfig' => '?', }); - $self->{'distro'}->startSession($params->{chrootDir}); + $self->{distro}->startSession($params->{chrootDir}); # invoke given function: $params->{function}->(); @@ -1757,36 +1763,11 @@ sub _changePersonalityIfNeeded my $distroName = $self->{'distro-name'}; if ($self->_hostIs64Bit() && $distroName !~ m[_64]) { - # trying to handle a 32-bit vendor-OS on a 64-bit machine, so we change - # the personality accordingly (from 64-bit to 32-bit): - $self->_loadPerlHeader('syscall.ph') - or die _tr("unable to load perl header '%s'\n", 'syscall.ph'); - $self->_loadPerlHeader('linux/personality.ph') - || $self->_loadPerlHeader('sys/personality.ph') - or die _tr("unable to load perl header '%s'\n", 'personality.ph'); - - syscall &SYS_personality, PER_LINUX32(); + OpenSLX::Syscall->enter32BitPersonality(); } return; } -sub _loadPerlHeader -{ - my $self = shift; - my $phFile = shift; - - if (!eval { require $phFile }) { - # perl-header has not been provided by host-OS, so we create it - # manually from C-header (via h2ph): - (my $hFile = $phFile) =~ s{\.ph$}{.h}; - return if !-e "/usr/include/$hFile"; - my $libDir = "$openslxConfig{'base-path'}/lib"; - slxsystem("cd /usr/include && h2ph -d $libDir $hFile") == 0 - or die _tr("unable to create %s! (%s)", $phFile, $!); - } - return eval { require $phFile; 1 }; -} - sub _hostIs64Bit { my $self = shift; diff --git a/lib/OpenSLX/Syscall.pm b/lib/OpenSLX/Syscall.pm new file mode 100644 index 00000000..58eb683d --- /dev/null +++ b/lib/OpenSLX/Syscall.pm @@ -0,0 +1,56 @@ +# Copyright (c) 2008 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# PerlHeaders.pm +# - provides automatic generation of required perl headers (for syscalls) +# ----------------------------------------------------------------------------- +package OpenSLX::Syscall; + +use strict; +use warnings; + +our $VERSION = 1.01; + +use OpenSLX::Basics; + +sub _loadPerlHeader +{ + my @phFiles = @_; + + for my $phFile (@phFiles) { + if (!eval { require $phFile }) { + # perl-header has not been provided by host-OS, so we create it + # manually from C-header (via h2ph): + (my $hFile = $phFile) =~ s{\.ph$}{.h}; + if (-e "/usr/include/$hFile") { + my $libDir = "$openslxConfig{'base-path'}/lib"; + slxsystem("cd /usr/include && h2ph -d $libDir $hFile") == 0 + or die _tr('unable to create %s! (%s)', $phFile, $!); + } + } + return 1 if eval { require $phFile; 1 }; + } + die _tr( + 'unable to load any of these perl headers: %s', join(',', @phFiles) + ); +} + +sub enter32BitPersonality +{ + _loadPerlHeader('syscall.ph'); + _loadPerlHeader('linux/personality.ph', 'sys/personality.ph'); + + syscall(&SYS_personality, PER_LINUX32()) != -1 + or die _tr("unable to invoke syscall '%s'! ($!)", 'personality'); + + return; +} + +1; |