[pve-devel] [PATCH container 1/2] setup getty: ensure the correct services are enabled

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Jul 17 12:08:24 CEST 2019


I.e., some distro templates do not have anything enabled, thus also
ensure that the respective container-getty@ services are enabled.

But, as to getty on the same TTY makes for a strange experience also
ensure that the getty@ are all removed (and vice versa in the other
case)

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 src/PVE/LXC/Setup/Base.pm | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm
index f5f8b0d..5ec78a0 100644
--- a/src/PVE/LXC/Setup/Base.pm
+++ b/src/PVE/LXC/Setup/Base.pm
@@ -185,7 +185,12 @@ sub setup_systemd_console {
     my $ttycount = PVE::LXC::Config->get_tty_count($conf);
 
     for (my $i = 1; $i < 7; $i++) {
-	my $tty_service_lnk = "/etc/systemd/system/getty.target.wants/getty\@tty$i.service";
+	my $getty_target_fn = "/etc/systemd/system/getty.target.wants/";
+	my $tty_service_lnk = "$getty_target_fn/getty\@tty$i.service";
+
+	# ensure that not two gettys are using the same tty!
+	$self->ct_unlink("$getty_target_fn/container-getty\@$i.service");
+
 	if ($i > $ttycount) {
 	    $self->ct_unlink($tty_service_lnk);
 	} else {
@@ -210,11 +215,30 @@ sub setup_container_getty_service {
     my $systemd_dir_rel = $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);
     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);
     }
+
+    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\@$i.service");
+
+	if ($i > $ttycount) {
+	    $self->ct_unlink($tty_service_lnk);
+	} else {
+	    if (!$self->ct_is_symlink($tty_service_lnk)) {
+		$self->ct_unlink($tty_service_lnk);
+		$self->ct_symlink($servicefile, $tty_service_lnk);
+	    }
+	}
+    }
 }
 
 sub setup_systemd_networkd {
-- 
2.20.1





More information about the pve-devel mailing list