Skip to content

Commit 3bef45e

Browse files
committed
Call exit handlers when process exits normally
Current implementation in exithandler.go is track only signals(SIGTERM and SIGINT), but vfkit process also could exit normally, when VM is turned off by guest OS. This commit add 'defer util.ExecuteExitHandlers()' call in to root command to call exit handlers when process ending. Signed-off-by: Yevhen Vydolob <[email protected]>
1 parent 7717e82 commit 3bef45e

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

cmd/vfkit/root.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66

77
"github.com/crc-org/vfkit/pkg/cmdline"
8+
"github.com/crc-org/vfkit/pkg/util"
89
"github.com/sirupsen/logrus"
910
"github.com/spf13/cobra"
1011
)
@@ -28,6 +29,9 @@ var rootCmd = &cobra.Command{
2829
if err != nil {
2930
return err
3031
}
32+
// if vfkit stop execution by itself, i.e. when VM stops by guest OS
33+
// we need to call ExecuteExitHandlers to clean up
34+
defer util.ExecuteExitHandlers()
3135
return runVFKit(vmConfig, opts)
3236
},
3337
Version: cmdline.Version(),

pkg/util/exithandler.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,20 @@ func setupExitSignalHandling(doExit bool) {
4141
go func() {
4242
for sig := range sigChan {
4343
log.Printf("captured %v, calling exit handlers and exiting..", sig)
44-
exitRegistry.mutex.Lock()
45-
for _, handler := range exitRegistry.handlers {
46-
handler()
47-
}
48-
exitRegistry.mutex.Unlock()
44+
ExecuteExitHandlers()
4945
if doExit {
5046
os.Exit(1)
5147
}
5248
}
5349
}()
5450
}
51+
52+
// ExecuteExitHandlers is call all registered exit handlers
53+
// This function should be called when program finish work(i.e. when VM is turned off by guest OS)
54+
func ExecuteExitHandlers() {
55+
exitRegistry.mutex.Lock()
56+
for _, handler := range exitRegistry.handlers {
57+
handler()
58+
}
59+
exitRegistry.mutex.Unlock()
60+
}

pkg/vf/virtionet.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ func (dev *VirtioNet) connectUnixPath() error {
5959
if len(localSocketPath) >= maxUnixgramPathLen {
6060
return fmt.Errorf("unixgram path '%s' is too long: %d >= %d bytes", localSocketPath, len(localSocketPath), maxUnixgramPathLen)
6161
}
62-
// FIXME: need to remove localSocketPath at process exit
6362
localAddr := net.UnixAddr{
6463
Name: localSocketPath,
6564
Net: "unixgram",

0 commit comments

Comments
 (0)