Skip to content

Commit d71818c

Browse files
committed
Handle signal preventing Start from completing
In the instance where the user sends a signal, such as SIGINT (Ctl-c) when a Podman Machine is in the middle of starting, make sure the state doesn't get stuck in the "Currently Starting" status. Resolves: containers#24416 Signed-off-by: Jake Correnti <[email protected]>
1 parent 20e1b9d commit d71818c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pkg/machine/shim/host.go

+15
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import (
66
"fmt"
77
"io"
88
"os"
9+
"os/signal"
910
"path"
1011
"path/filepath"
1112
"runtime"
1213
"strings"
14+
"syscall"
1315
"time"
1416

1517
"github.com/containers/podman/v5/pkg/machine"
@@ -447,6 +449,19 @@ func Start(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, dirs *machineDe
447449
return fmt.Errorf("reload config: %w", err)
448450
}
449451

452+
// if the machine cannot continue starting due to a signal, ensure the state
453+
// reflects the machine is no longer starting
454+
signalChan := make(chan os.Signal, 1)
455+
signal.Notify(signalChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
456+
go func() {
457+
for _ = range signalChan {
458+
mc.Starting = false
459+
if err := mc.Write(); err != nil {
460+
logrus.Error(err)
461+
}
462+
}
463+
}()
464+
450465
// Don't check if provider supports parallel running machines
451466
if mp.RequireExclusiveActive() {
452467
startLock, err := lock.GetMachineStartLock()

0 commit comments

Comments
 (0)