]> git.proxmox.com Git - pve-container.git/commitdiff
close #1940: pct console: added ability to specify escape sequence
authorTim Marx <t.marx@proxmox.com>
Tue, 9 Oct 2018 11:34:14 +0000 (13:34 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 9 Oct 2018 12:23:46 +0000 (14:23 +0200)
added clarification about behavior when passing -1 to escapechar
restored former behavior in other uses of get_console_command
added meaningful tag to commit message

Signed-off-by: Tim Marx <t.marx@proxmox.com>
src/PVE/API2/LXC.pm
src/PVE/CLI/pct.pm
src/PVE/LXC.pm

index cbcc3930da7e1f03d6a811eccb2eb949a6595425..6b3395bea1e2d0bbf149fadd5576869b7b97197b 100644 (file)
@@ -733,7 +733,7 @@ __PACKAGE__->register_method ({
            ['/usr/bin/ssh', '-e', 'none', '-t', $remip] : [];
 
        my $conf = PVE::LXC::Config->load_config($vmid, $node);
            ['/usr/bin/ssh', '-e', 'none', '-t', $remip] : [];
 
        my $conf = PVE::LXC::Config->load_config($vmid, $node);
-       my $concmd = PVE::LXC::get_console_command($vmid, $conf, 1);
+       my $concmd = PVE::LXC::get_console_command($vmid, $conf, -1);
 
        my $shcmd = [ '/usr/bin/dtach', '-A',
                      "/var/run/dtach/vzctlconsole$vmid",
 
        my $shcmd = [ '/usr/bin/dtach', '-A',
                      "/var/run/dtach/vzctlconsole$vmid",
@@ -836,7 +836,7 @@ __PACKAGE__->register_method ({
            ['/usr/bin/ssh', '-e', 'none', '-t', $remip, '--'] : [];
 
        my $conf = PVE::LXC::Config->load_config($vmid, $node);
            ['/usr/bin/ssh', '-e', 'none', '-t', $remip, '--'] : [];
 
        my $conf = PVE::LXC::Config->load_config($vmid, $node);
-       my $concmd = PVE::LXC::get_console_command($vmid, $conf, 1);
+       my $concmd = PVE::LXC::get_console_command($vmid, $conf, -1);
 
        my $shcmd = [ '/usr/bin/dtach', '-A',
                      "/var/run/dtach/vzctlconsole$vmid",
 
        my $shcmd = [ '/usr/bin/dtach', '-A',
                      "/var/run/dtach/vzctlconsole$vmid",
index 6296d6fc9aaa3b62d4d0b10ba5e6a1a45723d9f5..9d3a2301ff3b6a6da61bde3064188d6609cd68e5 100755 (executable)
@@ -119,6 +119,13 @@ __PACKAGE__->register_method ({
        additionalProperties => 0,
        properties => {
            vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid_running }),
        additionalProperties => 0,
        properties => {
            vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid_running }),
+           escape => {
+               description => "Escape sequence prefix. For example to use <Ctrl+b q> as the escape sequence pass '^b'.",
+               default =>  '^a',
+               type => 'string',
+               pattern => '\^?[a-z]',
+               optional => 1,
+           },
        },
     },
     returns => { type => 'null' },
        },
     },
     returns => { type => 'null' },
@@ -129,7 +136,7 @@ __PACKAGE__->register_method ({
        # test if container exists on this node
        my $conf = PVE::LXC::Config->load_config($param->{vmid});
 
        # test if container exists on this node
        my $conf = PVE::LXC::Config->load_config($param->{vmid});
 
-       my $cmd = PVE::LXC::get_console_command($param->{vmid}, $conf);
+       my $cmd = PVE::LXC::get_console_command($param->{vmid}, $conf, $param->{escape});
        exec(@$cmd);
     }});
 
        exec(@$cmd);
     }});
 
index 89f289e9113de6a4540d03e142807ed65cbfc3ab..a2a2c54670f8c1c802f341a8957306e87987558a 100644 (file)
@@ -664,17 +664,20 @@ sub verify_searchdomain_list {
 }
 
 sub get_console_command {
 }
 
 sub get_console_command {
-    my ($vmid, $conf, $noescapechar) = @_;
+    my ($vmid, $conf, $escapechar) = @_;
+    
+    # '-1' as $escapechar disables keyboard escape sequence
+    # any other passed char (a-z) will result in <Ctrl+$escapechar q>
 
     my $cmode = PVE::LXC::Config->get_cmode($conf);
 
     my $cmd = [];
     if ($cmode eq 'console') {
        push @$cmd, 'lxc-console', '-n',  $vmid, '-t', 0;
 
     my $cmode = PVE::LXC::Config->get_cmode($conf);
 
     my $cmd = [];
     if ($cmode eq 'console') {
        push @$cmd, 'lxc-console', '-n',  $vmid, '-t', 0;
-       push @$cmd, '-e', -1 if $noescapechar;
+       push @$cmd, '-e', $escapechar if $escapechar;
     } elsif ($cmode eq 'tty') {
        push @$cmd, 'lxc-console', '-n',  $vmid;
     } elsif ($cmode eq 'tty') {
        push @$cmd, 'lxc-console', '-n',  $vmid;
-       push @$cmd, '-e', -1 if $noescapechar;
+       push @$cmd, '-e', $escapechar if $escapechar;
     } elsif ($cmode eq 'shell') {
        push @$cmd, 'lxc-attach', '--clear-env', '-n', $vmid;
     } else {
     } elsif ($cmode eq 'shell') {
        push @$cmd, 'lxc-attach', '--clear-env', '-n', $vmid;
     } else {