[pve-devel] [PATCH container v2 3/5] setup getty: generalize setup_container_getty_service

Thomas Lamprecht t.lamprecht at proxmox.com
Thu Jul 18 18:37:00 CEST 2019


to allow switching the two remaining users and then finally dropping
the setup_systemd_console method

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---

new in v2

 src/PVE/LXC/Setup/Base.pm | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm
index e0b8244..4880a2b 100644
--- a/src/PVE/LXC/Setup/Base.pm
+++ b/src/PVE/LXC/Setup/Base.pm
@@ -216,26 +216,41 @@ sub fixup_old_getty {
 sub setup_container_getty_service {
     my ($self, $conf) = @_;
 
-    my $systemd_dir_rel = $self->ct_is_executable("/lib/systemd/systemd") ?
+    my $sd_dir = $self->ct_is_executable("/lib/systemd/systemd") ?
 	"/lib/systemd/system" : "/usr/lib/systemd/system";
-    my $servicefile = "$systemd_dir_rel/container-getty\@.service";
-    my $raw = $self->ct_file_get_contents($servicefile);
+
+    # prefer container-getty.service shipped by newer systemd versions
+    # fallback to getty.service and just return if that doesn't exists either..
+    my $service_base = "container-getty\@";
+    my $service = "${service_base}.service";
+    my $template_base = '';
+
+    if (!$self->ct_file_exists("$sd_dir/$service")) {
+	$service_base = "getty\@";
+	$service = "${service_base}.service";
+	$template_base = 'tty';
+	return if !$self->ct_file_exists("$sd_dir/$service");
+    }
+
+    my $raw = $self->ct_file_get_contents("$sd_dir/$service");
     my $ttyname = $self->devttydir($conf) . 'tty%I';
     if ($raw =~ s at pts/%I|lxc/tty%I@$ttyname at g) {
-	$self->ct_file_set_contents($servicefile, $raw);
+	$self->ct_file_set_contents("$sd_dir/$service", $raw);
     }
 
+    my $getty_target_fn = "/etc/systemd/system/getty.target.wants/";
     my $ttycount = PVE::LXC::Config->get_tty_count($conf);
+
     for (my $i = 1; $i < 7; $i++) {
-	my $getty_target_fn = "/etc/systemd/system/getty.target.wants/";
-	my $tty_service_lnk = "$getty_target_fn/container-getty\@$i.service";
-
 	# ensure that not two gettys are using the same tty!
 	$self->ct_unlink("$getty_target_fn/getty\@tty$i.service");
+	$self->ct_unlink("$getty_target_fn/container-getty\@$i.service");
 
-	$self->ct_unlink($tty_service_lnk);
+	# re-enable only those requested
 	if ($i <= $ttycount) {
-	    $self->ct_symlink($servicefile, $tty_service_lnk);
+	    my $tty_service = "${service_base}${template_base}${i}.service";
+
+	    $self->ct_symlink("$sd_dir/$service", "$getty_target_fn/$tty_service");
 	}
     }
 }
-- 
2.20.1





More information about the pve-devel mailing list