[lxc-devel] [lxd/master] lxc/console: Disconnect on shutdown
stgraber on Github
lxc-bot at linuxcontainers.org
Tue Jul 14 15:07:26 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200714/e75df048/attachment.bin>
-------------- next part --------------
From 57252181b2ee2aef3a8f0e034bfff6c2dedb3169 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 14 Jul 2020 11:06:41 -0400
Subject: [PATCH] lxc/console: Disconnect on shutdown
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxc/console.go | 41 +++++++++++++++++++++++++----------------
1 file changed, 25 insertions(+), 16 deletions(-)
diff --git a/lxc/console.go b/lxc/console.go
index 7a8064a33d..cfc134311b 100644
--- a/lxc/console.go
+++ b/lxc/console.go
@@ -304,24 +304,33 @@ func (c *cmdConsole) vga(d lxd.InstanceServer, name string) error {
}()
// Use either spicy or remote-viewer if available.
- remoteViewer, err := exec.LookPath("remote-viewer")
- if err == nil {
- _, err := shared.RunCommand(remoteViewer, fmt.Sprintf("spice+unix://%s", socket))
- if err != nil {
- return err
- }
- } else {
- spicy, err := exec.LookPath("spicy")
- if err == nil {
- _, err := shared.RunCommand(spicy, fmt.Sprintf("--uri=spice+unix://%s", socket))
- if err != nil {
- return err
- }
+ remoteViewer, _ := exec.LookPath("remote-viewer")
+ spicy, _ := exec.LookPath("spicy")
+
+ if remoteViewer != "" || spicy != "" {
+ var cmd *exec.Cmd
+ if remoteViewer != "" {
+ cmd = exec.Command(remoteViewer, fmt.Sprintf("spice+unix://%s", socket))
} else {
- fmt.Println(i18n.G("LXD automatically uses either spicy or remote-viewer when present."))
- fmt.Println(i18n.G("As neither could be found, the raw SPICE socket can be found at:"))
- fmt.Printf(" %s\n", socket)
+ cmd = exec.Command(spicy, fmt.Sprintf("--uri=spice+unix://%s", socket))
}
+
+ // Start the command.
+ cmd.Stdout = os.Stdout
+ cmd.Stderr = os.Stderr
+ cmd.Start()
+
+ defer func() {
+ if cmd.Process == nil {
+ return
+ }
+
+ cmd.Process.Kill()
+ }()
+ } else {
+ fmt.Println(i18n.G("LXD automatically uses either spicy or remote-viewer when present."))
+ fmt.Println(i18n.G("As neither could be found, the raw SPICE socket can be found at:"))
+ fmt.Printf(" %s\n", socket)
}
// Wait for the operation to complete.
More information about the lxc-devel
mailing list