From ad3f2e3f4f21e1a530403c51537f4c97c66649c9 Mon Sep 17 00:00:00 2001 From: leipeng Date: Sat, 6 Jan 2024 16:38:54 +0800 Subject: [PATCH 1/2] leak flags to avoid sleep --- main.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/main.go b/main.go index 112b8595..eff3a15f 100644 --- a/main.go +++ b/main.go @@ -26,7 +26,6 @@ import ( "strings" "sync" "syscall" - "time" "context" @@ -163,10 +162,6 @@ func main() { err = fmt.Errorf("invalid arguments") return } - defer func() { - time.Sleep(time.Second) - flags.Cleanup() - }() if !flags.Foreground { var wg sync.WaitGroup From abb88437afb750e41dff1715d0469f8edf132492 Mon Sep 17 00:00:00 2001 From: leipeng Date: Sat, 6 Jan 2024 19:15:01 +0800 Subject: [PATCH 2/2] Replace SIGUSR1 to SIGHUP --- main.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index eff3a15f..2c275288 100644 --- a/main.go +++ b/main.go @@ -37,17 +37,18 @@ import ( ) var log = GetLogger("main") +var SIGRTMIN = 34 func registerSIGINTHandler(fs *Goofys, flags *FlagStorage) { // Register for SIGINT. signalChan := make(chan os.Signal, 1) - signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM, syscall.SIGUSR1) + signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP) // Start a goroutine that will unmount when the signal is received. go func() { for { s := <-signalChan - if s == syscall.SIGUSR1 { + if s == syscall.SIGHUP { log.Infof("Received %v", s) fs.SigUsr1() continue @@ -76,7 +77,7 @@ var waitedForSignal os.Signal func waitForSignal(wg *sync.WaitGroup) { signalChan := make(chan os.Signal, 1) - signal.Notify(signalChan, syscall.SIGUSR1, syscall.SIGUSR2) + signal.Notify(signalChan, syscall.SIGHUP, syscall.SIGUSR2) wg.Add(1) go func() { @@ -181,14 +182,14 @@ func main() { if child != nil { // attempt to wait for child to notify parent wg.Wait() - if waitedForSignal == syscall.SIGUSR1 { + if waitedForSignal == syscall.SIGHUP { return } else { return fuse.EINVAL } } else { // kill our own waiting goroutine - kill(os.Getpid(), syscall.SIGUSR1) + kill(os.Getpid(), syscall.SIGHUP) wg.Wait() defer ctx.Release() } @@ -213,7 +214,7 @@ func main() { // fatal also terminates itself } else { if !flags.Foreground { - kill(os.Getppid(), syscall.SIGUSR1) + kill(os.Getppid(), syscall.SIGHUP) } log.Println("File system has been successfully mounted.") // Let the user unmount with Ctrl-C