Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

leak flags to avoid sleep and use SIGUSR3 instead of SIGUSR1 #783

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"strings"
"sync"
"syscall"
"time"

"context"

Expand All @@ -38,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
Expand Down Expand Up @@ -77,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() {
Expand Down Expand Up @@ -163,10 +163,6 @@ func main() {
err = fmt.Errorf("invalid arguments")
return
}
defer func() {
time.Sleep(time.Second)
flags.Cleanup()
}()

if !flags.Foreground {
var wg sync.WaitGroup
Expand All @@ -186,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()
}
Expand All @@ -218,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
Expand Down