Skip to content
Snippets Groups Projects
Commit a8b10af3 authored by jkito's avatar jkito :skull: Committed by jkito
Browse files

show error message when app already running

this adds a new error type when app is not able to
get a lock of the pid file as another instance  is
already running, it then shows a msg and quits
parent 26bb6ac1
No related branches found
No related tags found
1 merge request!273fix crash during start when helper not installed
Pipeline #253825 failed
......@@ -44,6 +44,19 @@ ErrorBox {
errorText: qsTr("Could not find polkit agent.")
visible: true
}
},
State {
name: "alreadyrunning"
when: root.error == "alreadyrunning"
PropertyChanges {
target: splashProgress
visible: false
}
PropertyChanges {
target: splashErrorBox
errorText: qsTr("Application is going to quit as another instance is already running. Please use the system tray icon to open it")
visible: true
}
}
]
}
package backend
import (
"errors"
"os"
"time"
"github.com/rs/zerolog/log"
"0xacab.org/leap/bitmask-vpn/pkg/bitmask"
......@@ -61,10 +65,15 @@ func initializeBitmask(errCh chan string, opts *InitOpts) {
ctx.UseUDP = ctx.cfg.UDP
err := pid.AcquirePID()
if err != nil {
log.Fatal().
if err != nil && errors.Is(err, pid.AlreadyRunningErr) {
log.Error().
Err(err).
Msg("Could not acquire PID")
errCh <- "alreadyrunning"
// would be better to quit the app from cpp land
// using go trigger(OnInitPidError)
time.Sleep(10 * time.Second)
os.Exit(1)
}
b, err := bitmask.InitializeBitmask(ctx.cfg)
......
......@@ -16,6 +16,7 @@
package pid
import (
"errors"
"fmt"
"io/ioutil"
"os"
......@@ -30,17 +31,20 @@ import (
"github.com/keybase/go-ps"
)
var pidFile = filepath.Join(config.Path, "systray.pid")
var (
pidFile = filepath.Join(config.Path, "systray.pid")
AlreadyRunningErr = errors.New("another instance is already running")
)
func AcquirePID() error {
pid := syscall.Getpid()
current, err := getPID()
if err != nil {
log.Print("Error reading pid file:", err)
log.Err(err).Msg("Error reading pid file")
}
if current != pid && pidRunning(current) {
return fmt.Errorf("Another systray is running with pid: %d", current)
return fmt.Errorf("%w, pid: %d", AlreadyRunningErr, current)
}
return setPID(pid)
......
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