summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2021-12-01 20:08:33 +0100
committerkali kaneko (leap communications) <kali@leap.se>2021-12-01 20:08:33 +0100
commit81bc89e89404761d2fd15093f7f7ad209784e36a (patch)
tree4b8142c3ac0fc623f9c93ffe804f83783d9e43c6
parent4f41965d86ada73f6148f756eef5048dc614c8f3 (diff)
[bug] clean exit
-rw-r--r--gui/components/MainView.qml2
-rw-r--r--gui/main.cpp32
-rw-r--r--pkg/vpn/bonafide/bonafide.go13
-rw-r--r--pkg/vpn/main.go2
4 files changed, 36 insertions, 13 deletions
diff --git a/gui/components/MainView.qml b/gui/components/MainView.qml
index 0893a2a..0f5fb58 100644
--- a/gui/components/MainView.qml
+++ b/gui/components/MainView.qml
@@ -76,7 +76,7 @@ Page {
text: qsTr("Quit")
icon: "../resources/quit.svg"
triggered: function () {
- Qt.callLater(backend.quit)
+ backend.quit()
}
}
}
diff --git a/gui/main.cpp b/gui/main.cpp
index 993ec2d..5a265eb 100644
--- a/gui/main.cpp
+++ b/gui/main.cpp
@@ -36,11 +36,6 @@ std::string getEnv(std::string const& key)
return val == NULL ? std::string() : std::string(val);
}
-void signalHandler(int) {
- Quit();
- exit(0);
-}
-
QString getAppName(QJsonValue info, QString provider) {
for (auto p: info.toArray()) {
QJsonObject item = p.toObject();
@@ -51,17 +46,38 @@ QString getAppName(QJsonValue info, QString provider) {
return "BitmaskVPN";
}
-int main(int argc, char **argv) {
- signal(SIGINT, signalHandler);
+void catchUnixSignals(std::initializer_list<int> quitSignals) {
+ auto handler = [](int sig) -> void {
+ printf("\nCatched signal(%d): quitting\n", sig);
+ Quit();
+ QGuiApplication::quit();
+ };
+
+ sigset_t blocking_mask;
+ sigemptyset(&blocking_mask);
+ for (auto sig : quitSignals)
+ sigaddset(&blocking_mask, sig);
+
+ struct sigaction sa;
+ sa.sa_handler = handler;
+ sa.sa_mask = blocking_mask;
+ sa.sa_flags = 0;
+
+ for (auto sig : quitSignals)
+ sigaction(sig, &sa, nullptr);
+}
+int main(int argc, char **argv) {
Backend backend;
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setApplicationVersion(backend.getVersion());
- QApplication app(argc, argv);
+ QGuiApplication app(argc, argv);
app.setQuitOnLastWindowClosed(false);
app.setAttribute(Qt::AA_UseHighDpiPixmaps);
+ catchUnixSignals({SIGINT, SIGTERM});
+
/* load providers json */
QFile providerJson (":/providers.json");
providerJson.open(QIODevice::ReadOnly | QIODevice::Text);
diff --git a/pkg/vpn/bonafide/bonafide.go b/pkg/vpn/bonafide/bonafide.go
index 907bba5..7bce545 100644
--- a/pkg/vpn/bonafide/bonafide.go
+++ b/pkg/vpn/bonafide/bonafide.go
@@ -247,10 +247,15 @@ func (b *Bonafide) maybeInitializeEIP() error {
b.gateways = newGatewayPool(b.eip)
}
- // FIXME: let's update the menshen gateways every time we 'maybe initilize EIP'
- // in a future we might want to be more clever on when to do that
- // (when opening the locations tab in the UI, only on reconnects, ...)
- b.fetchGatewaysFromMenshen()
+ // XXX For now, we just initialize once per session.
+ // We might update the menshen gateways every time we 'maybe initilize EIP'
+ // We might also want to be more clever on when to do that
+ // (when opening the locations tab in the UI, only on reconnects, ...)
+ // or just periodically - but we need to modify menshen api to
+ // pass a location parameter.
+ if len(b.gateways.recommended) == 0 {
+ b.fetchGatewaysFromMenshen()
+ }
}
return nil
}
diff --git a/pkg/vpn/main.go b/pkg/vpn/main.go
index da6caf1..d780afe 100644
--- a/pkg/vpn/main.go
+++ b/pkg/vpn/main.go
@@ -20,6 +20,7 @@ import (
"io/ioutil"
"log"
"os"
+ "time"
"0xacab.org/leap/bitmask-vpn/pkg/config"
"0xacab.org/leap/bitmask-vpn/pkg/config/version"
@@ -124,6 +125,7 @@ func (b *Bitmask) GetStatusCh() <-chan string {
func (b *Bitmask) Close() {
log.Printf("Close: cleanup and vpn shutdown...")
b.StopVPN()
+ time.Sleep(500 * time.Millisecond)
err := b.launch.close()
if err != nil {
log.Printf("There was an error closing the launcher: %v", err)