Skip to content

Commit

Permalink
lxc: Handle interupts properly to clean spice socket and avoid accumu…
Browse files Browse the repository at this point in the history
…lation

Signed-off-by: Gabriel Mougard <[email protected]>
  • Loading branch information
gabrielmougard committed Oct 31, 2024
1 parent c1f6a87 commit a2324dc
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lxc/console.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package main

import (
"context"
"errors"
"fmt"
"io"
"net"
"os"
"os/exec"
"os/signal"
"runtime"
"strconv"
"sync"
"syscall"

"github.com/gorilla/websocket"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -237,6 +240,12 @@ func (c *cmdConsole) vga(d lxd.InstanceServer, name string) error {
var err error
conf := c.global.conf

// Create a context that is canceled on signal reception.
// This is used to enable the function to execute any cleanup defer statements
// before exiting.
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
defer stop()

// We currently use the control websocket just to abort in case of errors.
controlDone := make(chan struct{}, 1)
handler := func(control *websocket.Conn) {
Expand Down Expand Up @@ -284,7 +293,8 @@ func (c *cmdConsole) vga(d lxd.InstanceServer, name string) error {
}

// Listen on the socket.
listener, err = net.Listen("unix", path.Name())
lc := net.ListenConfig{}
listener, err = lc.Listen(ctx, "unix", path.Name())
if err != nil {
return err
}
Expand Down

0 comments on commit a2324dc

Please sign in to comment.