summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pkg/backend/api.go2
-rw-r--r--pkg/backend/init.go8
-rw-r--r--pkg/bitmask/init.go8
-rw-r--r--pkg/pid/pid.go2
4 files changed, 11 insertions, 9 deletions
diff --git a/pkg/backend/api.go b/pkg/backend/api.go
index ea148f7..9706bdf 100644
--- a/pkg/backend/api.go
+++ b/pkg/backend/api.go
@@ -11,6 +11,7 @@ import (
"0xacab.org/leap/bitmask-vpn/pkg/bitmask"
"0xacab.org/leap/bitmask-vpn/pkg/config/version"
+ "0xacab.org/leap/bitmask-vpn/pkg/pid"
"0xacab.org/leap/bitmask-vpn/pkg/pickle"
)
@@ -56,6 +57,7 @@ func Quit() {
if ctx.bm != nil {
ctx.bm.Close()
}
+ pid.ReleasePID()
}
func DonateAccepted() {
diff --git a/pkg/backend/init.go b/pkg/backend/init.go
index aabc720..c0d8f37 100644
--- a/pkg/backend/init.go
+++ b/pkg/backend/init.go
@@ -7,6 +7,7 @@ import (
"0xacab.org/leap/bitmask-vpn/pkg/bitmask"
"0xacab.org/leap/bitmask-vpn/pkg/config"
"0xacab.org/leap/bitmask-vpn/pkg/config/version"
+ "0xacab.org/leap/bitmask-vpn/pkg/pid"
)
// initializeContext initializes an empty connStatus and assigns it to the
@@ -52,6 +53,13 @@ func initializeBitmask(errCh chan string, opts *InitOpts) {
bitmask.InitializeLogger()
ctx.cfg = config.ParseConfig()
+ err := pid.AcquirePID()
+ if err != nil {
+ log.Println("Error acquiring PID:", err)
+ errCh <- err.Error()
+ return
+ }
+
b, err := bitmask.InitializeBitmask(opts.SkipLaunch)
if err != nil {
log.Println("error: cannot initialize bitmask")
diff --git a/pkg/bitmask/init.go b/pkg/bitmask/init.go
index 7ac6f76..401f8a7 100644
--- a/pkg/bitmask/init.go
+++ b/pkg/bitmask/init.go
@@ -26,7 +26,6 @@ import (
"golang.org/x/text/message"
"0xacab.org/leap/bitmask-vpn/pkg/config"
- "0xacab.org/leap/bitmask-vpn/pkg/pid"
"0xacab.org/leap/bitmask-vpn/pkg/vpn"
)
@@ -107,13 +106,6 @@ func InitializeBitmask(skipLaunch bool) (Bitmask, error) {
os.MkdirAll(config.Path, os.ModePerm)
}
- err := pid.AcquirePID()
- if err != nil {
- log.Println("Error acquiring PID:", err)
- return nil, err
- }
- defer pid.ReleasePID()
-
conf := config.ParseConfig()
conf.Printer = initPrinter()
diff --git a/pkg/pid/pid.go b/pkg/pid/pid.go
index 1124210..b6e6947 100644
--- a/pkg/pid/pid.go
+++ b/pkg/pid/pid.go
@@ -35,7 +35,7 @@ func AcquirePID() error {
pid := syscall.Getpid()
current, err := getPID()
if err != nil {
- return err
+ log.Print("Error reading pid file:", err)
}
if current != pid && pidRunning(current) {