[pve-devel] [PATCH pve-container] update inittab instead of replacing it

Dietmar Maurer dietmar at proxmox.com
Wed Oct 14 15:55:48 CEST 2015



> On October 14, 2015 at 2:48 PM Wolfgang Bumiller <w.bumiller at proxmox.com>
> wrote:
> 
> 
> ---
>  src/PVE/LXC/Setup/Base.pm   |  6 ++---
>  src/PVE/LXC/Setup/Debian.pm | 61
> ++++++++++++++++++++++++++++++++++-----------
>  2 files changed, 49 insertions(+), 18 deletions(-)
> 
> diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm
> index ba7453d..9a39468 100644
> --- a/src/PVE/LXC/Setup/Base.pm
> +++ b/src/PVE/LXC/Setup/Base.pm
> @@ -191,7 +191,7 @@ sub setup_network {
>  }
>  
>  sub setup_init {
> -    my ($self, $conf) = @_;
> +    my ($self, $conf, $creation) = @_;
>  
>      die "please implement this inside subclass"
>  }
> @@ -454,7 +454,7 @@ sub rewrite_ssh_host_keys {
>  sub pre_start_hook {
>      my ($self, $conf) = @_;
>  
> -    $self->setup_init($conf);
> +    $self->setup_init($conf, 0);
>      $self->setup_network($conf);
>      $self->set_hostname($conf);
>      $self->set_dns($conf);
> @@ -470,7 +470,7 @@ sub post_create_hook {
>      &$randomize_crontab($self, $conf);
>      
>      $self->set_user_password($conf, 'root', $root_password);
> -    $self->setup_init($conf);
> +    $self->setup_init($conf, 1);
>      $self->setup_network($conf);
>      $self->set_hostname($conf);
>      $self->set_dns($conf);
> diff --git a/src/PVE/LXC/Setup/Debian.pm b/src/PVE/LXC/Setup/Debian.pm
> index 1b2a277..068d155 100644
> --- a/src/PVE/LXC/Setup/Debian.pm
> +++ b/src/PVE/LXC/Setup/Debian.pm
> @@ -77,26 +77,57 @@ p0::powerfail:/sbin/init 0
>  __EOD__
>  
>  sub setup_init {
> -    my ($self, $conf) = @_;
> +    my ($self, $conf, $creation) = @_;
>  
>      my $filename = "/etc/inittab";
> +    return if !$self->ct_file_exists($filename);
>  
> -    if ($self->ct_file_exists($filename)) {
> -	my $inittab = $default_inittab;
> -
> -	my $ttycount =  PVE::LXC::get_tty_count($conf);
> -	for (my $i = 1; $i <= $ttycount; $i++) {
> -	    next if $i == 7; # reserved for X11
> -	    my $levels = ($i == 1) ? '2345' : '23';
> -	    if ($self->{version} < 7) {
> -		$inittab .= "$i:$levels:respawn:/sbin/getty -L 38400 tty$i\n";
> -	    } else {
> -		$inittab .= "$i:$levels:respawn:/sbin/getty --noclear 38400 tty$i\n";
> -	    }
> +    my $ttycount =  PVE::LXC::get_tty_count($conf);
> +    my $inittab = $creation ? $default_inittab :
> $self->ct_file_get_contents($filename);

Why do we want to overwrite an existing file with $default_inittab ?




More information about the pve-devel mailing list