diff options
author | Ruben Pollan <meskio@sindominio.net> | 2018-06-13 15:02:23 +0200 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2018-06-20 12:18:17 +0200 |
commit | d4f013fee611299aea7f8cfff0377ba8646ba17d (patch) | |
tree | 05c20f5aeacdd088e0d7e209b99f2d87294fa783 /bitmask_go/launcher_linux.go | |
parent | 9f6a017b93569f5abe0ef2aeb22efb05fd0e99a7 (diff) |
[feat] do a proper openvpn process management
Diffstat (limited to 'bitmask_go/launcher_linux.go')
-rw-r--r-- | bitmask_go/launcher_linux.go | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/bitmask_go/launcher_linux.go b/bitmask_go/launcher_linux.go index 05398a6..6a1407c 100644 --- a/bitmask_go/launcher_linux.go +++ b/bitmask_go/launcher_linux.go @@ -34,32 +34,63 @@ var bitmaskRootPaths = []string{ "/snap/bin/riseup-vpn.bitmask-root", } -func openvpnStart(flags ...string) error { +type launcher struct { + openvpnCh chan []string +} + +func newLauncher() *launcher { + l := launcher{make(chan []string, 1)} + go l.openvpnRunner() + return &l +} + +func (l *launcher) openvpnStart(flags ...string) error { log.Println("openvpn start: ", flags) arg := []string{"openvpn", "start", getOpenvpnPath()} arg = append(arg, flags...) - // TODO: check errors somehow instead of fire and forget - go runBitmaskRoot(arg...) + l.openvpnCh <- arg return nil } -func openvpnStop() error { +func (l *launcher) openvpnStop() error { + l.openvpnCh <- nil log.Println("openvpn stop") return runBitmaskRoot("openvpn", "stop") } -func firewallStart(gateways []string) error { +func (l *launcher) firewallStart(gateways []string) error { log.Println("firewall start") arg := []string{"firewall", "start"} arg = append(arg, gateways...) return runBitmaskRoot(arg...) } -func firewallStop() error { +func (l *launcher) firewallStop() error { log.Println("firewall stop") return runBitmaskRoot("firewall", "stop") } +func (l *launcher) openvpnRunner(arg ...string) { + running := false + runOpenvpn := func(arg []string) { + for running { + err := runBitmaskRoot(arg...) + if err != nil { + log.Printf("An error ocurred running openvpn: %v", err) + } + } + } + + for arg := range l.openvpnCh { + if arg == nil { + running = false + } else { + running = true + go runOpenvpn(arg) + } + } +} + func runBitmaskRoot(arg ...string) error { bitmaskRoot, err := bitmaskRootPath() if err != nil { |