Skip to content
Snippets Groups Projects
Unverified Commit 74733b24 authored by Kali Kaneko's avatar Kali Kaneko
Browse files

[bug] exit cleanly in osx

two things happen differently in osx:

- call to systray.Quit() halts the program (so if called directly, none
        of the deferred functions that we use for cleanup get to
        execute)
- systray.Run() blocks (so after loop returns, the main run.Run() function
        did not get to receive the boolean through the finishedCh channel.

proper shutdown is therefore fixed here by moving the call to
systray.Quit() to a goroutine that executes when the initialize()
function calls all the deferred functions.

we need to revisit this in case we want to break the main select loop
for a reson other than successfully terminating the program.
parent 80993915
No related branches found
No related tags found
No related merge requests found
......@@ -68,6 +68,7 @@ func (b *Bitmask) GetStatusCh() <-chan string {
// Close the connection to bitmask
func (b *Bitmask) Close() {
log.Printf("Close: cleanup and vpn shutdown...")
b.StopVPN()
err := b.launch.close()
if err != nil {
......
......@@ -27,8 +27,13 @@ func Run(conf *Config) {
bt := bmTray{conf: conf, waitCh: make(chan bool)}
finishedCh := make(chan bool)
go initialize(conf, &bt, finishedCh)
go func() {
<-finishedCh
/* in osx, systray.Quit() halts the program */
bt.quit()
os.Exit(0)
}()
bt.start()
<-finishedCh
}
func initialize(conf *Config, bt *bmTray, finishedCh chan bool) {
......
......@@ -57,6 +57,10 @@ func (bt *bmTray) start() {
systray.Run(bt.onReady, bt.onExit)
}
func (bt *bmTray) quit() {
systray.Quit()
}
func (bt *bmTray) onExit() {
log.Println("Closing systray")
}
......@@ -146,10 +150,10 @@ func (bt *bmTray) loop(bm bitmask.Bitmask, notify *notificator, as bitmask.Autos
if err != nil {
log.Printf("Error disabling autostart: %v", err)
}
systray.Quit()
/* we return and leave bt.quit() to the caller */
return
case <-signalCh:
systray.Quit()
/* we return and leave bt.quit() to the caller */
return
case <-time.After(5 * time.Second):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment